feat: 升级到 playsound3 以替代问题频出的 playsound

This commit is contained in:
2026-05-04 14:22:45 +08:00
parent ca86b2d8e9
commit 03300f0b18
6 changed files with 13 additions and 19 deletions

View File

@@ -160,5 +160,11 @@
"ident": "屈平正道直行, 竭忠尽智以事其君, 谗人间之, 可谓穷矣.",
"added": 1777847825,
"tags": []
},
{
"repo_path": "cngk-t",
"ident": "上称帝喾, 下道齐桓, 中述汤武, 以刺世事.",
"added": 1777874192,
"tags": []
}
]

View File

@@ -30,10 +30,7 @@ tts-edgetts = [
"edge-tts>=7.2.8", # 微软 TTS
]
llm = ["openai>=2.32.0"]
audio-playsound = [
"playsound3==3.3.1",
#"pygobject>=3.56.2", # playsound 依赖它
]
audio-playsound = ["playsound3>=3.3.1"]
dev = [ # 调试所需依赖
"zmq>=0.0.0", # 用于 ZMQ 远程调试服务器, 在 linux 上建议先安装 libzmq
"pytest>=8.0.0", # 用于普通测试

View File

@@ -1,7 +0,0 @@
edge-tts==7.0.2
openai==1.0.0
playsound==1.2.2
tabulate>=0.9.0
textual==7.0.0
toml==0.10.2
transitions==0.9.3

View File

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

View File

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

2
uv.lock generated
View File

@@ -493,7 +493,7 @@ requires-dist = [
{ name = "heurams", extras = ["tts-edgetts"], marker = "extra == 'all'" },
{ name = "heurams", extras = ["tts-edgetts"], marker = "extra == 'basic'" },
{ name = "openai", marker = "extra == 'llm'", specifier = ">=2.32.0" },
{ name = "playsound3", marker = "extra == 'audio-playsound'", specifier = "==3.3.1" },
{ name = "playsound3", marker = "extra == 'audio-playsound'", specifier = ">=3.3.1" },
{ name = "psutil", marker = "extra == 'interface'", specifier = ">=7.2.2" },
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8.0.0" },
{ name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=6.0.0" },