Download app.py from akashdeb/TTS: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/spaces/akashdeb/TTS/resolve/main/app.py
- Command line
-
hf download hf://spaces/akashdeb/TTS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/akashdeb/TTS/resolve/main/app.py
1.83 kB
| import gradio as gr | |
| import torch | |
| from transformers import pipeline | |
| # Load the available pre-trained TTS models from Hugging Face | |
| models = { | |
| "FastSpeech2": "espnet/fastspeech2-ljspeech", | |
| "Tacotron2": "tacotron2-ljspeech", | |
| "Glow-TTS": "glow-tts-ljspeech" | |
| } | |
| # Set up a function to generate TTS from selected model | |
| def generate_audio(model_name, input_text): | |
| # Load the model using the Hugging Face pipeline | |
| if model_name == "FastSpeech2": | |
| model = pipeline("text-to-speech", model="espnet/fastspeech2-ljspeech") | |
| elif model_name == "Tacotron2": | |
| model = pipeline("text-to-speech", model="tacotron2-ljspeech") | |
| elif model_name == "Glow-TTS": | |
| model = pipeline("text-to-speech", model="glow-tts-ljspeech") | |
| # Generate the audio from the input text | |
| audio = model(input_text) | |
| return audio | |
| # Create a Gradio interface with model selection and text input | |
| def gradio_interface(): | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### Select a model, input text and generate audio.") | |
| # Dropdown to select model | |
| model_dropdown = gr.Dropdown(choices=list(models.keys()), label="Select TTS Model", default="FastSpeech2") | |
| # Text input for user input text | |
| text_input = gr.Textbox(label="Input Text", placeholder="Type your text here...") | |
| # Button to generate audio | |
| generate_button = gr.Button("Generate Audio") | |
| # Output audio player | |
| audio_output = gr.Audio(type="filepath", label="Generated Audio") | |
| # Generate audio when button is clicked | |
| generate_button.click(fn=generate_audio, inputs=[model_dropdown, text_input], outputs=audio_output) | |
| demo.launch() | |
| if __name__ == "__main__": | |
| gradio_interface() | |