'commit'
This commit is contained in:
@@ -51,7 +51,7 @@ async def generate_video(request: VideoRetalkRequest):
|
||||
video_retalk = VideoRetalk(Config.ALY_LLM_API_KEY)
|
||||
|
||||
# 调用视频生成方法
|
||||
video_url = video_retalk.generate_video(
|
||||
video_result = video_retalk.generate_video(
|
||||
image_url=request.image_url,
|
||||
audio_url=request.audio_url,
|
||||
template_id=request.template_id,
|
||||
@@ -62,15 +62,14 @@ async def generate_video(request: VideoRetalkRequest):
|
||||
head_move_strength=request.head_move_strength
|
||||
)
|
||||
|
||||
if video_url:
|
||||
if video_result and video_result['video_url']:
|
||||
return VideoRetalkResponse(
|
||||
success=True,
|
||||
message="视频生成成功",
|
||||
video_url=video_url,
|
||||
# 以下字段在实际实现中可以从API响应中获取
|
||||
video_url=video_result['video_url'],
|
||||
task_id=str(uuid.uuid4()),
|
||||
video_duration=10.23, # 示例值,实际应从API响应获取
|
||||
video_ratio="standard", # 示例值,实际应从API响应获取
|
||||
video_duration=video_result['video_duration'],
|
||||
video_ratio=video_result['video_ratio'],
|
||||
request_id=str(uuid.uuid4())
|
||||
)
|
||||
else:
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -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)}")
|
||||
|
Reference in New Issue
Block a user