import gradio as gr from TTS.api import TTS # Use a model that does not require licensing confirmation # Example: "tts_models/en/ljspeech/tacotron2-DDC" tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=True, gpu=False) # List of available speakers (this can vary based on the model you choose) available_speakers = ["LJSpeech"] def text_to_speech(text, speaker_id): # Generate speech to a file file_path = "output.wav" tts.tts_to_file(text=text, speaker=speaker_id, language="en", file_path=file_path) return file_path # Create the Gradio interface iface = gr.Interface( fn=text_to_speech, inputs=[ gr.Textbox(lines=5, label="Enter Text"), gr.Dropdown(choices=available_speakers, label="Choose Speaker") ], outputs=gr.Audio(label="Output Audio"), title="Text to Speech", description="Select a speaker and enter text to generate speech." ) # Launch the interface iface.launch()