Coder Social home page Coder Social logo

audio-recorder-streamlit's Introduction

Audio record streamlit

This streamlit component allows to register an audio utterence from a user.

recorder.png

Installation

pip install audio-recorder-streamlit

Usage

import streamlit as st
from audio_recorder_streamlit import audio_recorder

audio_bytes = audio_recorder()
if audio_bytes:
    st.audio(audio_bytes, format="audio/wav")

Recording parameters

You can adjust the recording parameters energy_threshold and pause_threshold:

  • energy_threshold: The energy recording sensibility above which we consider that the user is speaking. If it is a float, then this is the energy threshold used to automatically detect recording start and recording end. You can provide a tuple for specifying different threshold for recording start detection and recording end detection.
  • pause_threshold: The number of seconds to spend below energy_level to automatically stop the recording.
  • sample_rate: Sample rate of the recorded audio. If not provided, this will use the default sample rate (https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/AudioContext).
# The recording will stop automatically
# 2 sec after the utterance end
audio_bytes = audio_recorder(pause_threshold=2.0, sample_rate=41_000)

Styling parameters

You can adjust the button style parameters:

audio_bytes = audio_recorder(
    text="",
    recording_color="#e8b62c",
    neutral_color="#6aa36f",
    icon_name="user",
    icon_size="6x",
)

custom.png

Frequently Asked Question

How can I record for a fixed duration ?

You can record for a fixed duration by setting the energy_threshold=(-1.0, 1.0) so that the recorder considers that you are speaking at the beginning and then you are never speaking from this point on.

Then simply set pause_threshold to your desired recording length.

# Records 3 seconds in any case
audio_bytes = audio_recorder(
  energy_threshold=(-1.0, 1.0),
  pause_threshold=3.0,
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.