| import gradio as gr |
| from kittentts import KittenTTS |
| import soundfile as sf |
| import os |
|
|
| |
| |
| |
| |
| |
| try: |
| model = KittenTTS(".") |
| except Exception: |
| model = KittenTTS("KittenML/kitten-tts-mini-0.8") |
|
|
| |
| AVAILABLE_VOICES =['Bella', 'Jasper', 'Luna', 'Bruno', 'Rosie', 'Hugo', 'Kiki', 'Leo'] |
|
|
| |
| def synthesize_audio(text, voice): |
| |
| audio = model.generate(text, voice=voice) |
| |
| |
| output_path = "output.wav" |
| sf.write(output_path, audio, 24000) |
| |
| return output_path |
|
|
| |
| with gr.Blocks(title="Kitten TTS Mini") as demo: |
| gr.Markdown("# 🐱 Kitten TTS Mini 0.8") |
| gr.Markdown("Type some text below to generate speech using your uploaded ONNX model!") |
| |
| with gr.Row(): |
| with gr.Column(): |
| text_input = gr.Textbox(label="Text to Speak", placeholder="Hello, I am a lightweight AI...", lines=4) |
| voice_dropdown = gr.Dropdown(choices=AVAILABLE_VOICES, value="Jasper", label="Select Voice") |
| generate_btn = gr.Button("Generate Speech", variant="primary") |
| |
| with gr.Column(): |
| audio_output = gr.Audio(label="Generated Audio", type="filepath") |
| |
| |
| generate_btn.click( |
| fn=synthesize_audio, |
| inputs=[text_input, voice_dropdown], |
| outputs=audio_output |
| ) |
|
|
| |
| if __name__ == "__main__": |
| demo.launch() |