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()