Spaces:
Runtime error
Runtime error
Commit
·
6aac638
1
Parent(s):
22cc11f
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,90 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
|
| 4 |
-
model_name = TTS.list_models()[0]
|
| 5 |
# Init TTS
|
| 6 |
-
tts = TTS(model_name)
|
| 7 |
|
| 8 |
-
def text_to_speech(text: str, speaker_wav, language: str):
|
| 9 |
-
# Use the 'speaker_wav' parameter to get the path of the uploaded audio file
|
| 10 |
-
tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path="output.wav")
|
| 11 |
-
return 'output.wav'
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
|
|
|
|
| 4 |
# Init TTS
|
| 5 |
+
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
def text_to_speech(text: str, speaker_wav, speaker_wav_file, language: str):
|
| 9 |
+
if speaker_wav_file and not speaker_wav:
|
| 10 |
+
speaker_wav = speaker_wav_file
|
| 11 |
+
file_path = "output.wav"
|
| 12 |
+
if language == "zh-CN":
|
| 13 |
+
# if speaker_wav is not None:
|
| 14 |
+
# zh_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
| 15 |
+
# else:
|
| 16 |
+
zh_tts.tts_to_file(text, file_path=file_path)
|
| 17 |
+
elif language == "de":
|
| 18 |
+
# if speaker_wav is not None:
|
| 19 |
+
# de_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
| 20 |
+
# else:
|
| 21 |
+
de_tts.tts_to_file(text, file_path=file_path)
|
| 22 |
+
elif language == "es":
|
| 23 |
+
# if speaker_wav is not None:
|
| 24 |
+
# es_tts.tts_to_file(text, speaker_wav=speaker_wav, file_path=file_path)
|
| 25 |
+
# else:
|
| 26 |
+
es_tts.tts_to_file(text, file_path=file_path)
|
| 27 |
+
else:
|
| 28 |
+
if speaker_wav is not None:
|
| 29 |
+
tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path=file_path)
|
| 30 |
+
else:
|
| 31 |
+
tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path=file_path)
|
| 32 |
+
return file_path
|
| 33 |
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# inputs = [gr.Textbox(label="Input the text", value="", max_lines=3),
|
| 37 |
+
# gr.Audio(label="Voice to clone", source="microphone", type="filepath"),
|
| 38 |
+
# gr.Audio(label="Voice to clone", type="filepath"),
|
| 39 |
+
# gr.Radio(label="Language", choices=["en", "zh-CN", "fr-fr", "pt-br", "de", "es"], value="en"),
|
| 40 |
+
# gr.Text(intro_text, font_size=14)]
|
| 41 |
+
# outputs = gr.Audio(label="Output")
|
| 42 |
+
|
| 43 |
+
# demo = gr.Interface(fn=text_to_speech, inputs=inputs, outputs=outputs)
|
| 44 |
+
|
| 45 |
+
# demo.launch()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
title = "Voice-Cloning-Demo"
|
| 49 |
+
|
| 50 |
+
def toggle(choice):
|
| 51 |
+
if choice == "mic":
|
| 52 |
+
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
| 53 |
+
else:
|
| 54 |
+
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
| 55 |
+
|
| 56 |
+
def handle_language_change(choice):
|
| 57 |
+
if choice == "zh-CN" or choice == "de" or choice == "es":
|
| 58 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 59 |
+
else:
|
| 60 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 61 |
+
|
| 62 |
+
warming_text = """Please note that Chinese, German, and Spanish are currently not supported for voice cloning."""
|
| 63 |
+
|
| 64 |
+
with gr.Blocks() as demo:
|
| 65 |
+
with gr.Row():
|
| 66 |
+
with gr.Column():
|
| 67 |
+
text_input = gr.Textbox(label="Input the text", value="", max_lines=3)
|
| 68 |
+
lan_input = gr.Radio(label="Language", choices=["en", "fr-fr", "pt-br"], value="en")
|
| 69 |
+
gr.Markdown(warming_text)
|
| 70 |
+
radio = gr.Radio(["mic", "file"], value="mic",
|
| 71 |
+
label="How would you like to upload your audio?")
|
| 72 |
+
audio_input_mic = gr.Audio(label="Voice to clone", source="microphone", type="filepath", visible=True)
|
| 73 |
+
audio_input_file = gr.Audio(label="Voice to clone", type="filepath", visible=False)
|
| 74 |
+
|
| 75 |
+
with gr.Row():
|
| 76 |
+
with gr.Column():
|
| 77 |
+
btn_clear = gr.Button("Clear")
|
| 78 |
+
with gr.Column():
|
| 79 |
+
btn = gr.Button("Submit", variant="primary")
|
| 80 |
+
with gr.Column():
|
| 81 |
+
audio_output = gr.Audio(label="Output")
|
| 82 |
+
|
| 83 |
+
# gr.Examples(examples, fn=inference, inputs=[audio_file, text_input],
|
| 84 |
+
# outputs=audio_output, cache_examples=True)
|
| 85 |
+
btn.click(text_to_speech, inputs=[text_input, audio_input_mic,
|
| 86 |
+
audio_input_file, lan_input], outputs=audio_output)
|
| 87 |
+
radio.change(toggle, radio, [audio_input_mic, audio_input_file])
|
| 88 |
+
lan_input.change(handle_language_change, lan_input, [radio, audio_input_mic, audio_input_file])
|
| 89 |
+
|
| 90 |
+
demo.launch(enable_queue=True)
|