Audio recorder component for streamlit
Project description
Audio Recorder for streamlit
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.
The component's return value is a pydub AudioSegment.
To play the audio in the frontend, use st.audio(audio.export().read())
.
All pydub AudioSegment methods are available, so you can save the audio to a file with audio.export("audio.wav", format="wav")
for example.
Install it with pip:
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
Use it:
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 is using 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for streamlit-audiorecorder-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d028f260ac0f0f114cd8ccefe87e8fbc31db781d52b4d01903f44141410c97e |
|
MD5 | 239af00f5c9d7b919e99c270079885f7 |
|
BLAKE2b-256 | c14418aa191eb3a60f88c05e9b1d8709590355e82fcd022ce428200aee470cdb |
Hashes for streamlit_audiorecorder-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a85b0a6305ff84c29d0ff0b697c4863cd5f74cc810c7e4628699f3de4922506 |
|
MD5 | d05135cfe81b60fe10e88b6bcbc085ce |
|
BLAKE2b-256 | a4b8612ea35612b89c9af998b47bc0de2f43cf0ce5a461946fef8aa5a5571f7a |