Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Hugging Face TTS pipelines | |
korean_tts = pipeline("text-to-speech", model="facebook/mms-tts-ko") | |
us_english_tts = pipeline("text-to-speech", model="facebook/mms-tts-en-US") | |
uk_english_tts = pipeline("text-to-speech", model="facebook/mms-tts-en-GB") | |
# Function to generate audio from text | |
def generate_audio(text, language): | |
if language == "Korean": | |
audio = korean_tts(text) | |
elif language == "US English": | |
audio = us_english_tts(text) | |
elif language == "UK English": | |
audio = uk_english_tts(text) | |
else: | |
return "Invalid language selection." | |
return audio["audio"] | |
# Gradio Interface | |
with gr.Blocks() as demo: | |
gr.Markdown("## Multilingual TTS Application") | |
with gr.Row(): | |
text_input = gr.Textbox(label="Enter text to convert to speech") | |
language_selector = gr.Dropdown( | |
choices=["Korean", "US English", "UK English"], label="Select language" | |
) | |
audio_output = gr.Audio(label="Generated Speech") | |
generate_button = gr.Button("Generate") | |
generate_button.click( | |
fn=generate_audio, inputs=[text_input, language_selector], outputs=audio_output | |
) | |
# Launch the app | |
demo.launch() |