Closed sumeetmahesh closed 3 weeks ago
I’m developing software for clients that showcase it at conferences and we use iPads to run Gradio apps. Right now audio streaming is broken for all iOS devices - it says “Error” and draws a yellow box around the component. This happens in Safari and Chrome.
The following code is the “stream_audio_out” demo notebook ran on an iPad:
The impact is huge - I am considering moving away from Gradio, as I had to engineer a workaround to segment the audio to multiple files and trigger the initial start of the stream with a hidden component (changing it’s default value once) and then load a new file with Audio.stop() event every time one file finishes.
Example of what is needed to be done in order to stream audio on iOS devices right now:
with gr.Blocks() as app:
audio_input = gr.Audio(label="Record or upload Audio", type="filepath", interactive=True, format='mp3')
hidden_textbox = gr.Textbox(value="someValue", visible=False)
start_button = gr.Button("Start", elem_id="start_btn", variant="primary")
audio_output = gr.Audio(label="Output Audio", type="filepath", autoplay=True)
text_output = gr.Textbox(label="Output text")
# Returning an empty string so it changes the value of the hidden textbox only once.
text_output.change(fn=text_changed, inputs=[text_output], outputs=[hidden_textbox])
start_button.click(fn=process_input, inputs=[audio_input], outputs=[text_output])
# This triggers the initial audio start
hidden_textbox.change(fn=start_audio, outputs=[audio_output])
# This loads the next audio segment when the previous is finished
audio_output.stop(fn=on_finished_playing_audio, inputs=[], outputs=[audio_output])
There are no errors in the js console nor python output that I can see.
I believe this should have been fixed with https://github.com/gradio-app/gradio/issues/6835, @sumeetmahesh if you'd like to confirm.
Forgot to comment about this in #8906 - i think iphone safari does not like autoplay (https://stackoverflow.com/questions/43570460/html5-video-autoplay-on-iphone) but if you manually click play, you will hear the audio as soon as it's ready. Looking into it.
thanks @freddyaboulton !
Now the yield function to pass chunks of audio to Gradio audio output in streaming mode is working fine for iPhone and Android phones. However, the playback now fails to play audio on desktop (chrome and Edge) with no error status.
> import numpy as np
> import gradio as gr
> import librosa
> import soundfile as sf
>
> SEGMENT_DURATION_SEC = 2
>
> def splitter(audio):
> print(audio)
> wave, sr = librosa.load(audio, sr=None)
> duration = librosa.get_duration(y=wave, sr=sr)
>
> if duration > SEGMENT_DURATION_SEC:
> segment_length = sr * SEGMENT_DURATION_SEC
> num_sections = int(np.ceil(len(wave) / segment_length))
> split = []
> print(f'Number of Sections:{num_sections}')
> for i in range(num_sections):
> t = wave[i * segment_length: ((i + 1) * segment_length)-1]
> split.append(t)
>
> for i in range(num_sections):
> audio_out = f"{audio[:-4]}{i}_out.wav"
> sf.write(audio_out, split[i], sr)
> yield audio_out
>
> gr.Interface(splitter,
> gr.Audio(sources=["microphone"], type="filepath"),
> gr.Audio(streaming=True, autoplay=True, type="filepath")
> ).launch(share=True, debug=True)
Hi @sumeetmahesh - sorry for the delay. I am not sure why it would work for iphone but not otherwise.
Going to close this as I don't think we have a clear path to repro. If we have the code, environment, and audio files needed to repro this issue, we can reopen
Describe the bug
When a yield function is used to pass chunks of audio to Gradio audio output in streaming mode, the Gradio audio playback works fine on desktop (windows) and Android phones. However, the playback fails on iphone with an error status.
If instead of yielding chunks of audio, the code waits to have the fully audio created before passing it to the Gradio audio output, the audio playback works fine on iphone. However, this approach is not desirable due to lower service quality i.e. longer wait time before audio is played for the user.
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio