Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,48 @@
|
|
1 |
import gradio as gr
|
2 |
from TTS.api import TTS
|
3 |
-
import os
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
if audio_file_path and not audio_source:
|
15 |
-
audio_source = audio_file_path
|
16 |
-
|
17 |
-
# Generate speech using the TTS engine
|
18 |
-
if audio_source is not None:
|
19 |
-
tts_engine.tts_to_file(input_text, speaker_wav=audio_source, language=language, file_path=output_audio_path)
|
20 |
else:
|
21 |
-
|
22 |
-
|
23 |
-
return output_audio_path
|
24 |
|
25 |
-
|
26 |
-
title = "Enhanced Voice-Cloning Interface"
|
27 |
|
28 |
-
def
|
29 |
-
"""Toggle audio input method based on user choice."""
|
30 |
if choice == "mic":
|
31 |
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
32 |
else:
|
33 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
34 |
|
35 |
-
with gr.Blocks() as
|
|
|
36 |
with gr.Row():
|
37 |
with gr.Column():
|
38 |
-
text_input = gr.Textbox(label="Enter
|
39 |
-
gr.
|
40 |
-
|
|
|
41 |
audio_input_mic = gr.Audio(label="Record your voice", source="microphone", type="filepath", visible=True)
|
42 |
-
audio_input_file = gr.Audio(label="Upload
|
43 |
|
44 |
with gr.Row():
|
45 |
-
|
46 |
-
|
|
|
|
|
47 |
with gr.Column():
|
48 |
audio_output = gr.Audio(label="Generated Speech")
|
49 |
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
-
|
|
|
1 |
import gradio as gr
|
2 |
from TTS.api import TTS
|
|
|
3 |
|
4 |
+
# Initialize TTS models
|
5 |
+
tts = TTS(model_name="tts_models/multilingual/multi-dataset/your_tts", progress_bar=False, gpu=False)
|
6 |
|
7 |
+
def text_to_speech(text: str, speaker_wav, speaker_wav_file, language: str):
|
8 |
+
if speaker_wav_file and not speaker_wav:
|
9 |
+
speaker_wav = speaker_wav_file
|
10 |
+
file_path = "output.wav"
|
11 |
+
if speaker_wav is not None:
|
12 |
+
tts.tts_to_file(text, speaker_wav=speaker_wav, language=language, file_path=file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
else:
|
14 |
+
tts.tts_to_file(text, speaker=tts.speakers[0], language=language, file_path=file_path)
|
15 |
+
return file_path
|
|
|
16 |
|
17 |
+
title = "Prateek's Voice Cloning Demo"
|
|
|
18 |
|
19 |
+
def toggle(choice):
|
|
|
20 |
if choice == "mic":
|
21 |
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
22 |
else:
|
23 |
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
24 |
|
25 |
+
with gr.Blocks() as demo:
|
26 |
+
gr.Markdown("# 🎙️ Prateek's Voice Cloning Demo")
|
27 |
with gr.Row():
|
28 |
with gr.Column():
|
29 |
+
text_input = gr.Textbox(label="Enter the text you want to convert to speech", value="", max_lines=3)
|
30 |
+
lan_input = gr.Radio(label="Language", choices=["en"], value="en", visible=False)
|
31 |
+
radio = gr.Radio(["Record your voice", "Upload an audio file"], value="mic",
|
32 |
+
label="How would you like to provide your voice sample?")
|
33 |
audio_input_mic = gr.Audio(label="Record your voice", source="microphone", type="filepath", visible=True)
|
34 |
+
audio_input_file = gr.Audio(label="Upload an audio file", type="filepath", visible=False)
|
35 |
|
36 |
with gr.Row():
|
37 |
+
with gr.Column():
|
38 |
+
btn_clear = gr.Button("Clear")
|
39 |
+
with gr.Column():
|
40 |
+
btn = gr.Button("Generate Speech", variant="primary")
|
41 |
with gr.Column():
|
42 |
audio_output = gr.Audio(label="Generated Speech")
|
43 |
|
44 |
+
btn.click(text_to_speech, inputs=[text_input, audio_input_mic,
|
45 |
+
audio_input_file, lan_input], outputs=audio_output)
|
46 |
+
radio.change(toggle, radio, [audio_input_mic, audio_input_file])
|
47 |
|
48 |
+
demo.launch(enable_queue=True)
|