fix(tts): use temporary file for WAV encoding to avoid BytesIO limitation
fix(UniverPreview): update error messages and hints for document loading
This commit is contained in:
+10
-3
@@ -214,10 +214,17 @@ async def tts_endpoint(req: TTSRequest):
|
||||
|
||||
# 编码 WAV 到内存
|
||||
try:
|
||||
import tempfile
|
||||
import soundfile as sf
|
||||
bio = BytesIO()
|
||||
sf.write(bio, wav_data, sr, format="WAV")
|
||||
audio_bytes = bio.getvalue()
|
||||
# soundfile 不支持直接写入 BytesIO,需要用临时文件
|
||||
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
||||
tmp_path = tmp.name
|
||||
sf.write(tmp_path, wav_data, sr, format="WAV")
|
||||
with open(tmp_path, "rb") as f:
|
||||
audio_bytes = f.read()
|
||||
# 清理临时文件
|
||||
import os as _os
|
||||
_os.unlink(tmp_path)
|
||||
except Exception as e:
|
||||
logger.exception("音频编码失败")
|
||||
raise HTTPException(status_code=500, detail=f"音频编码失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user