import gradio as gr from elevenlabs import generate, stream, set_api_key # Set up ElevenLabs API Key set_api_key("73bb17b223e2b0f90a403eaeaa3b4d35") def generate_streamed_audio(text): audio_stream = generate( text=text, stream=True ) # This is where we'd integrate the streaming into Gradio. # However, Gradio's native components don't support audio streaming directly. # As a workaround, we might need to save the streamed audio to a file and return that. # But this is not true real-time streaming. audio_filename = "temp_audio.mp3" with open(audio_filename, "wb") as f: for chunk in audio_stream: f.write(chunk) return audio_filename # Set up Gradio components and interface input_text = gr.Textbox(label="Input Text", lines=2) output_audio = gr.Audio(label="Generated Voice", type="file") iface = gr.Interface( fn=generate_streamed_audio, inputs=input_text, outputs=output_audio, theme="Monochrome", ) # Launch Gradio app iface.launch()