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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for streamlit_mic_recorder-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9ca8e7db50f99f9c340ddbdd476036668b46b28dd290453f99f8afa1b562db12
MD5 668bbd7896f5286b6a4d0359346f4947
BLAKE2b-256 6ef2d86a73d61b117f4ba93fbc1b0823536ce935dd41e8c1e881132b1ba90739

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for streamlit_mic_recorder-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cdbf1feeb2a38698755136804cad950953194c3cb37eb0669a46366f33609876
MD5 e53e97ee37b4261aaae10b4739257f69
BLAKE2b-256 d179f8923447ce3494e1de70c0876b3b8d45ef8638e2d2c63e22d89b1137c6ed

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