Offex commited on
Commit
aebcd2d
·
verified ·
1 Parent(s): 8faa3fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -15
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 numpy as np
 
5
 
6
- # मॉडल लोड करना (यह पहली बार में थोड़ा समय ले सकता है)
7
- kokoro = Kokoro("model.onnx", "voices.json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def generate_voice(text, voice_style):
10
- # आवाज़ जनरेट करने का फंक्शन
11
- samples, sample_rate = kokoro.create(text, voice=voice_style, speed=1.0, lang="en-us")
12
- sf.write("output.wav", samples, sample_rate)
13
- return "output.wav"
 
 
14
 
15
- # इंटरफेस डिज़ाइन
16
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
17
- gr.Markdown("# 🎙️ My Private Hyper-Realistic TTS")
18
- gr.Markdown("ElevenLabs जैसा अनुभव, अब बिना किसी लिमिट के।")
19
 
20
  with gr.Row():
21
- input_text = gr.Textbox(label="यहाँ अपना टेक्स्ट लिखें", lines=3)
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="तैयार आवाज़", type="filepath")
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