feat: 升级到 playsound3 以替代问题频出的 playsound
This commit is contained in:
@@ -156,11 +156,11 @@ class MemScreen(Screen):
|
||||
|
||||
path = Path(config_var.get()["global"]["paths"]["data"]) / "cache" / "voice"
|
||||
path = path / f"{get_md5(self.atom.registry['nucleon']["tts_text"])}.wav"
|
||||
logger.debug(str(path))
|
||||
if path.exists():
|
||||
play_by_path(path)
|
||||
else:
|
||||
from heurams.services.tts_service import convertor
|
||||
|
||||
convertor(self.atom.registry["nucleon"]["tts_text"], path)
|
||||
play_by_path(path)
|
||||
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
"""通用音频适配器
|
||||
基于 playsound 库的音频播放器, 在绝大多数 python 环境上提供音频服务
|
||||
注意: 在未配置 pulseaudio 的 termux 不可用
|
||||
基于 playsound3 的音频播放器, 在绝大多数 python 环境上提供音频服务
|
||||
注意: 在 termux 不可用
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
|
||||
import playsound
|
||||
import playsound3
|
||||
|
||||
from heurams.services.logger import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
|
||||
def play_by_path(path: pathlib.Path):
|
||||
logger.debug("playsound_audio.play_by_path: 开始播放 %s", path)
|
||||
try:
|
||||
playsound.playsound(str(path))
|
||||
playsound3.playsound(str(path))
|
||||
logger.debug("播放完成: %s", path)
|
||||
except Exception as e:
|
||||
logger.error("播放失败: %s, 错误: %s", path, e)
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user