Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,32 +8,18 @@ zh_tts = TTS(model_name="tts_models/zh-CN/baker/tacotron2-DDC-GST", progress_bar
|
|
8 |
de_tts = TTS(model_name="tts_models/de/thorsten/vits", gpu=False)
|
9 |
es_tts = TTS(model_name="tts_models/es/mai/tacotron2-DDC", progress_bar=False, gpu=False)
|
10 |
|
11 |
-
def text_to_speech(text: str, speaker_wav, speaker_wav_file
|
12 |
-
if
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
# if speaker_wav is not None:
|
17 |
-
# zh_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
18 |
-
# else:
|
19 |
-
zh_tts.tts_to_file(text, file_path=file_path)
|
20 |
-
elif language == "de":
|
21 |
-
# if speaker_wav is not None:
|
22 |
-
# de_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
23 |
-
# else:
|
24 |
-
de_tts.tts_to_file(text, file_path=file_path)
|
25 |
-
elif language == "es":
|
26 |
-
# if speaker_wav is not None:
|
27 |
-
# es_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
28 |
-
# else:
|
29 |
-
es_tts.tts_to_file(text, file_path=file_path)
|
30 |
-
else:
|
31 |
if speaker_wav is not None:
|
32 |
-
tts.tts_to_file(text, speaker_wav=speaker_wav, language=
|
33 |
else:
|
34 |
-
tts.tts_to_file(text, speaker=tts.speakers[0], language=
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
|
39 |
title = "Voice-Cloning-Demo"
|
@@ -44,27 +30,15 @@ def toggle(choice):
|
|
44 |
else:
|
45 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
46 |
|
47 |
-
def
|
48 |
-
|
49 |
-
|
50 |
-
else:
|
51 |
-
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
52 |
-
|
53 |
-
def btn_input(text_input):
|
54 |
-
if len(text_input) > 0:
|
55 |
-
new_btn = gr.Button("Submit", variant="primary", interactive=True)
|
56 |
-
else:
|
57 |
-
new_btn = gr.Button("Submit", variant="primary", interactive=False)
|
58 |
-
return new_btn
|
59 |
|
60 |
-
warming_text = """Please note that Chinese, German, and Spanish are currently not supported for voice cloning."""
|
61 |
|
62 |
with gr.Blocks() as demo:
|
63 |
with gr.Row():
|
64 |
with gr.Column():
|
65 |
text_input = gr.Textbox(label="Input the text", value="", max_lines=3)
|
66 |
-
lan_input = gr.Radio(label="Language", choices=["en", "fr-fr", "pt-br", "zh-CN", "de", "es"], value="en")
|
67 |
-
gr.Markdown(warming_text)
|
68 |
radio = gr.Radio(["mic", "file"], value="mic",
|
69 |
label="How would you like to upload your audio?")
|
70 |
audio_input_mic = gr.Audio(label="Voice to clone", sources="microphone", type="filepath", visible=True)
|
@@ -74,16 +48,14 @@ with gr.Blocks() as demo:
|
|
74 |
with gr.Column():
|
75 |
btn_clear = gr.Button("Clear")
|
76 |
with gr.Column():
|
77 |
-
btn = gr.Button("Submit", variant="primary"
|
78 |
with gr.Column():
|
79 |
audio_output = gr.Audio(label="Output")
|
80 |
|
81 |
# gr.Examples(examples, fn=inference, inputs=[audio_file, text_input],
|
82 |
# outputs=audio_output, cache_examples=True)
|
83 |
-
btn.click(text_to_speech, inputs=[text_input, audio_input_mic,
|
84 |
-
audio_input_file, lan_input], outputs=audio_output)
|
85 |
radio.change(toggle, radio, [audio_input_mic, audio_input_file])
|
86 |
-
|
87 |
-
text_input.change(btn_input, text_input, btn)
|
88 |
|
89 |
demo.launch(share=True)
|
|
|
8 |
de_tts = TTS(model_name="tts_models/de/thorsten/vits", gpu=False)
|
9 |
es_tts = TTS(model_name="tts_models/es/mai/tacotron2-DDC", progress_bar=False, gpu=False)
|
10 |
|
11 |
+
def text_to_speech(text: str, speaker_wav, speaker_wav_file):
|
12 |
+
if len(text) > 0:
|
13 |
+
if speaker_wav_file and not speaker_wav:
|
14 |
+
speaker_wav = speaker_wav_file
|
15 |
+
file_path = "output.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
if speaker_wav is not None:
|
17 |
+
tts.tts_to_file(text, speaker_wav=speaker_wav, language="en", file_path=file_path)
|
18 |
else:
|
19 |
+
tts.tts_to_file(text, speaker=tts.speakers[0], language="en", file_path=file_path)
|
20 |
+
return file_path
|
21 |
+
else:
|
22 |
+
raise gr.Error("Input box cannot be blank")
|
23 |
|
24 |
|
25 |
title = "Voice-Cloning-Demo"
|
|
|
30 |
else:
|
31 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
32 |
|
33 |
+
# def btn_input(text_input):
|
34 |
+
# if len(text_input) == 0:
|
35 |
+
# raise gr.Error("Input box cannot be blank")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
37 |
|
38 |
with gr.Blocks() as demo:
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
41 |
text_input = gr.Textbox(label="Input the text", value="", max_lines=3)
|
|
|
|
|
42 |
radio = gr.Radio(["mic", "file"], value="mic",
|
43 |
label="How would you like to upload your audio?")
|
44 |
audio_input_mic = gr.Audio(label="Voice to clone", sources="microphone", type="filepath", visible=True)
|
|
|
48 |
with gr.Column():
|
49 |
btn_clear = gr.Button("Clear")
|
50 |
with gr.Column():
|
51 |
+
btn = gr.Button("Submit", variant="primary")
|
52 |
with gr.Column():
|
53 |
audio_output = gr.Audio(label="Output")
|
54 |
|
55 |
# gr.Examples(examples, fn=inference, inputs=[audio_file, text_input],
|
56 |
# outputs=audio_output, cache_examples=True)
|
57 |
+
btn.click(text_to_speech, inputs=[text_input, audio_input_mic,audio_input_file], outputs=audio_output)
|
|
|
58 |
radio.change(toggle, radio, [audio_input_mic, audio_input_file])
|
59 |
+
# btn.click(btn_input, inputs=text_input, outputs=None)
|
|
|
60 |
|
61 |
demo.launch(share=True)
|