Spaces:
Running
Running
File size: 1,132 Bytes
fb93a17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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()
|