what's the sample width of returned audio bytes?
gustavz opened this issue · comments
Gustav von Zitzewitz commented
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
Johan Leduc commented
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())