Skip to main content

A Streamlit component that records audio with real-time silence detection

Project description

Streamlit Realtime Audio Recorder

A Streamlit component that records audio in real-time and automatically stops recording after a configurable silence period.

Installation

pip install streamlit-realtime-audio-recorder

Usage

from streamlit_realtime_audio_recorder import audio_recorder
import streamlit as st
import base64
import io

result = audio_recorder(
    interval=50,
    threshold=-60,
    silenceTimeout=200
)

if result:
    if result.get('status') == 'stopped':
        audio_data = result.get('audioData')
        if audio_data:
            audio_bytes = base64.b64decode(audio_data)
            audio_file = io.BytesIO(audio_bytes)
            st.audio(audio_file, format="audio/webm")
        else:
            pass
    elif result.get('error'):
            st.error(f"Error: {result.get('error')}")

Parameters

  • interval (optional, default: 50): How often to check audio level in milliseconds
  • threshold (optional, default: -60): Audio level threshold for speech detection in dB
  • silenceTimeout (optional, default: 1500): Time in milliseconds to wait after silence before stopping recording
  • play (optional, default: False): Whether to play the audio during recording

Demo

Check out the demo video showing the component in action:

Streamlit Realtime Audio Recorder Demo

How It Works

This component uses the Web Audio API and the hark library to detect speech and silence. When you click the microphone button:

  1. The microphone starts recording
  2. When you stop speaking (silence is detected), the recording automatically stops after a configurable timeout
  3. The audio data is returned as base64-encoded data that you can play, save, or process

Use Cases

  • Voice commands in Streamlit apps
  • Speech-to-text integration
  • Audio data collection
  • Voice recording with automatic silence detection

License

MIT

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_realtime_audio_recorder-0.1.1.tar.gz (5.2 MB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file streamlit_realtime_audio_recorder-0.1.1.tar.gz.

File metadata

File hashes

Hashes for streamlit_realtime_audio_recorder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 64676fdb39aa82673385e3c9b326e0eef83502f6e4fca7590584b1af4192db5c
MD5 4c0b254dd05fc204b4d96b78421c4459
BLAKE2b-256 dcf4fdbadb5abcf45bee70a4ca715188d9c9043140f14abfbf532f1540c32d8f

See more details on using hashes here.

File details

Details for the file streamlit_realtime_audio_recorder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_realtime_audio_recorder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c14e9a6edf81040ef2397d76beed2160f698e5253546f534e861d22a1a417213
MD5 07c3fd0ce06701a85f9da844d91ee37d
BLAKE2b-256 c38ae6856264cf3b820d6a78b12fc638d74f18636fde1a3cf9f7deabaaf18ba9

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