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