This commit is contained in:
eric
2025-08-04 15:02:18 +08:00
parent 1eb1150b84
commit 2224b5dfe5

View File

@@ -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__