Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,12 @@ from TTS.api import TTS
|
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
# Load multilingual TTS model
|
| 7 |
model_name = "tts_models/multilingual/multi-dataset/your_tts"
|
| 8 |
tts = TTS(model_name)
|
| 9 |
|
| 10 |
-
# Get available
|
|
|
|
| 11 |
available_speakers = tts.speakers
|
| 12 |
|
| 13 |
def text_to_speech(text, language, speaker_name, speed, pitch):
|
|
@@ -16,15 +17,18 @@ def text_to_speech(text, language, speaker_name, speed, pitch):
|
|
| 16 |
if not text.strip():
|
| 17 |
raise ValueError("Please enter some text")
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
params = {
|
| 21 |
"text": text,
|
| 22 |
"speaker": speaker_name,
|
| 23 |
"language": language,
|
| 24 |
-
"file_path": None
|
| 25 |
}
|
| 26 |
|
| 27 |
-
# Add optional parameters
|
| 28 |
if speed != 1.0:
|
| 29 |
params["speed"] = speed
|
| 30 |
if pitch != 1.0:
|
|
@@ -45,14 +49,14 @@ def create_download_link(audio_file):
|
|
| 45 |
return gr.DownloadButton(label="Download Audio", value=audio_file)
|
| 46 |
|
| 47 |
with gr.Blocks(title="Enhanced TTS App") as app:
|
| 48 |
-
gr.Markdown("# Enhanced
|
| 49 |
-
gr.Markdown("
|
| 50 |
|
| 51 |
with gr.Row():
|
| 52 |
with gr.Column():
|
| 53 |
-
text_input = gr.Textbox(label="Enter text
|
| 54 |
-
language = gr.Dropdown(choices=
|
| 55 |
-
speaker = gr.Dropdown(choices=available_speakers, label="Voice
|
| 56 |
|
| 57 |
with gr.Accordion("Advanced Settings", open=False):
|
| 58 |
speed = gr.Slider(minimum=0.5, maximum=2.0, value=1.0, step=0.1,
|
|
@@ -80,10 +84,12 @@ with gr.Blocks(title="Enhanced TTS App") as app:
|
|
| 80 |
outputs=download_section
|
| 81 |
)
|
| 82 |
|
|
|
|
| 83 |
gr.Examples(
|
| 84 |
examples=[
|
| 85 |
["Hello, welcome to our text-to-speech application!", "en", available_speakers[0], 1.0, 1.0],
|
| 86 |
-
["
|
|
|
|
| 87 |
],
|
| 88 |
inputs=[text_input, language, speaker, speed, pitch],
|
| 89 |
outputs=audio_output,
|
|
|
|
| 3 |
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
# Load multilingual TTS model
|
| 7 |
model_name = "tts_models/multilingual/multi-dataset/your_tts"
|
| 8 |
tts = TTS(model_name)
|
| 9 |
|
| 10 |
+
# Get available languages and speakers
|
| 11 |
+
available_languages = list(tts.languages) # ['en', 'fr-fr', 'pt-br']
|
| 12 |
available_speakers = tts.speakers
|
| 13 |
|
| 14 |
def text_to_speech(text, language, speaker_name, speed, pitch):
|
|
|
|
| 17 |
if not text.strip():
|
| 18 |
raise ValueError("Please enter some text")
|
| 19 |
|
| 20 |
+
if language not in available_languages:
|
| 21 |
+
raise ValueError(f"Language '{language}' not supported by this model")
|
| 22 |
+
|
| 23 |
+
# Create parameters dictionary
|
| 24 |
params = {
|
| 25 |
"text": text,
|
| 26 |
"speaker": speaker_name,
|
| 27 |
"language": language,
|
| 28 |
+
"file_path": None
|
| 29 |
}
|
| 30 |
|
| 31 |
+
# Add optional parameters
|
| 32 |
if speed != 1.0:
|
| 33 |
params["speed"] = speed
|
| 34 |
if pitch != 1.0:
|
|
|
|
| 49 |
return gr.DownloadButton(label="Download Audio", value=audio_file)
|
| 50 |
|
| 51 |
with gr.Blocks(title="Enhanced TTS App") as app:
|
| 52 |
+
gr.Markdown("# Enhanced Multilingual Text-to-Speech")
|
| 53 |
+
gr.Markdown(f"Supported languages: {', '.join(available_languages)}")
|
| 54 |
|
| 55 |
with gr.Row():
|
| 56 |
with gr.Column():
|
| 57 |
+
text_input = gr.Textbox(label="Enter text", lines=5)
|
| 58 |
+
language = gr.Dropdown(choices=available_languages, label="Language", value="en")
|
| 59 |
+
speaker = gr.Dropdown(choices=available_speakers, label="Voice")
|
| 60 |
|
| 61 |
with gr.Accordion("Advanced Settings", open=False):
|
| 62 |
speed = gr.Slider(minimum=0.5, maximum=2.0, value=1.0, step=0.1,
|
|
|
|
| 84 |
outputs=download_section
|
| 85 |
)
|
| 86 |
|
| 87 |
+
# Update examples to only use supported languages
|
| 88 |
gr.Examples(
|
| 89 |
examples=[
|
| 90 |
["Hello, welcome to our text-to-speech application!", "en", available_speakers[0], 1.0, 1.0],
|
| 91 |
+
["Bonjour, bienvenue dans notre application!", "fr-fr", available_speakers[-1], 1.0, 1.0],
|
| 92 |
+
["Olá, bem-vindo ao nosso aplicativo!", "pt-br", available_speakers[0], 1.0, 1.0]
|
| 93 |
],
|
| 94 |
inputs=[text_input, language, speaker, speed, pitch],
|
| 95 |
outputs=audio_output,
|