St.audio not working

I am trying to use st,audio to play audio inside my streamlit app.

I am using the steps as described in the API reference:

audio_file = open(‘playlist.ogg’, ‘rb’)
audio_bytes = audio_file.read()
st.audio(audio_bytes, format=‘audio/ogg’)

However, when I do it from my app, a blank page is displayed when the st.audio command runs. I tried other formats (mp3) but get same behavior. There is no error message on the streamlit console.

If I try to play a video instead, it works fine

video_file = open(‘joker_inter_clip.mp4’, ‘rb’)
video_bytes = video_file.read()
st.video(video_bytes)

So not sure why the audio player is not working.

Any help will be appreciated.

Thanks!

2 Likes

I think it had to do with the length of the audio file. When I clipped it to a 3-minute file, it loads and plays fine.

1 Like

Ah, yes, that is very likely.

Today there’s a maximum size of ~50MB to data packets transferred on the websocket between the Streamlit server and the browser. I created a feature request for removing this maximum here: https://github.com/streamlit/streamlit/issues/414

Another idea we’ve been meaning to implement is to not transfer that data over the websocket at all, but instead serve them via HTTP. The feature request for that is here: https://github.com/streamlit/streamlit/issues/415

3 Likes