Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from kokoro_onnx import Kokoro
|
| 3 |
import soundfile as sf
|
| 4 |
-
import
|
|
|
|
| 5 |
|
| 6 |
-
# मॉडल
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def generate_voice(text, voice_style):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 17 |
-
gr.Markdown("# 🎙️
|
| 18 |
-
gr.Markdown("ElevenLabs जैसा अनुभव, अब बिना किसी लिमिट के।")
|
| 19 |
|
| 20 |
with gr.Row():
|
| 21 |
-
input_text = gr.Textbox(label="यहाँ
|
| 22 |
-
# यहाँ आप अलग-अलग स्टाइल चुन सकते हैं (Bella, Adam, etc. के विकल्प यहाँ मिल जाएंगे)
|
| 23 |
voice_opt = gr.Dropdown(
|
| 24 |
-
choices=["af_bella", "af_sarah", "am_adam", "am_michael"],
|
| 25 |
value="af_bella",
|
| 26 |
-
label="
|
| 27 |
)
|
| 28 |
|
| 29 |
submit_btn = gr.Button("Generate Audio", variant="primary")
|
| 30 |
-
audio_out = gr.Audio(label="
|
| 31 |
|
| 32 |
submit_btn.click(generate_voice, inputs=[input_text, voice_opt], outputs=audio_out)
|
| 33 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from kokoro_onnx import Kokoro
|
| 3 |
import soundfile as sf
|
| 4 |
+
import os
|
| 5 |
+
import urllib.request
|
| 6 |
|
| 7 |
+
# मॉडल और वॉइस फाइल डाउनलोड करने का फंक्शन
|
| 8 |
+
def download_files():
|
| 9 |
+
files = {
|
| 10 |
+
"model.onnx": "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0/kokoro-v1.0.onnx",
|
| 11 |
+
"voices.bin": "https://github.com/thewh1teagle/kokoro-onnx/releases/download/model-files-v1.0/voices-v1.0.bin"
|
| 12 |
+
}
|
| 13 |
+
for name, url in files.items():
|
| 14 |
+
if not os.path.exists(name):
|
| 15 |
+
print(f"Downloading {name}...")
|
| 16 |
+
urllib.request.urlretrieve(url, name)
|
| 17 |
+
|
| 18 |
+
# फाइलें डाउनलोड करें
|
| 19 |
+
download_files()
|
| 20 |
+
|
| 21 |
+
# अब Kokoro को लोड करें (Error नहीं आएगा)
|
| 22 |
+
kokoro = Kokoro("model.onnx", "voices.bin")
|
| 23 |
|
| 24 |
def generate_voice(text, voice_style):
|
| 25 |
+
try:
|
| 26 |
+
samples, sample_rate = kokoro.create(text, voice=voice_style, speed=1.0, lang="en-us")
|
| 27 |
+
sf.write("output.wav", samples, sample_rate)
|
| 28 |
+
return "output.wav"
|
| 29 |
+
except Exception as e:
|
| 30 |
+
return str(e)
|
| 31 |
|
| 32 |
+
# UI डिज़ाइन
|
| 33 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 34 |
+
gr.Markdown("# 🎙️ Hyper-Realistic TTS (Free ElevenLabs Alternative)")
|
|
|
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
+
input_text = gr.Textbox(label="यहाँ टेक्स्ट लिखें", lines=3, placeholder="Hello, how can I help you today?")
|
|
|
|
| 38 |
voice_opt = gr.Dropdown(
|
| 39 |
+
choices=["af_bella", "af_sarah", "am_adam", "am_michael", "am_fenrir", "af_sky"],
|
| 40 |
value="af_bella",
|
| 41 |
+
label="Voice Style (Bella/Adam are best)"
|
| 42 |
)
|
| 43 |
|
| 44 |
submit_btn = gr.Button("Generate Audio", variant="primary")
|
| 45 |
+
audio_out = gr.Audio(label="Download Audio", type="filepath")
|
| 46 |
|
| 47 |
submit_btn.click(generate_voice, inputs=[input_text, voice_opt], outputs=audio_out)
|
| 48 |
|