fix: TTS朗读失败且刷新内容 — 安装edge-tts,前端改用blob播放代替downloadFile
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user