Skip to main content

Audio recorder component for streamlit

Project description

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.

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_rec

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 streamlit_rec import audiorecorder

st.title("Audio Recorder")
audio = audiorecorder()

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.

Just solved this problem.

1.Generate temporary SSL authentication

openssl genrsa 2048 > host.key
chmod 400 host.key
openssl req -new -x509 -nodes -sha256 -days 365 -key host.key -out host.cert

2.streamlit run with https

streamlit run xx.py --server.sslCertFile host.cert --server.sslKeyFile=host.key

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_rec-0.0.5.tar.gz (521.1 kB view details)

Uploaded Source

Built Distribution

streamlit_rec-0.0.5-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file streamlit_rec-0.0.5.tar.gz.

File metadata

  • Download URL: streamlit_rec-0.0.5.tar.gz
  • Upload date:
  • Size: 521.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for streamlit_rec-0.0.5.tar.gz
Algorithm Hash digest
SHA256 e5e448c9d56681eeef05b858c38d647b8f34b006535842f17ff957807839a8bb
MD5 8b7c747307ee1716f29e3bc57304eba6
BLAKE2b-256 06cca9e605151a147e96a813e6ff8e87e6086412c94f8567fb4020dfc932bcc9

See more details on using hashes here.

File details

Details for the file streamlit_rec-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_rec-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6145a91f898e0e85e46803811e9009f51e430353692fc7e85bb29036ae46b9a8
MD5 223819d92e5fc845551dd7b3fb903c5b
BLAKE2b-256 2562562197226b7bb3e10b9e3fabdae82c48051140e82e7f32532575207b61b8

See more details on using hashes here.

Supported by

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