fix: TTS朗读失败且刷新内容 — 安装edge-tts,前端改用blob播放代替downloadFile

This commit is contained in:
TradeMate Dev
2026-05-17 14:10:45 +08:00
parent f33d33f980
commit 7b7f90d57a
3 changed files with 56 additions and 25 deletions
+1 -3
View File
@@ -111,9 +111,7 @@ async def text_to_speech_get(
if not audio:
raise HTTPException(status_code=501, detail="TTS not available")
return Response(content=audio, media_type="audio/mpeg", headers={
"Content-Disposition": f'attachment; filename="tts-{lang}.mp3"',
})
return Response(content=audio, media_type="audio/mpeg")
@router.post("/feedback")
+5 -2
View File
@@ -28,7 +28,7 @@ SUPPORTED_LANGS = list(VOICE_MAP.keys())
class TextToSpeechService:
@staticmethod
async def synthesize(text: str, lang: str = "en", rate: str = "0%", pitch: str = "0Hz") -> Optional[bytes]:
async def synthesize(text: str, lang: str = "en", rate: str = "", pitch: str = "") -> Optional[bytes]:
if not HAS_EDGE_TTS:
logger.warning("edge-tts not available")
return None
@@ -36,7 +36,10 @@ class TextToSpeechService:
voice = VOICE_MAP.get(lang, VOICE_MAP["en"])
try:
communicate = edge_tts.Communicate(text, voice, rate=rate, pitch=pitch)
kwargs = {"voice": voice, "rate": rate} if rate else {"voice": voice}
if pitch:
kwargs["pitch"] = pitch
communicate = edge_tts.Communicate(text, **kwargs)
audio_data = b""
async for chunk in communicate.stream():
if chunk["type"] == "audio":