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.2.tar.gz (2.6 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.2.tar.gz.

File metadata

File hashes

Hashes for streamlit_realtime_audio_recorder-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c8e43c1948f3b6fb6eae719652de15eba77579a4a8d82d0cb01f3463f717733e
MD5 7697e6e1f538318b6a15cf522f3bdda0
BLAKE2b-256 5dda0bb050b292cf443a8432aee2d7a7770acd3f890e39844a0d06f2977a4c66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_realtime_audio_recorder-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ade901db01ace24c7510a7fa94b70a2b62538fc439f88f3b38ab3e914a55b79b
MD5 f8e48d3fdaa93c8062eee601e4796dc0
BLAKE2b-256 3848e8621528923c408510d786f6fa94114db4576e9afbace07ac008845f4be4

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