Skip to main content

Streamlit component that allows to record mono audio from the user's microphone, and/or perform speech recognition directly.

Project description

streamlit-mic-recorder

Streamlit component that allows to record mono audio from the user's microphone, and/or perform speech recognition directly.

Installation instructions

$ pip install streamlit-mic-recorder

Usage instructions

Two functions are provided (with the same front-end):

audio=mic_recorder(
    start_prompt="Start recording",
    stop_prompt="Stop recording", 
    just_once=False,
    use_container_width=False,
    key=None
)

Renders a button. Click to start recording, click to stop. Returns None or a dictionary with the following structure:

{
    "bytes":audio_bytes, # wav audio bytes mono signal, can be processed directly by st.audio
    "sample_rate":sample_rate, # depends on your browser's audio configuration
    "sample_width":sample_width # 2
}

sample_rate and sample_width are provided in case you need them for further audio processing.

Arguments:

  • start/stop_prompt, the prompts appearing on the button depending on its recording state.
  • 'just_once' determines if the widget returns the audio only once just after it has been recorded (and then None), or on every rerun of the app. Useful to avoid reprocessing the same audio twice.
  • 'use_container_width' just like for st.button, determines if the button fills its container width or not.
text=speech_to_text(
    language='en',
    start_prompt="Start recording",
    stop_prompt="Stop recording", 
    just_once=False,
    use_container_width=False,
    key=None
)

Renders a button. Click to start recording, click to stop. Returns None or a text transcription of the recorded speech in the chosen language.

Example

import streamlit as st
from streamlit_mic_recorder import mic_recorder,speech_to_text

state=st.session_state

if 'text_received' not in state:
    state.text_received=[]

c1,c2=st.columns(2)
with c1:
    st.write("Convert speech to text:")
with c2:
    text=speech_to_text(language='en',use_container_width=True,just_once=True,key='STT')

if text:       
    state.text_received.append(text)

for text in state.text_received:
    st.text(text)

st.write("Record your voice, and play the recorded audio:")
audio=mic_recorder(start_prompt="⏺️",stop_prompt="⏹️",key='recorder')

if audio:       
    st.audio(audio['bytes'])

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_mic_recorder-0.0.2.tar.gz (470.6 kB view details)

Uploaded Source

Built Distribution

streamlit_mic_recorder-0.0.2-py3-none-any.whl (474.9 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_mic_recorder-0.0.2.tar.gz.

File metadata

  • Download URL: streamlit_mic_recorder-0.0.2.tar.gz
  • Upload date:
  • Size: 470.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for streamlit_mic_recorder-0.0.2.tar.gz
Algorithm Hash digest
SHA256 115ecd7e526315afc6c7231859e2aa038f388a296fa0d7bbf791d857003d8b54
MD5 6648369331d831214693a53e667e1a52
BLAKE2b-256 b3f3d293057024d4ac642d988bcdf0b6d26202395ebee10ed51e3135f0dcd041

See more details on using hashes here.

File details

Details for the file streamlit_mic_recorder-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_mic_recorder-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e09e63ffe503976e2fd24e16ef2ee3666bae83f18c5bd13f2345e41bfbb6cea
MD5 86602e001afc0a074ea5cdeef9345ae8
BLAKE2b-256 28c866185fa15c9980ed50cc45f4341a9bf169fcc757753dc549e6c62781bd76

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