MK-316 commited on
Commit
08c2be2
1 Parent(s): 87ebcee

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gtts import gTTS
3
+ import os
4
+
5
+ def generate_speech(text, language):
6
+ tts = gTTS(text=text, lang=language)
7
+ tts.save("output.mp3")
8
+ return "output.mp3"
9
+
10
+ language_options = {
11
+ "American English": 'en',
12
+ "Korean": 'ko',
13
+ "Mandarin(Chinese mainland)": 'zh-CN',
14
+ "Japanese": 'jp',
15
+ "Spanish": 'es',
16
+ "French": 'fr'
17
+ # Add more languages as needed
18
+ }
19
+
20
+ iface = gr.Interface(
21
+ fn=generate_speech,
22
+ inputs=[
23
+ gr.Textbox(lines=2, placeholder="Enter text here..."),
24
+ gr.Radio(choices=list(language_options.keys()), label="Language")
25
+ ],
26
+ outputs="audio",
27
+ title="Text-to-Speech Converter",
28
+ description="Enter text and choose a language to convert text to speech."
29
+ )
30
+
31
+ def process_text_and_language(text, language):
32
+ language_code = language_options[language]
33
+ return generate_speech(text, language_code)
34
+
35
+ iface = gr.Interface(
36
+ fn=process_text_and_language,
37
+ inputs=[
38
+ gr.Textbox(lines=2, placeholder="Enter text here..."),
39
+ gr.Radio(choices=list(language_options.keys()), label="Language")
40
+ ],
41
+ outputs="audio",
42
+ title="Text-to-Speech Converter",
43
+ description="Enter text and choose a language to convert text to speech."
44
+ )
45
+
46
+ iface.launch()