import gradio as gr from transformers import pipeline # Define a list of available speaker models 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): # 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["audio"] # Create a Gradio interface 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()