Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from kittentts import KittenTTS
|
| 3 |
+
import soundfile as sf
|
| 4 |
+
import numpy as np
|
| 5 |
+
import tempfile
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# Load model
|
| 9 |
+
model = KittenTTS("KittenML/kitten-tts-nano-0.1")
|
| 10 |
+
|
| 11 |
+
# Function to generate audio
|
| 12 |
+
def tts_generate(text):
|
| 13 |
+
audio = model.generate(text)
|
| 14 |
+
|
| 15 |
+
# Save audio to a temporary file
|
| 16 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 17 |
+
sf.write(tmp_file.name, audio, 24000)
|
| 18 |
+
tmp_path = tmp_file.name
|
| 19 |
+
|
| 20 |
+
return tmp_path
|
| 21 |
+
|
| 22 |
+
# Gradio interface
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=tts_generate,
|
| 25 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text to synthesize..."),
|
| 26 |
+
outputs=gr.Audio(type="filepath"),
|
| 27 |
+
title="🐱 KittenTTS: Text-to-Speech",
|
| 28 |
+
description="Generate speech from text using KittenTTS Nano model (runs on CPU!)"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|