Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,40 @@
|
|
1 |
-
|
2 |
-
|
3 |
from TTS.api import TTS
|
4 |
-
import torch
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
# Initialize the TTS model
|
9 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
10 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
-
tts.to(device)
|
12 |
|
13 |
# Get available voices and languages
|
14 |
available_voices = tts.list_speakers()
|
15 |
available_languages = tts.list_languages()
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
language
|
|
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
return {"languages": available_languages}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
raise HTTPException(status_code=400, detail="Invalid voice selected")
|
34 |
-
if request.language not in available_languages:
|
35 |
-
raise HTTPException(status_code=400, detail="Invalid language selected")
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
from TTS.api import TTS
|
|
|
4 |
|
5 |
+
# Set the environment variable to agree to the terms of service
|
6 |
+
os.environ["COQUI_TOS_AGREED"] = "1"
|
7 |
|
8 |
# Initialize the TTS model
|
9 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
|
|
|
|
10 |
|
11 |
# Get available voices and languages
|
12 |
available_voices = tts.list_speakers()
|
13 |
available_languages = tts.list_languages()
|
14 |
|
15 |
+
def generate_speech(text, voice, language):
|
16 |
+
# Generate speech
|
17 |
+
output_path = "output.wav"
|
18 |
+
tts.tts_to_file(text=text, speaker_wav=voice, language=language, file_path=output_path)
|
19 |
+
return output_path
|
20 |
|
21 |
+
# Create Gradio interface
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("# XTTS v2 Text-to-Speech Generator")
|
24 |
|
25 |
+
with gr.Row():
|
26 |
+
text_input = gr.Textbox(label="Input Text", placeholder="Enter text to be synthesized")
|
|
|
27 |
|
28 |
+
with gr.Row():
|
29 |
+
voice_dropdown = gr.Dropdown(label="Select Voice", choices=available_voices)
|
30 |
+
language_dropdown = gr.Dropdown(label="Select Language", choices=available_languages)
|
|
|
|
|
|
|
31 |
|
32 |
+
with gr.Row():
|
33 |
+
generate_button = gr.Button("Generate Speech")
|
34 |
+
|
35 |
+
with gr.Row():
|
36 |
+
audio_output = gr.Audio(label="Generated Speech")
|
37 |
+
|
38 |
+
generate_button.click(generate_speech, inputs=[text_input, voice_dropdown, language_dropdown], outputs=audio_output)
|
39 |
+
|
40 |
+
demo.launch(debug=True)
|