Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,54 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from kokoro import
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load model once at startup
|
| 6 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
|
| 8 |
-
|
| 9 |
-
VOICE = "af_heart"
|
| 10 |
|
| 11 |
-
print("π Loading Kokoro
|
| 12 |
-
|
| 13 |
-
print("β
|
| 14 |
|
| 15 |
|
| 16 |
-
def generate_audio(text):
|
| 17 |
if not text.strip():
|
| 18 |
return None, "Please enter some text."
|
| 19 |
|
| 20 |
try:
|
| 21 |
-
print("π€ Generating
|
| 22 |
-
audio = tts
|
| 23 |
-
return (
|
| 24 |
except Exception as e:
|
| 25 |
return None, f"Error: {str(e)}"
|
| 26 |
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
placeholder="Type something to speak...",
|
| 36 |
-
lines=4
|
| 37 |
-
)
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
fn=generate_audio,
|
| 47 |
-
inputs=
|
| 48 |
-
outputs=[
|
| 49 |
)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from kokoro import Kokoro
|
| 3 |
import torch
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 7 |
|
| 8 |
+
print("π Loading Kokoro model...")
|
| 9 |
+
model = Kokoro(device=device)
|
| 10 |
+
print("β
Kokoro loaded!")
|
| 11 |
|
| 12 |
|
| 13 |
+
def generate_audio(text, voice):
|
| 14 |
if not text.strip():
|
| 15 |
return None, "Please enter some text."
|
| 16 |
|
| 17 |
try:
|
| 18 |
+
print("π€ Generating...")
|
| 19 |
+
audio = model.tts(text, voice=voice) # numpy float32 array
|
| 20 |
+
return (24000, audio), "Success!"
|
| 21 |
except Exception as e:
|
| 22 |
return None, f"Error: {str(e)}"
|
| 23 |
|
| 24 |
|
| 25 |
+
voices = [
|
| 26 |
+
"af_heart",
|
| 27 |
+
"af_bella",
|
| 28 |
+
"af_nicole",
|
| 29 |
+
"am_adam",
|
| 30 |
+
"am_michael",
|
| 31 |
+
"bf_emma",
|
| 32 |
+
"bm_george"
|
| 33 |
+
]
|
| 34 |
|
| 35 |
+
|
| 36 |
+
with gr.Blocks(title="Kokoro-TTS") as demo:
|
| 37 |
+
gr.Markdown("## π§ Kokoro Text β Speech")
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
+
txt = gr.Textbox(lines=4, label="Input Text")
|
| 41 |
+
voice_select = gr.Dropdown(voices, value="af_heart", label="Voice")
|
| 42 |
+
|
| 43 |
+
audio_out = gr.Audio(label="Generated Audio")
|
| 44 |
+
status = gr.Textbox(label="Status")
|
| 45 |
|
| 46 |
+
btn = gr.Button("Generate Audio")
|
| 47 |
|
| 48 |
+
btn.click(
|
| 49 |
fn=generate_audio,
|
| 50 |
+
inputs=[txt, voice_select],
|
| 51 |
+
outputs=[audio_out, status]
|
| 52 |
)
|
| 53 |
|
| 54 |
+
demo.launch()
|
|
|