Restore Pi Chrome TTS daemon unchanged

This commit is contained in:
legop3
2026-07-07 00:22:47 -04:00
parent f4683cd47d
commit f7514e71cc
+1 -36
View File
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
import ctypes
import ctypes.util
import json
import os
import struct
@@ -34,40 +33,6 @@ MAX_PITCH = 2.0
MIN_SPEED = 0.5
MAX_SPEED = 2.0
_runtime_handles = []
def load_shared_library(path):
mode = ctypes.RTLD_GLOBAL | getattr(os, "RTLD_NOW", 0)
return ctypes.CDLL(path, mode=mode)
def preload_runtime_libraries():
# Some ChromeOS libchrometts builds reference compiler helper symbols such
# as __udivmodti4 without declaring the runtime library as an ELF dependency.
# Loading common compiler runtimes globally first makes those symbols visible
# before ctypes loads /opt/roverd/googletts/libchrometts.so.
candidates = [
"gcc_s",
"atomic",
"stdc++",
"c++",
"c++abi",
]
for name in candidates:
lib = ctypes.util.find_library(name)
if not lib:
continue
try:
_runtime_handles.append(load_shared_library(lib))
except OSError:
pass
# Load the runtime helpers at module import time so daemon readiness fails only
# when libchrometts itself is still unusable after the best-effort preloads.
preload_runtime_libraries()
def varint(value):
out = bytearray()
@@ -99,7 +64,7 @@ def build_speaker(name, gender):
class ChromeTTS:
def __init__(self):
self.lib = load_shared_library(LIB_PATH)
self.lib = ctypes.CDLL(LIB_PATH)
self.lib.GoogleTtsInit.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
self.lib.GoogleTtsInit.restype = ctypes.c_bool
self.lib.GoogleTtsInitBuffered.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int, ctypes.c_int]