Skip to main content

Streamlit App

streamlit-audiorecorder

An audio Recorder for streamlit

Description

Audio recorder component for streamlit.
It creates a button to start the recording and takes three arguments: the start button text, the stop button text, and the pause button text.
If the pause button text is not specified, the pause button is not displayed.

Example with buttons

If all prompts are given as empty strings, the component will use the react-audio-recorder visualizer:

Example with the visualiser

Parameters

The signature of the component is:

audiorecorder(
    start_prompt="Start recording",
    stop_prompt="Stop recording",
    pause_prompt="",
    custom_style={'color': 'black'},
    start_style={},
    pause_style={},
    stop_style={},
    show_visualizer=True,
    key=None):

The prompt parameters are self-explanatory.
The style parameters are dictionaries that allow you to customize the appearance of the buttons using CSS. The custom_style parameter is applied to all buttons, while the start_style, pause_style, and stop_style parameters are applied only to the corresponding button.
The optional key parameter is used internally by Streamlit to properly distinguish multiple audiorecorders on the page.
The show_visualizer parameter is a boolean that determines whether to show live audio visualization while recording. If set to False, the text "recording" is displayed. It is used only when all prompts are empty strings.

Return value

The component's return value is a pydub AudioSegment.
All AudioSegment methods are available. In particular, you can:

  • Play the audio in the frontend with st.audio(audio.export().read())
  • Save the audio to a file with audio.export("audio.wav", format="wav")

Installation:

pip install streamlit-audiorecorder

Note: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.

On Ubuntu/Debian: sudo apt update && sudo apt install ffmpeg
On Mac: brew install ffmpeg

Usage:

import streamlit as st
from audiorecorder import audiorecorder

st.title("Audio Recorder")
audio = audiorecorder("Click to record", "Click to stop recording")

if len(audio) > 0:
    # To play audio in frontend:
    st.audio(audio.export().read())  

    # To save audio to a file, use pydub export method:
    audio.export("audio.wav", format="wav")

    # To get audio properties, use pydub AudioSegment properties:
    st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")

Troubleshooting:

Error: No record button is shown and you get the following error message in the console:

Component Error
Cannot read properties of undefined (reading 'getUserMedia')

Reason: To record the audio, this component uses the MediaDevices interface.
For security reasons, the getUserMedia() method is available only in secure contexts (HTTPS), as explained in the MDM documentation :

As an API that may involve significant privacy concerns, getUserMedia()'s specification lays out a wide array of privacy and security requirements that browsers are obligated to meet.

getUserMedia() is a powerful feature that can only be used in secure contexts; in insecure contexts, navigator.mediaDevices is undefined, preventing access to getUserMedia(). A secure context is, in short, a page loaded using HTTPS or the file:/// URL scheme, or a page loaded from localhost.

Solution: Serve your website using HTTPS. If you are serving your website locally, make sure to access it using localhost, not an IP address.

Metadata

Release files for streamlit-audiorecorder 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-audiorecorder 0.0.6
File Size Uploaded
streamlit_audiorecorder-0.0.6.tar.gz 483.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-audiorecorder 0.0.6
File Interpreter ABI Platform
streamlit_audiorecorder-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 971.4 kB

Release files / streamlit_audiorecorder-0.0.6.tar.gz

Download URL streamlit_audiorecorder-0.0.6.tar.gz
Size 483.7 kB
Tags Source
SHA-256 checksum
How to use checksums
64b66c25b2b5e603cbea67b14074aaa7e93188913d7c83bbbc9f4d8ff237939d
BLAKE2b-256 checksum
How to use checksums
3e1c22c755df2606163e5c646e8bad87aa29eaa8e1c163787282607eeb9abda0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / streamlit_audiorecorder-0.0.6-py3-none-any.whl

Download URL streamlit_audiorecorder-0.0.6-py3-none-any.whl
Size 487.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6f4fa16136d96ed8457768b9fe7e7745a3e1ba3fc50b85ad87b39f785e1a067
BLAKE2b-256 checksum
How to use checksums
90d2c61e0f91617e43bc60627f633953ee35877380b90fcc0888de81786ddd17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page