Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -45,10 +45,13 @@ def chatgpt(apikey, result):
|
|
45 |
|
46 |
return chat_response
|
47 |
|
48 |
-
def english(text_en, upload):
|
49 |
-
|
50 |
-
|
51 |
|
|
|
|
|
|
|
52 |
noisy = enhance_model.load_audio(
|
53 |
"output.wav"
|
54 |
).unsqueeze(0)
|
@@ -58,14 +61,29 @@ def english(text_en, upload):
|
|
58 |
|
59 |
return "enhanced.wav"
|
60 |
|
61 |
-
def chinese(text_cn, upload1):
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
return "
|
69 |
|
70 |
block = gr.Blocks()
|
71 |
|
@@ -95,13 +113,13 @@ with block:
|
|
95 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
96 |
inp3 = texts1
|
97 |
inp4 = gr.Audio(source="upload", label = "请上传您喜欢的声音(wav/mp3文件)", type="filepath")
|
98 |
-
|
99 |
|
100 |
btn1 = gr.Button("用喜欢的声音听一听吧(中文)")
|
101 |
|
102 |
out1 = gr.Audio(label="合成的专属声音(中文)")
|
103 |
|
104 |
-
btn1.click(chinese, [inp3, inp4], [out1])
|
105 |
|
106 |
with gr.Box():
|
107 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
@@ -110,7 +128,7 @@ with block:
|
|
110 |
|
111 |
out2 = gr.Audio(label="合成的专属声音(英文)")
|
112 |
|
113 |
-
btn2.click(english, [inp3, inp4], [out2])
|
114 |
|
115 |
gr.Markdown(
|
116 |
""" ### <center>注意❗:请不要输入或生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及娱乐使用。用户输入或生成的内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。</center>
|
@@ -124,7 +142,7 @@ with block:
|
|
124 |
<div class="footer">
|
125 |
<p>🎶🖼️🎡 - It’s the intersection of technology and liberal arts that makes our hearts sing. - Steve Jobs
|
126 |
</p>
|
127 |
-
<p>注:中文声音克隆实际上是由声音转换(Voice Conversion)
|
128 |
</p>
|
129 |
</div>
|
130 |
''')
|
|
|
45 |
|
46 |
return chat_response
|
47 |
|
48 |
+
def english(text_en, upload, VoiceMicrophone):
|
49 |
+
if upload is not None:
|
50 |
+
tts1.tts_to_file(text_en, speaker_wav = upload, language="en", file_path="output.wav")
|
51 |
|
52 |
+
else:
|
53 |
+
tts1.tts_to_file(text_en, speaker_wav = VoiceMicrophone, language="en", file_path="output.wav")
|
54 |
+
|
55 |
noisy = enhance_model.load_audio(
|
56 |
"output.wav"
|
57 |
).unsqueeze(0)
|
|
|
61 |
|
62 |
return "enhanced.wav"
|
63 |
|
64 |
+
def chinese(text_cn, upload1, VoiceMicrophone):
|
65 |
+
if upload1 is not None:
|
66 |
+
tts2.tts_with_vc_to_file(
|
67 |
+
text_cn + "。",
|
68 |
+
speaker_wav=upload1,
|
69 |
+
file_path="ouptut1.wav"
|
70 |
+
)
|
71 |
+
|
72 |
+
else:
|
73 |
+
tts2.tts_with_vc_to_file(
|
74 |
+
text_cn + "。",
|
75 |
+
speaker_wav=upload1,
|
76 |
+
file_path="ouptut1.wav"
|
77 |
+
)
|
78 |
+
|
79 |
+
noisy = enhance_model.load_audio(
|
80 |
+
"output1.wav"
|
81 |
+
).unsqueeze(0)
|
82 |
+
|
83 |
+
enhanced = enhance_model.enhance_batch(noisy, lengths=torch.tensor([1.]))
|
84 |
+
torchaudio.save("enhanced1.wav", enhanced.cpu(), 16000)
|
85 |
|
86 |
+
return "enhanced1.wav"
|
87 |
|
88 |
block = gr.Blocks()
|
89 |
|
|
|
113 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
114 |
inp3 = texts1
|
115 |
inp4 = gr.Audio(source="upload", label = "请上传您喜欢的声音(wav/mp3文件)", type="filepath")
|
116 |
+
inp5 = gr.Audio(source="microphone", type="filepath", label = '请用麦克风上传您喜欢的声音,与文件上传二选一即可')
|
117 |
|
118 |
btn1 = gr.Button("用喜欢的声音听一听吧(中文)")
|
119 |
|
120 |
out1 = gr.Audio(label="合成的专属声音(中文)")
|
121 |
|
122 |
+
btn1.click(chinese, [inp3, inp4, inp5], [out1])
|
123 |
|
124 |
with gr.Box():
|
125 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
|
|
128 |
|
129 |
out2 = gr.Audio(label="合成的专属声音(英文)")
|
130 |
|
131 |
+
btn2.click(english, [inp3, inp4, inp5], [out2])
|
132 |
|
133 |
gr.Markdown(
|
134 |
""" ### <center>注意❗:请不要输入或生成会对个人以及组织造成侵害的内容,此程序仅供科研、学习及娱乐使用。用户输入或生成的内容与程序开发者无关,请自觉合法合规使用,违反者一切后果自负。</center>
|
|
|
142 |
<div class="footer">
|
143 |
<p>🎶🖼️🎡 - It’s the intersection of technology and liberal arts that makes our hearts sing. - Steve Jobs
|
144 |
</p>
|
145 |
+
<p>注:中文声音克隆实际上是由声音转换(Voice Conversion)实现,所以输出结果可能更像是一种新的声音,效果不一定很理想,希望大家理解(之后也会不断迭代的)!为了更好的效果,使用中文声音克隆时请尽量上传女声。
|
146 |
</p>
|
147 |
</div>
|
148 |
''')
|