|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
SPEAKER_MODELS = { |
|
"Default": "kokoro/tts-default", |
|
"Speaker 1": "kokoro/tts-speaker1", |
|
"Speaker 2": "kokoro/tts-speaker2" |
|
} |
|
|
|
def kokoro_tts(text, speaker): |
|
|
|
tts_pipeline = pipeline("text-to-speech", model=SPEAKER_MODELS[speaker]) |
|
|
|
speech = tts_pipeline(text) |
|
return speech["waveform"] |
|
|
|
|
|
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() |