'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_retalk = VideoRetalk(Config.ALY_LLM_API_KEY)
|
||||||
|
|
||||||
# 调用视频生成方法
|
# 调用视频生成方法
|
||||||
video_url = video_retalk.generate_video(
|
video_result = video_retalk.generate_video(
|
||||||
image_url=request.image_url,
|
image_url=request.image_url,
|
||||||
audio_url=request.audio_url,
|
audio_url=request.audio_url,
|
||||||
template_id=request.template_id,
|
template_id=request.template_id,
|
||||||
@@ -62,15 +62,14 @@ async def generate_video(request: VideoRetalkRequest):
|
|||||||
head_move_strength=request.head_move_strength
|
head_move_strength=request.head_move_strength
|
||||||
)
|
)
|
||||||
|
|
||||||
if video_url:
|
if video_result and video_result['video_url']:
|
||||||
return VideoRetalkResponse(
|
return VideoRetalkResponse(
|
||||||
success=True,
|
success=True,
|
||||||
message="视频生成成功",
|
message="视频生成成功",
|
||||||
video_url=video_url,
|
video_url=video_result['video_url'],
|
||||||
# 以下字段在实际实现中可以从API响应中获取
|
|
||||||
task_id=str(uuid.uuid4()),
|
task_id=str(uuid.uuid4()),
|
||||||
video_duration=10.23, # 示例值,实际应从API响应获取
|
video_duration=video_result['video_duration'],
|
||||||
video_ratio="standard", # 示例值,实际应从API响应获取
|
video_ratio=video_result['video_ratio'],
|
||||||
request_id=str(uuid.uuid4())
|
request_id=str(uuid.uuid4())
|
||||||
)
|
)
|
||||||
else:
|
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
|
from Config.Config import OBS_BUCKET, OBS_SERVER
|
||||||
# 导入TTS生成类
|
# 导入TTS生成类
|
||||||
from Util.GengerateAudio import ByteDanceTTS
|
from Util.GengerateAudio import ByteDanceTTS
|
||||||
|
from fastapi.responses import StreamingResponse
|
||||||
|
import requests
|
||||||
|
|
||||||
# 配置日志
|
# 配置日志
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
if 'output_path' in locals() and os.path.exists(output_path):
|
||||||
background_tasks.add_task(os.remove, output_path)
|
background_tasks.add_task(os.remove, output_path)
|
||||||
raise HTTPException(status_code=500, detail=f"处理失败: {str(e)}")
|
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)}")
|
||||||
|
@@ -170,10 +170,15 @@ class VideoRetalk:
|
|||||||
print(f"视频生成成功: {video_url}")
|
print(f"视频生成成功: {video_url}")
|
||||||
# 获取使用情况信息
|
# 获取使用情况信息
|
||||||
usage = result.get('usage', {})
|
usage = result.get('usage', {})
|
||||||
|
video_info = {
|
||||||
|
'video_url': video_url,
|
||||||
|
'video_duration': usage.get('video_duration'),
|
||||||
|
'video_ratio': usage.get('video_ratio')
|
||||||
|
}
|
||||||
if usage:
|
if usage:
|
||||||
print(f"视频时长: {usage.get('video_duration')}秒")
|
print(f"视频时长: {video_info['video_duration']}秒")
|
||||||
print(f"视频比例: {usage.get('video_ratio')}")
|
print(f"视频比例: {video_info['video_ratio']}")
|
||||||
return video_url
|
return video_info
|
||||||
else:
|
else:
|
||||||
print("未找到生成的视频URL")
|
print("未找到生成的视频URL")
|
||||||
return None
|
return None
|
||||||
|
Binary file not shown.
@@ -289,7 +289,6 @@
|
|||||||
<div id="audio-result" style="display: none;">
|
<div id="audio-result" style="display: none;">
|
||||||
<audio id="audio-player" class="audio-player" controls></audio>
|
<audio id="audio-player" class="audio-player" controls></audio>
|
||||||
<div class="form-group" style="margin-top: 20px;">
|
<div class="form-group" style="margin-top: 20px;">
|
||||||
<button id="download-btn" class="btn btn-primary">下载音频</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -511,8 +510,10 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = data.audio_url;
|
// 移除本地代理,直接使用OBS的HTTPS链接
|
||||||
a.download = fileName;
|
// 同时添加URL清理逻辑,移除可能存在的引号和空格
|
||||||
|
a.href = data.audio_url.trim().replace(/[`'"\s]/g, '');
|
||||||
|
a.download = data.filename;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
|
340
dsLightRag/static/video-retalk.html
Normal file
340
dsLightRag/static/video-retalk.html
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>视频合成</title>
|
||||||
|
<link rel="stylesheet" href="/static/layui/css/layui.css">
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0; padding: 0; box-sizing: border-box;
|
||||||
|
font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
background-color: #f5f7fa;
|
||||||
|
color: #333;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
header {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 20px;
|
||||||
|
background: linear-gradient(135deg, #3498db, #8e44ad);
|
||||||
|
color: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 2.2rem;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.subtitle {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
opacity: 0.9;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 30px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-section {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 300px;
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 25px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-section {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 300px;
|
||||||
|
background-color: white;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 25px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #2c3e50;
|
||||||
|
}
|
||||||
|
|
||||||
|
select, textarea, input[type="text"] {
|
||||||
|
width: 100%;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 6px;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: border 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
select:focus, textarea:focus, input[type="text"]:focus {
|
||||||
|
border-color: #3498db;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
min-height: 150px;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
padding: 12px 24px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 16px;
|
||||||
|
transition: background 0.3s;
|
||||||
|
display: inline-block;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary {
|
||||||
|
background-color: #3498db;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background-color: #2980b9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn:disabled {
|
||||||
|
background-color: #95a5a6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area {
|
||||||
|
border: 2px dashed #ddd;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 30px;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area:hover {
|
||||||
|
border-color: #3498db;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-icon {
|
||||||
|
font-size: 48px;
|
||||||
|
color: #95a5a6;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.video-preview {
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 6px;
|
||||||
|
margin-top: 20px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
display: none;
|
||||||
|
text-align: center;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading.active {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
border: 4px solid rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 50%;
|
||||||
|
border-top: 4px solid #3498db;
|
||||||
|
width: 40px;
|
||||||
|
height: 40px;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
margin: 0 auto 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
0% { transform: rotate(0deg); }
|
||||||
|
100% { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
padding: 40px 0;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-input-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-input-group input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 768px) {
|
||||||
|
.main-content {
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.8rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<header>
|
||||||
|
<h1>视频合成</h1>
|
||||||
|
<p class="subtitle">上传图片和音频,合成人物讲话视频</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="main-content">
|
||||||
|
<div class="form-section">
|
||||||
|
<h2>素材设置</h2>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>图片上传/地址录入</label>
|
||||||
|
<div class="upload-area" id="image-upload">
|
||||||
|
<div class="upload-icon">📷</div>
|
||||||
|
<p>点击上传图片或拖放至此处</p>
|
||||||
|
<p style="font-size: 0.9rem; color: #999; margin-top: 5px;">支持JPG、PNG格式,大小不超过5MB</p>
|
||||||
|
</div>
|
||||||
|
<div class="url-input-group">
|
||||||
|
<input type="text" id="image-url" placeholder="或输入图片URL地址" value="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/LiBai.jpg">
|
||||||
|
</div>
|
||||||
|
<div style="margin-top: 15px;">
|
||||||
|
<label>图片预览</label>
|
||||||
|
<div style="border: 1px solid #ddd; border-radius: 6px; padding: 10px; text-align: center; margin-top: 8px;">
|
||||||
|
<img id="image-preview" src="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/LiBai.jpg" style="max-width: 100%; max-height: 200px; border-radius: 4px;" alt="图片预览">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>音频上传/地址录入</label>
|
||||||
|
<div class="upload-area" id="audio-upload">
|
||||||
|
<div class="upload-icon">🎵</div>
|
||||||
|
<p>点击上传音频或拖放至此处</p>
|
||||||
|
<p style="font-size: 0.9rem; color: #999; margin-top: 5px;">支持MP3、WAV格式,大小不超过20MB</p>
|
||||||
|
</div>
|
||||||
|
<div class="url-input-group">
|
||||||
|
<input type="text" id="audio-url" placeholder="或输入音频URL地址" value="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HaiShangShengMingYue.mp3">
|
||||||
|
</div>
|
||||||
|
<div style="margin-top: 15px;">
|
||||||
|
<label>音频试听</label>
|
||||||
|
<div style="margin-top: 8px;">
|
||||||
|
<audio id="audio-preview" controls style="width: 100%; border-radius: 4px;">
|
||||||
|
<source src="https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/Backup/HaiShangShengMingYue.mp3" type="audio/mpeg">
|
||||||
|
您的浏览器不支持音频播放
|
||||||
|
</audio>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="eye-movement">眼睛移动频率</label>
|
||||||
|
<select id="eye-movement">
|
||||||
|
<option value="low">低</option>
|
||||||
|
<option value="medium" selected>中</option>
|
||||||
|
<option value="high">高</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="generate-btn" class="btn btn-primary">生成视频</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="result-section">
|
||||||
|
<h2>合成结果</h2>
|
||||||
|
|
||||||
|
<div id="loading" class="loading">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<p>正在生成视频,请稍候...</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="video-result" style="display: none;">
|
||||||
|
<video class="video-preview" id="video-player" controls></video>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="empty-result" class="empty-state">
|
||||||
|
<p>暂无合成结果</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="/static/layui/layui.js"></script>
|
||||||
|
<script>
|
||||||
|
// 初始化LayUI
|
||||||
|
layui.use(['layer'], function() {
|
||||||
|
const layer = layui.layer;
|
||||||
|
|
||||||
|
// 上传区域点击事件 - 仅UI展示
|
||||||
|
document.getElementById('image-upload').addEventListener('click', function() {
|
||||||
|
layer.msg('图片上传功能敬请期待', {icon: 6});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('audio-upload').addEventListener('click', function() {
|
||||||
|
layer.msg('音频上传功能敬请期待', {icon: 6});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 实时更新预览
|
||||||
|
document.getElementById('image-url').addEventListener('input', function() {
|
||||||
|
const preview = document.getElementById('image-preview');
|
||||||
|
const url = this.value.trim();
|
||||||
|
if (url) {
|
||||||
|
preview.src = url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('audio-url').addEventListener('input', function() {
|
||||||
|
const preview = document.getElementById('audio-preview');
|
||||||
|
const url = this.value.trim();
|
||||||
|
if (url) {
|
||||||
|
preview.src = url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 生成按钮点击事件
|
||||||
|
document.getElementById('generate-btn').addEventListener('click', function() {
|
||||||
|
const generateBtn = this;
|
||||||
|
const loading = document.getElementById('loading');
|
||||||
|
const videoResult = document.getElementById('video-result');
|
||||||
|
const emptyResult = document.getElementById('empty-result');
|
||||||
|
|
||||||
|
// 显示加载状态
|
||||||
|
generateBtn.disabled = true;
|
||||||
|
loading.classList.add('active');
|
||||||
|
videoResult.style.display = 'none';
|
||||||
|
emptyResult.style.display = 'none';
|
||||||
|
|
||||||
|
// 模拟生成过程
|
||||||
|
setTimeout(() => {
|
||||||
|
loading.classList.remove('active');
|
||||||
|
videoResult.style.display = 'block';
|
||||||
|
generateBtn.disabled = false;
|
||||||
|
layer.msg('视频合成成功', {icon: 1});
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user