Ramzan0553 commited on
Commit
efff306
·
verified ·
1 Parent(s): 8d7da91

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gtts import gTTS
2
+ import gradio as gr
3
+ import tempfile
4
+
5
+ def text_to_speech(text, lang='en', slow=False):
6
+ try:
7
+ # Create temporary file
8
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
9
+ tts = gTTS(text=text, lang=lang, slow=slow)
10
+ tts.save(tmp.name)
11
+ return tmp.name
12
+ except Exception as e:
13
+ return f"❌ Error: {str(e)}"
14
+
15
+ iface = gr.Interface(
16
+ fn=text_to_speech,
17
+ inputs=[
18
+ gr.Textbox(label="Enter text", placeholder="Type something..."),
19
+ gr.Dropdown(choices=["en", "es", "fr", "de", "ur", "hi"], value="en", label="Language"),
20
+ gr.Checkbox(label="Slow mode")
21
+ ],
22
+ outputs=gr.Audio(type="filepath", label="Generated Audio"),
23
+ title="🗣️ Text-to-Speech Converter",
24
+ description="Converts text into speech using Google TTS (gTTS)."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ iface.launch()