File size: 1,035 Bytes
f0afc12 db33eee f0afc12 db33eee f0afc12 db33eee 5f06acc db33eee 5a75523 f0afc12 f459688 db33eee 00bbc0d 562ed19 db33eee f0afc12 1e717a6 562ed19 5f06acc f0afc12 9a0de0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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() |