Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gtts import gTTS
|
| 3 |
+
import os
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
def read_hindi_text(text):
|
| 7 |
+
if not text.strip():
|
| 8 |
+
return "❌ Please enter some text!"
|
| 9 |
+
|
| 10 |
+
# Generate TTS
|
| 11 |
+
tts = gTTS(text=text, lang='hi', slow=False)
|
| 12 |
+
filename = "hindi_output.mp3"
|
| 13 |
+
tts.save(filename)
|
| 14 |
+
|
| 15 |
+
# Play audio
|
| 16 |
+
try:
|
| 17 |
+
os.system("start " + filename) # Windows
|
| 18 |
+
# os.system("afplay " + filename) # Mac
|
| 19 |
+
# os.system("xdg-open " + filename) # Linux
|
| 20 |
+
output_message = f"✅ Hindi Text saved as '{filename}' and playing now!"
|
| 21 |
+
except Exception as e:
|
| 22 |
+
output_message = f"⚠️ Error playing the file: {str(e)}"
|
| 23 |
+
|
| 24 |
+
return output_message
|
| 25 |
+
|
| 26 |
+
# Gradio interface
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=read_hindi_text,
|
| 29 |
+
inputs=gr.Textbox(lines=4, placeholder="यहाँ हिंदी टेक्स्ट लिखें..."),
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="Hindi Text-to-Speech",
|
| 32 |
+
description="हिंदी टेक्स्ट डालें और 'Read' बटन दबाएँ। टेक्स्ट को आवाज़ में बदला जाएगा।"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
iface.launch()
|