File size: 1,194 Bytes
d027c33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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()