| import gradio as gr |
| import torch |
| from TTS.api import TTS |
|
|
| |
| device = "cuda" if torch.cuda.is_available() else "cpu" |
|
|
| |
| tts = TTS(model_name="tts_models/en/ljspeech/fast_pitch", progress_bar=False) |
|
|
| def generate_audio(text): |
| """Function to synthesize speech from text.""" |
| output_path = "output.wav" |
| print("Generating audio...") |
|
|
| |
| tts.tts_to_file(text, file_path=output_path) |
|
|
| print("Audio saved:", output_path) |
| return output_path |
|
|
| |
| interface = gr.Interface( |
| fn=generate_audio, |
| inputs=gr.Textbox(label="Enter text"), |
| outputs=gr.Audio(label="Generated Speech"), |
| title="Coqui TTS Text-to-Speech", |
| description="Enter text and click **Synthesize** to generate speech.", |
| live=True |
| ) |
|
|
| |
| if __name__ == "__main__": |
| interface.launch(share=True) |
|
|