素材设置
+ +点击上传图片或拖放至此处
+支持JPG、PNG格式,大小不超过5MB
+
点击上传音频或拖放至此处
+支持MP3、WAV格式,大小不超过20MB
+合成结果
+ +正在生成视频,请稍候...
+暂无合成结果
+diff --git a/dsLightRag/Routes/VideoRetalkRoute.py b/dsLightRag/Routes/VideoRetalkRoute.py index dfa59edc..d267535e 100644 --- a/dsLightRag/Routes/VideoRetalkRoute.py +++ b/dsLightRag/Routes/VideoRetalkRoute.py @@ -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: diff --git a/dsLightRag/Routes/__pycache__/VideoRetalkRoute.cpython-310.pyc b/dsLightRag/Routes/__pycache__/VideoRetalkRoute.cpython-310.pyc index 9d7d585a..66e6b23d 100644 Binary files a/dsLightRag/Routes/__pycache__/VideoRetalkRoute.cpython-310.pyc and b/dsLightRag/Routes/__pycache__/VideoRetalkRoute.cpython-310.pyc differ diff --git a/dsLightRag/Routes/__pycache__/ttsRoute.cpython-310.pyc b/dsLightRag/Routes/__pycache__/ttsRoute.cpython-310.pyc index 279cce17..d2a6c423 100644 Binary files a/dsLightRag/Routes/__pycache__/ttsRoute.cpython-310.pyc and b/dsLightRag/Routes/__pycache__/ttsRoute.cpython-310.pyc differ diff --git a/dsLightRag/Routes/ttsRoute.py b/dsLightRag/Routes/ttsRoute.py index 32208ebe..c9cdde6d 100644 --- a/dsLightRag/Routes/ttsRoute.py +++ b/dsLightRag/Routes/ttsRoute.py @@ -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)}") diff --git a/dsLightRag/Util/VideoRetalk.py b/dsLightRag/Util/VideoRetalk.py index 0771e751..929d0c50 100644 --- a/dsLightRag/Util/VideoRetalk.py +++ b/dsLightRag/Util/VideoRetalk.py @@ -170,10 +170,15 @@ class VideoRetalk: print(f"视频生成成功: {video_url}") # 获取使用情况信息 usage = result.get('usage', {}) + video_info = { + 'video_url': video_url, + 'video_duration': usage.get('video_duration'), + 'video_ratio': usage.get('video_ratio') + } if usage: - print(f"视频时长: {usage.get('video_duration')}秒") - print(f"视频比例: {usage.get('video_ratio')}") - return video_url + print(f"视频时长: {video_info['video_duration']}秒") + print(f"视频比例: {video_info['video_ratio']}") + return video_info else: print("未找到生成的视频URL") return None diff --git a/dsLightRag/Util/__pycache__/VideoRetalk.cpython-310.pyc b/dsLightRag/Util/__pycache__/VideoRetalk.cpython-310.pyc index f01c0387..8494498a 100644 Binary files a/dsLightRag/Util/__pycache__/VideoRetalk.cpython-310.pyc and b/dsLightRag/Util/__pycache__/VideoRetalk.cpython-310.pyc differ diff --git a/dsLightRag/static/text-to-speech.html b/dsLightRag/static/text-to-speech.html index 58eb5d90..6a1681d1 100644 --- a/dsLightRag/static/text-to-speech.html +++ b/dsLightRag/static/text-to-speech.html @@ -289,7 +289,6 @@
@@ -511,8 +510,10 @@ try { const a = document.createElement('a'); - a.href = data.audio_url; - a.download = fileName; + // 移除本地代理,直接使用OBS的HTTPS链接 + // 同时添加URL清理逻辑,移除可能存在的引号和空格 + a.href = data.audio_url.trim().replace(/[`'"\s]/g, ''); + a.download = data.filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); diff --git a/dsLightRag/static/video-retalk.html b/dsLightRag/static/video-retalk.html new file mode 100644 index 00000000..5d44d511 --- /dev/null +++ b/dsLightRag/static/video-retalk.html @@ -0,0 +1,340 @@ + + + + + +上传图片和音频,合成人物讲话视频
+点击上传图片或拖放至此处
+支持JPG、PNG格式,大小不超过5MB
+点击上传音频或拖放至此处
+支持MP3、WAV格式,大小不超过20MB
+正在生成视频,请稍候...
+暂无合成结果
+