thak123 commited on
Commit
f0626d2
·
verified ·
1 Parent(s): 8435823

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gtts import gTTS
2
+ import gradio as gr
3
+ import os
4
+
5
+ # Function to convert text to speech and save as an audio file
6
+ def text_to_speech(text, language="hr"):
7
+ # Create a gTTS object
8
+ tts = gTTS(text=text, lang=language, slow=False)
9
+
10
+ # Save the audio file
11
+ audio_file = "output.mp3"
12
+ tts.save(audio_file)
13
+
14
+ return audio_file
15
+
16
+ # Gradio interface
17
+ def tts_demo(text, language):
18
+ # Convert text to speech
19
+ audio_file = text_to_speech(text, language)
20
+
21
+ # Return the audio file to be played in the Gradio interface
22
+ return audio_file
23
+
24
+ # Define Gradio inputs and outputs
25
+ inputs = [
26
+ gr.Textbox(label="Enter Text", placeholder="Type something here..."),
27
+ gr.Dropdown(label="Language", choices=["en", "es", "fr", "de", "hr"], value="hr")
28
+ ]
29
+ outputs = gr.Audio(label="Generated Audio", type="filepath")
30
+
31
+ # Create the Gradio interface
32
+ iface = gr.Interface(
33
+ fn=tts_demo,
34
+ inputs=inputs,
35
+ outputs=outputs,
36
+ title="Text-to-Speech Demo",
37
+ description="Enter text and select a language to generate and play audio."
38
+ )
39
+
40
+ # Launch the app
41
+ iface.launch()