Autoplay option for audio files
See original GitHub issueRequest
When a user uploads an audio file via st.audio(), they then have to hit the play button to hear the audio. While this works in most cases, for interesting applications, like writing an app that takes text-to-speech, it would be reasonable to have the audio file play once automatically.
Solution
MVP: What’s the smallest possible solution that would get 80% of the problem out of the way?
To have a parameter like auto_play
that can be passed to the function such as st.audio(file.mp4,auto_play=True)
(default is auto_play=False), that triggers the audio file to play one time after the file is finished loading.
Additional context
The conversation that sparked this Feature Request from the streamlit community
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:28
- Comments:16 (1 by maintainers)
Top GitHub Comments
I found a workaround. You can use html code to do exactly this:
This will display the same widget as
st.audio
but will autoplay the sound once it is created. You can also afterwards remove it again by using the.empty()
, but you need totime.sleep(2)
to make sure it has enough time to finish autoplaying.This works both locally as on streamlit cloud!
I found a solution to not show the player:
<audio autoplay>
instead of<audio controls autoplay>