Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,43 @@
|
|
|
|
1 |
from kittentts import KittenTTS
|
|
|
|
|
|
|
2 |
m = KittenTTS("KittenML/kitten-tts-nano-0.1")
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
sf.write('output.wav', audio, 24000)
|
|
|
1 |
+
import gradio as gr
|
2 |
from kittentts import KittenTTS
|
3 |
+
|
4 |
+
# Initialize the KittenTTS model
|
5 |
+
# This model is lightweight and runs on the CPU
|
6 |
m = KittenTTS("KittenML/kitten-tts-nano-0.1")
|
7 |
|
8 |
+
def text_to_speech(text):
|
9 |
+
"""
|
10 |
+
Generates audio from the input text using the KittenTTS model.
|
11 |
+
|
12 |
+
Args:
|
13 |
+
text: The text to be converted to speech.
|
14 |
+
|
15 |
+
Returns:
|
16 |
+
A tuple containing the sample rate and the audio data as a NumPy array.
|
17 |
+
"""
|
18 |
+
# The KittenTTS model generates audio at a sample rate of 24000 Hz
|
19 |
+
sampling_rate = 24000
|
20 |
+
audio_numpy = m.generate(text)
|
21 |
+
return (sampling_rate, audio_numpy)
|
22 |
+
|
23 |
+
# Define the Gradio interface
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=text_to_speech,
|
26 |
+
inputs=gr.Textbox(
|
27 |
+
lines=3,
|
28 |
+
label="Text to Synthesize",
|
29 |
+
placeholder="Enter your text here..."
|
30 |
+
),
|
31 |
+
outputs=gr.Audio(label="Synthesized Speech"),
|
32 |
+
title="KittenTTS: Text-to-Speech",
|
33 |
+
description="A simple Gradio app to demonstrate the capabilities of the KittenTTS model. KittenTTS is a lightweight, high-quality text-to-speech model that can run on a CPU. [2]",
|
34 |
+
examples=[
|
35 |
+
["This high quality TTS model works without a GPU"],
|
36 |
+
["Gradio is a great tool for creating machine learning demos."],
|
37 |
+
["The quick brown fox jumps over the lazy dog."]
|
38 |
+
],
|
39 |
+
allow_flagging="never"
|
40 |
+
)
|
41 |
|
42 |
+
# Launch the Gradio app
|
43 |
+
iface.launch()
|
|