diff --git a/liveMan.py b/liveMan.py index 1d8197d..f0a2a49 100644 --- a/liveMan.py +++ b/liveMan.py @@ -27,6 +27,7 @@ from protobuf.douyin import * from ws_server import push_to_frontend import asyncio from dataclasses import asdict +import subprocess # TTS 播报引擎(全局只初始化一次) tts_engine = pyttsx3.init() @@ -36,16 +37,25 @@ tts_engine.setProperty('volume', 1.0) # 加锁防止多线程同时播报冲突 tts_lock = threading.Lock() -def speak(text: str): - """线程安全地进行语音播报""" +import subprocess + +import subprocess + +def speak(text: str, voice='zh', pitch=70, speed=170): try: - with tts_lock: - tts_engine.say(text) - tts_engine.runAndWait() + subprocess.run([ + 'espeak-ng', + '-v', voice, + '-p', str(pitch), + '-s', str(speed), + text + ], check=True) except Exception as e: print("【X】TTS 播报失败:", e) + + @contextmanager def patched_popen_encoding(encoding='utf-8'): original_popen_init = subprocess.Popen.__init__