Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,37 @@
|
|
1 |
import gradio as gr
|
2 |
from pydub import AudioSegment
|
3 |
|
4 |
-
#
|
5 |
-
def
|
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 |
-
|
17 |
-
|
18 |
-
return
|
19 |
|
20 |
-
#
|
21 |
interface = gr.Interface(
|
22 |
-
fn=
|
23 |
inputs=[
|
24 |
-
gr.
|
25 |
-
gr.
|
|
|
|
|
|
|
|
|
26 |
],
|
27 |
-
outputs=gr.outputs.File(label="输出音频"), # 输出最终合成的音频文件
|
28 |
live=False
|
29 |
)
|
30 |
|
31 |
-
# 启动 Gradio 应用
|
32 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from pydub import AudioSegment
|
3 |
|
4 |
+
# 处理音频函数
|
5 |
+
def combine_audio_with_time(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 |
+
# 记录目标说话人音频的时间点(精确到0.01秒)
|
13 |
+
target_start_time = len(mixed_audio_segment) / 1000 # 秒为单位,精确到 0.01 秒
|
14 |
+
|
15 |
# 将目标说话人的音频片段添加到混合音频的最后
|
16 |
final_audio = mixed_audio_segment + target_audio_segment
|
17 |
|
18 |
+
# 保存拼接后的音频并返回时间点
|
19 |
+
final_audio.export("final_output.wav", format="wav")
|
20 |
+
|
21 |
+
return "final_output.wav", target_start_time
|
22 |
|
23 |
+
# Gradio 接口
|
24 |
interface = gr.Interface(
|
25 |
+
fn=combine_audio_with_time,
|
26 |
inputs=[
|
27 |
+
gr.File(label="目标说话人音频"), # 上传目标说话人音频
|
28 |
+
gr.File(label="混合音频") # 上传混合音频
|
29 |
+
],
|
30 |
+
outputs=[
|
31 |
+
gr.Audio(label="输出音频"), # 返回拼接后的音频文件
|
32 |
+
gr.Textbox(label="目标音频起始时间") # 显示目标音频的起始时间
|
33 |
],
|
|
|
34 |
live=False
|
35 |
)
|
36 |
|
|
|
37 |
interface.launch()
|