Spaces:
Running
Running
import gradio as gr | |
from gtts import gTTS | |
import os | |
import time | |
def read_hindi_text(text): | |
if not text.strip(): | |
return "❌ Please enter some text!" | |
# Generate TTS | |
tts = gTTS(text=text, lang='hi', slow=False) | |
filename = "hindi_output.mp3" | |
tts.save(filename) | |
# Play audio | |
try: | |
os.system("start " + filename) # Windows | |
# os.system("afplay " + filename) # Mac | |
# os.system("xdg-open " + filename) # Linux | |
output_message = f"✅ Hindi Text saved as '{filename}' and playing now!" | |
except Exception as e: | |
output_message = f"⚠️ Error playing the file: {str(e)}" | |
return output_message | |
# Gradio interface | |
iface = gr.Interface( | |
fn=read_hindi_text, | |
inputs=gr.Textbox(lines=4, placeholder="यहाँ हिंदी टेक्स्ट लिखें..."), | |
outputs="text", | |
title="Hindi Text-to-Speech", | |
description="हिंदी टेक्स्ट डालें और 'Read' बटन दबाएँ। टेक्स्ट को आवाज़ में बदला जाएगा।" | |
) | |
iface.launch() | |