Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
-
import
|
| 4 |
-
import scipy.io.wavfile
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
MODEL_NAME = "
|
| 8 |
-
tts = TTS(model_name=MODEL_NAME)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
if not text.strip():
|
| 13 |
-
return None, "براہ کرم اردو جملہ لکھیں"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
with gr.Blocks() as demo:
|
| 26 |
-
gr.Markdown("# 🇵🇰 Urdu Text to Speech App (Coqui TTS)")
|
| 27 |
-
input_text = gr.Textbox(label="اردو میں جملہ لکھیں", placeholder="مثال: آج کا موسم خوشگوار ہے۔")
|
| 28 |
-
output_audio = gr.Audio(label="آواز سنیں", type="filepath")
|
| 29 |
-
status = gr.Textbox(label="اسٹیٹس")
|
| 30 |
-
|
| 31 |
-
generate_btn = gr.Button("آواز بنائیں")
|
| 32 |
-
generate_btn.click(fn=urdu_tts, inputs=[input_text], outputs=[output_audio, status])
|
| 33 |
-
|
| 34 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
+
import os
|
|
|
|
| 4 |
|
| 5 |
+
# ✅ Correct model name format for local loading
|
| 6 |
+
MODEL_NAME = "tts_models/ur/mai/mai_400k"
|
|
|
|
| 7 |
|
| 8 |
+
# ✅ Load TTS model
|
| 9 |
+
tts = TTS(MODEL_NAME)
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# ✅ Text-to-Speech function
|
| 12 |
+
def tts_fn(text):
|
| 13 |
+
output_path = "output.wav"
|
| 14 |
+
tts.tts_to_file(text=text, file_path=output_path)
|
| 15 |
+
return output_path
|
| 16 |
|
| 17 |
+
# ✅ Gradio interface
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=tts_fn,
|
| 20 |
+
inputs=gr.Textbox(label="اردو متن درج کریں", lines=3, placeholder="مثلاً: میرا نام نجم علی ہے"),
|
| 21 |
+
outputs=gr.Audio(type="filepath", label="آواز"),
|
| 22 |
+
title="اردو TTS ایپ (Coqui)",
|
| 23 |
+
description="یہ ایپ کوکی کا اردو TTS ماڈل استعمال کرتی ہے۔"
|
| 24 |
+
)
|
| 25 |
|
| 26 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|