#11360·streamlit

Multiple `st.audio` calls with same parameters and autoplay=True raises DuplicateWidget error, prompts you to add a key, but you can't add a key

Author: sfc-gh-zblackwoodCreated May 14, 2025Updated Sep 16, 2026
Labelstype:bugpapercutstatus:confirmedpriority:P3feature:st.audio

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

If autoplay=True, then multiple calls to st.audio with the same file generates

streamlit.errors.StreamlitDuplicateElementId: There are multiple audio elements with the same auto-generated ID. When this element is created, it is assigned an internal ID based on the element type and provided parameters. Multiple elements with the same type and parameters will cause this error.

To fix this error, please pass a unique key argument to the audio element.

But you can't pass a key. If you pass different values for sample_rate, it removes the issue, but raises a warning about sample_rate only applying to numpy arrays, and also stops autoplay from working.

Reproducible Code Example

python
autoplay = st.toggle("Autoplay", value=False)

for i in range(3):
    audio_path = "sample.wav"
    st.audio(audio_path, autoplay=autoplay)

Steps To Reproduce

Run the code -- turn Autoplay on

Expected Behavior

Either it should work, or there should be a key to fix this, or at the very least the error message should be corrected

Current Behavior

No response

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.45.1
  • Python version:
  • Operating System:
  • Browser:

Additional Information

No response