Show API reference for

Configure an audio column in st.dataframe or st.data_editor.

Audio columns display an icon. When a user double clicks the icon in a cell, Streamlit displays playback controls. To play an audio file, a cell must have one of the following values:

  • A URL to fetch the audio from. If you use static file serving, the URL can be relative to your app's URL. Otherwise, the URL must be fully qualified with a scheme, like "https://example.com/my_audio.mp3".

    Paths to local audio files aren't supported.

  • A data URL containing a Base64-encoded audio like "data:audio/mp3;base64,//uQ...".

Audio columns aren't editable at this time. This command must be used in the column_config parameter of st.dataframe or st.data_editor.

Function signature[source]

st.column_config.AudioColumn(label=None, *, width=None, help=None, pinned=None, alignment=None)

Parameters

label (str or None)

The label shown at the top of the column. If this is None (default), the column name is used.

width ("small", "medium", "large", int, or None)

The display width of the column. If this is None (default), the column will be sized to fit the cell contents. Otherwise, this can be one of the following:

  • "small": 75px wide
  • "medium": 200px wide
  • "large": 400px wide
  • An integer specifying the width in pixels

If the total width of all columns is less than the width of the dataframe, the remaining space will be distributed evenly among all columns.

help (str or None)

A tooltip that gets displayed when hovering over the column label. If this is None (default), no tooltip is displayed.

The tooltip can optionally contain GitHub-flavored Markdown, including the Markdown directives described in the body parameter of st.markdown.

pinned (bool or None)

Whether the column is pinned. A pinned column will stay visible on the left side no matter where the user scrolls. If this is None (default), Streamlit will decide: index columns are pinned, and data columns are not pinned.

alignment ("left", "center", "right", or None)

The horizontal alignment of cell content. If this is None (default), audio icons are center-aligned.

Examples

You can use publicly accessible URLs or Base64-encoded audio data. To show the playback controls, double click a cell in the audio column.

import base64
import pandas as pd
import streamlit as st

@st.cache_data
def load_audio_as_base64():
    with open("cat-purr.mp3", "rb") as audio_file:
        audio_bytes = audio_file.read()
    return base64.b64encode(audio_bytes).decode("utf-8")

data_df = pd.DataFrame(
    {
        "source": [
            "Small and fluffy house panther",
            "Wikimedia, Performed by Muriel Nguyen Xuan and Stéphane Magnenat",
        ],
        "audio": [
            f"data:audio/mp3;base64,{load_audio_as_base64()}",
            "https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg",
        ],
    }
)

st.dataframe(
    data_df,
    column_config={
        "audio": st.column_config.AudioColumn("Preview Audio"),
    },
)
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.