|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
SPEAKER_MODELS = { |
|
"Default": "onnx-community/Kokoro-82M-ONNX", |
|
"Speaker 1": "onnx-community/Kokoro-82M-ONNX", |
|
"Speaker 2": "onnx-community/Kokoro-82M-ONNX" |
|
} |
|
|
|
def kokoro_tts(text, speaker): |
|
|
|
tts_pipeline = pipeline("text-to-speech", model=SPEAKER_MODELS[speaker]) |
|
|
|
speech = tts_pipeline(text) |
|
return speech["audio"] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=kokoro_tts, |
|
inputs=[ |
|
gr.Textbox(lines=2, placeholder="Enter text here..."), |
|
gr.Dropdown(choices=list(SPEAKER_MODELS.keys()), label="Select Speaker") |
|
], |
|
outputs=gr.Audio(label="Generated Speech"), |
|
title="Kokoro Text-to-Speech", |
|
description="A Text-to-Speech app powered by Hugging Face Transformers.js with multiple speaker options" |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |