Skip to main content

A Streamlit component for sequential audio playback with an internal queue.

Project description

Streamlit Audio Queue Player

This is a custom Streamlit component that plays audio files sequentially. It maintains an internal queue on the frontend so that when you send audio (as a base64 string) from Streamlit, they are played one after another.

Features

  • Internal Queue: New audio items are added to a queue and played sequentially.
  • Persistent State: The component uses a fixed key so that its internal state is preserved across Streamlit reruns.
  • Easy Integration: Simply call audio_player(audio, format="audio/wav", key="...") from your Streamlit app.
  • Automatic Refresh Example: An included sample app automatically refreshes every 1 second.

Installation

pip install streamlit-audio-queue-player

Usage

In a Streamlit App A sample Streamlit app is provided under the example/ directory. For example:

streamlit run example/app.py

In your app, you can add audio to the playback queue as follows:

import streamlit as st
import base64
from streamlit_audio_queue_player import audio_player

st.title("Demo: Streamlit Audio Player Component")

# Example: When the button is pressed, a dummy audio file is added to the queue.
if st.button("Add Dummy Audio"):
    try:
        with open("dummy.wav", "rb") as f:
            audio_bytes = f.read()
        audio_b64 = base64.b64encode(audio_bytes).decode()
        # Call the component with a fixed key so that its internal queue is preserved.
        audio_player(audio_b64, format="audio/wav", key="audio_player")
    except Exception as e:
        st.error(f"Error loading dummy audio: {e}")
else:
    # Even if no new audio is provided, call the component to maintain its state.
    audio_player(None, format="audio/wav", key="audio_player")

For Forcing Stop / Clearing the Queue

You can force-stop the current audio and clear the playback queue by providing a new clear_key value. For example, include a "Clear Audio Queue" button that increments an internal counter:

if "clear_key" not in st.session_state:
    st.session_state["clear_key"] = 0

if st.button("Clear Audio Queue"):
    st.session_state["clear_key"] += 1

audio_player(
    None,
    format="audio/wav",
    clear_key=st.session_state["clear_key"],
    key="audio_player"
)

Automatic Refresh Sample

The sample app under example/app.py includes a 1-second refresh loop using st.rerun to simulate a dynamic UI while preserving the component's internal state.

dummy.wav

https://www3.jvckenwood.com/pro/soft_dl/pa-d_message/aisatu.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_audio_queue_player-0.1.2.tar.gz (388.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_audio_queue_player-0.1.2-py3-none-any.whl (391.0 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_audio_queue_player-0.1.2.tar.gz.

File metadata

File hashes

Hashes for streamlit_audio_queue_player-0.1.2.tar.gz
Algorithm Hash digest
SHA256 141e384f039494204637376f6112c6e2c5d7677a1586f9f7f92c84a709e060b3
MD5 24629992107602558412e1803bac23e6
BLAKE2b-256 487e4bc5e7a93e6247d8b32f79c1227ca5f7fe9af240826e6bb20df49b4fedb1

See more details on using hashes here.

File details

Details for the file streamlit_audio_queue_player-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_audio_queue_player-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8d897ccacec0150d6e146b073a9fd3455857e59642012b9fb4b60c96f7c19ced
MD5 be07b84987a3dc999754dcf26a3383bb
BLAKE2b-256 e01ea388f1f126481323610fd5a5a8ce428a8f0cd1a78c9f5c748b2d74a2ddef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page