azils3 commited on
Commit
ec3f74a
1 Parent(s): 1152fcf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from TTS.api import TTS
3
+
4
+ # Initialize the TTS model
5
+ tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
6
+
7
+ # Get available voices and languages
8
+ available_voices = tts.list_speakers()
9
+ available_languages = tts.list_languages()
10
+
11
+ def generate_speech(text, voice, language):
12
+ # Generate speech
13
+ output_path = "output.wav"
14
+ tts.tts_to_file(text=text, speaker_wav=voice, language=language, file_path=output_path)
15
+ return output_path
16
+
17
+ # Create Gradio interface
18
+ with gr.Blocks() as demo:
19
+ gr.Markdown("# XTTS v2 Text-to-Speech Generator")
20
+
21
+ with gr.Row():
22
+ text_input = gr.Textbox(label="Input Text", placeholder="Enter text to be synthesized")
23
+
24
+ with gr.Row():
25
+ voice_dropdown = gr.Dropdown(label="Select Voice", choices=available_voices)
26
+ language_dropdown = gr.Dropdown(label="Select Language", choices=available_languages)
27
+
28
+ with gr.Row():
29
+ generate_button = gr.Button("Generate Speech")
30
+
31
+ with gr.Row():
32
+ audio_output = gr.Audio(label="Generated Speech")
33
+
34
+ generate_button.click(generate_speech, inputs=[text_input, voice_dropdown, language_dropdown], outputs=audio_output)
35
+
36
+ demo.launch(debug=True)