File size: 1,660 Bytes
7a0c265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import gradio as gr
from gtts import gTTS
import uuid

def text_to_speech(text, lang, speed):
    slow = True if speed == "Slow" else False
    filename = f"{uuid.uuid4()}.mp3"
    tts = gTTS(text, lang=lang, slow=slow)
    tts.save(filename)
    return filename

demo = gr.Interface(
    fn=text_to_speech,
    inputs=[
        gr.Textbox(label="Enter Text"),
        gr.Dropdown(
            label="Language",
            choices=[
                ("English", "en"),
                ("Spanish", "es"),
                ("French", "fr"),
                ("German", "de"),
                ("Italian", "it"),
                ("Japanese", "ja"),
                ("Korean", "ko"),
                ("Russian", "ru"),
                ("Chinese (Simplified)", "zh-CN"),
                ("Portuguese", "pt"),
                ("Hindi", "hi"),
                ("Arabic", "ar"),
                ("Bengali", "bn"),
                ("Dutch", "nl"),
                ("Greek", "el"),
                ("Hungarian", "hu"),
                ("Indonesian", "id"),
                ("Polish", "pl"),
                ("Swedish", "sv"),
                ("Thai", "th"),
                ("Turkish", "tr"),
                ("Vietnamese", "vi")
            ],
            value="en"
        ),
        gr.Dropdown(
            label="Speed",
            choices=["Normal", "Slow"],
            value="Normal"
        )
    ],
    outputs=gr.Audio(label="Generated Speech", type="filepath"),
    title="Text to Speech Converter",
    description="Type something and convert it into speech using gTTS with language and speed selection.",
    theme="gradio/space"
)

demo.launch(share=True)