Spaces:
Sleeping
Sleeping
Download app.py from ananthakrishnan171/Text_To_Audio: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/ananthakrishnan171/Text_To_Audio/resolve/main/app.py
- Command line
-
hf download hf://spaces/ananthakrishnan171/Text_To_Audio/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ananthakrishnan171/Text_To_Audio/resolve/main/app.py
1.19 kB
| import gradio as gr | |
| import torch | |
| from bark import SAMPLE_RATE, generate_audio | |
| from scipy.io.wavfile import write as write_wav | |
| import tempfile | |
| def generate_voice(text_prompt, language): | |
| if not text_prompt.strip() or text_prompt.isnumeric(): | |
| return None, "Please enter valid text." | |
| try: | |
| audio_array = generate_audio(text_prompt) | |
| audio_array = audio_array.cpu().numpy() | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as fp: | |
| write_wav(fp.name, SAMPLE_RATE, audio_array) | |
| return fp.name, "Audio generated successfully!" | |
| except Exception as e: | |
| return None, f"Error: {str(e)}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# ๐ Text to Speech Generator (Multi-Language Bark TTS GPU) ๐") | |
| txt = gr.Textbox(label="Enter Text") | |
| lang = gr.Dropdown( | |
| choices=["English", "Tamil", "Hindi", "French"], | |
| label="Select Language" | |
| ) | |
| btn = gr.Button("Generate Audio") | |
| audio = gr.Audio(label="Generated Audio", type="filepath") | |
| output_text = gr.Textbox(label="Status Message") | |
| btn.click(fn=generate_voice, inputs=[txt, lang], outputs=[audio, output_text]) | |
| demo.launch() | |