mprateek commited on
Commit
d7346fe
1 Parent(s): 2b181f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from TTS.api import TTS
3
+
4
+ # Initialize the Text-to-Speech models
5
+ tts_engine = TTS(model_name="tts_models/en/global/your_tts", progress_bar=False, gpu=False)
6
+
7
+ # Function to convert text to speech
8
+ def convert_text_to_speech(input_text: str, audio_source, audio_file_path, language: str = "en"):
9
+ output_audio_path = "generated_speech.wav"
10
+ if audio_file_path and not audio_source:
11
+ audio_source = audio_file_path
12
+
13
+ # Generate speech using the TTS engine
14
+ if audio_source is not None:
15
+ tts_engine.tts_to_file(input_text, speaker_wav=audio_source, language=language, file_path=output_audio_path)
16
+ else:
17
+ tts_engine.tts_to_file(input_text, speaker=tts_engine.speakers[0], language=language, file_path=output_audio_path)
18
+
19
+ return output_audio_path
20
+
21
+ # Gradio interface setup
22
+ title = "Enhanced Voice-Cloning Interface"
23
+
24
+ def audio_input_toggle(choice):
25
+ """Toggle audio input method based on user choice."""
26
+ if choice == "mic":
27
+ return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
28
+ else:
29
+ return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
30
+
31
+ with gr.Blocks() as enhanced_demo:
32
+ with gr.Row():
33
+ with gr.Column():
34
+ text_input = gr.Textbox(label="Enter your text here", value="", max_lines=3)
35
+ gr.Markdown("### Note: This demo currently supports English only.")
36
+ audio_method = gr.Radio(["mic", "file"], value="mic", label="Select your audio input method:")
37
+ audio_input_mic = gr.Audio(label="Record your voice", source="microphone", type="filepath", visible=True)
38
+ audio_input_file = gr.Audio(label="Upload your voice file", type="filepath", visible=False)
39
+
40
+ with gr.Row():
41
+ btn_clear = gr.Button("Clear")
42
+ btn_submit = gr.Button("Generate Speech", variant="primary")
43
+ with gr.Column():
44
+ audio_output = gr.Audio(label="Generated Speech")
45
+
46
+ btn_submit.click(convert_text_to_speech, inputs=[text_input, audio_input_mic, audio_input_file], outputs=audio_output)
47
+ audio_method.change(audio_input_toggle, audio_method, [audio_input_mic, audio_input_file])
48
+
49
+ enhanced_demo.launch(enable_queue=True)