File size: 879 Bytes
1269a6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
import torch
from transformers import AutoProcessor, AutoModel

# Load Kokoro TTS Model
device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "hexgrad/Kokoro-82M"
model = AutoModel.from_pretrained(model_name).to(device)
processor = AutoProcessor.from_pretrained(model_name)

def text_to_speech(text):
    """Convert input text to speech using Kokoro TTS"""
    inputs = processor(text, return_tensors="pt").to(device)
    with torch.no_grad():
        output = model.generate(**inputs)
    return output.cpu().numpy()

# Gradio Interface
description = "Enter text and listen to the Kokoro TTS model read it aloud."

demo = gr.Interface(
    fn=text_to_speech,
    inputs=gr.Textbox(placeholder="Type something here..."),
    outputs=gr.Audio(type="numpy"),
    title="Kokoro TTS - Text-to-Speech",
    description=description,
)

demo.launch()