Want to upload audio file to process. I usually use soundfile.read(“filename.wav”) to get the array.
Essentially I want a function to get the numpy array with the audio data out of the uploader.
I tried this:
file = st.file_uploader("Upload Wav File", type=[".wav",".wave"], key = "file", on_change=upload) ... def upload(): wav_bytes = io.BytesIO(st.session_state["file"].read()) if wav_bytes is not None: with wave.open(wav_bytes, 'rb') as wav_file: # Get parameters params = wav_file.getparams() # Get array audio_data = np.frombuffer(wav_file.readframes(params.nframes), dtype=np.int16)
I get an array, but not the correct one. I guess that with readframes() i am reading all wave file bytes(chunksize, framerate, fromat, audiodata,…), not only the audio data meant to read.
So if anyone can help, thank you.