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=True,
    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 sampe_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=True,
    use_container_width=False,
    key=None
)

Renders a button. Click to start recording, click to stop. Returns None or 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.1.tar.gz (470.7 kB view hashes)

Uploaded Source

Built Distribution

streamlit_mic_recorder-0.0.1-py3-none-any.whl (475.0 kB view hashes)

Uploaded Python 3

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