Convert audio.wav file uploaded with st.file_uploader into numpy array

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.

Why are you deviating from that now?

There are multiple ways in which audio data can be encoded as an array.

What is the deviation?

After the documentation, I’d say that should really just be the audio data.

However, as @Goyo already mentioned, the audio data can be represented differently in a wav file. For example, have you considered the channel number and sample width?

 wav_file.getnchannels()
 wav_file.getsampwidth()