File size: 1,027 Bytes
fc1fe4c
 
 
8a61d62
 
 
 
 
 
 
 
 
 
fc1fe4c
 
 
 
 
 
 
8a61d62
 
 
 
fc1fe4c
 
8a61d62
fc1fe4c
 
 
 
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
31
import gradio as gr
from transformers import pipeline

# Define a list of available speaker models
SPEAKER_MODELS = {
    "Default": "kokoro/tts-default",
    "Speaker 1": "kokoro/tts-speaker1",
    "Speaker 2": "kokoro/tts-speaker2"
}

def kokoro_tts(text, speaker):
    # Initialize the transformers pipeline for text-to-speech with the selected speaker model
    tts_pipeline = pipeline("text-to-speech", model=SPEAKER_MODELS[speaker])
    # Generate speech from text
    speech = tts_pipeline(text)
    return speech["waveform"]

# Create a Gradio interface
iface = gr.Interface(
    fn=kokoro_tts,
    inputs=[
        gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
        gr.inputs.Dropdown(choices=list(SPEAKER_MODELS.keys()), label="Select Speaker")
    ],
    outputs=gr.outputs.Audio(label="Generated Speech"),
    title="Kokoro Text-to-Speech",
    description="A Text-to-Speech app powered by Kokoro and Transformers.js with multiple speaker options"
)

if __name__ == "__main__":
    iface.launch()