Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pydub import AudioSegment
|
3 |
+
|
4 |
+
# 定义一个函数来拼接音频
|
5 |
+
def combine_audio(target_audio, mixed_audio):
|
6 |
+
# 加载目标说话人的样本音频
|
7 |
+
target_audio_segment = AudioSegment.from_wav(target_audio.name)
|
8 |
+
|
9 |
+
# 加载混合音频
|
10 |
+
mixed_audio_segment = AudioSegment.from_wav(mixed_audio.name)
|
11 |
+
|
12 |
+
# 将目标说话人的音频片段添加到混合音频的最后
|
13 |
+
final_audio = mixed_audio_segment + target_audio_segment
|
14 |
+
|
15 |
+
# 保存并返回输出音频
|
16 |
+
output_path = "final_output.wav"
|
17 |
+
final_audio.export(output_path, format="wav")
|
18 |
+
return output_path
|
19 |
+
|
20 |
+
# 创建 Gradio 接口
|
21 |
+
interface = gr.Interface(
|
22 |
+
fn=combine_audio, # 处理音频的函数
|
23 |
+
inputs=[
|
24 |
+
gr.inputs.File(label="目标说话人音频"), # 上传目标说话人音频
|
25 |
+
gr.inputs.File(label="混合音频") # 上传混合音频
|
26 |
+
],
|
27 |
+
outputs=gr.outputs.File(label="输出音频"), # 输出最终合成的音频文件
|
28 |
+
live=False
|
29 |
+
)
|
30 |
+
|
31 |
+
# 启动 Gradio 应用
|
32 |
+
interface.launch()
|