Joooohan / audio-recorder-streamlit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

what's the sample width of returned audio bytes?

gustavz opened this issue · comments

What's the sample width of returned audio bytes?
I want to convert the data into a speech_recognition.AudioData object which needs sample_rate and sample_width defined.
lib: https://github.com/Uberi/speech_recognition

Hi @gustavz, you can get the sample_width using a third party library like wave. I tried this and it seems to work:

    import io
    import wave
    import streamlit as st

    base_audio_bytes = audio_recorder(key="base")
    if base_audio_bytes:
        st.audio(base_audio_bytes, format="audio/wav")
        buffer = io.BytesIO(base_audio_bytes)
        with wave.open(buffer) as f:
            st.write(f.getsampwidth())