This commit is contained in:
2025-09-02 08:48:33 +08:00
parent 1512346ef0
commit 044312e500
8 changed files with 382 additions and 12 deletions

View File

@@ -10,6 +10,8 @@ from Util.ObsUtil import ObsUploader
from Config.Config import OBS_BUCKET, OBS_SERVER
# 导入TTS生成类
from Util.GengerateAudio import ByteDanceTTS
from fastapi.responses import StreamingResponse
import requests
# 配置日志
logger = logging.getLogger(__name__)
@@ -143,3 +145,26 @@ async def generate_audio(request: TextToSpeechRequest, background_tasks: Backgro
if 'output_path' in locals() and os.path.exists(output_path):
background_tasks.add_task(os.remove, output_path)
raise HTTPException(status_code=500, detail=f"处理失败: {str(e)}")
@router.get("/download/{filename}")
async def download_audio(filename: str):
# 构建OBS文件URL
obs_url = f"https://{OBS_BUCKET}.{OBS_SERVER}/HuangHai/tts/{filename}"
try:
# 流式获取OBS文件
response = requests.get(obs_url, stream=True)
if response.status_code != 200:
raise HTTPException(status_code=404, detail="音频文件不存在")
# 设置下载响应头
headers = {
"Content-Disposition": f"attachment; filename={filename}",
"Content-Type": "audio/mpeg"
}
# 返回流式响应
return StreamingResponse(response.iter_content(chunk_size=8192), headers=headers)
except Exception as e:
raise HTTPException(status_code=500, detail=f"下载失败: {str(e)}")