简体   繁体   中英

extract data from .wav file

i have this .wav file containing an ECG signal , Iwant to extract the data in that file using scipy.io.wavfile.read('sig100.wav') but I got this error

"has {}-bit data.".format(bit_depth))

ValueError: Unsupported bit depth: the wav file has 11-bit data.

As I was doing some research on this I found out that that function only accepts 8-bit depth file , but I can't figure out how to modify it to accept my file I found this on stackoverflow but didn't get it

As per scipy.io.wavfile source code , it accepts (8, 16, 32, 64, 96, 128) bit data.

While you can modify wavfile source code to accept the data, an easier alternative is to use external libraries like pydub . See API and installation details here.

First, we take your file, convert bitrate to 16bit and export it.
Then, simply import modified wav file using scipy to get data and frame-rate.

from scipy.io import wavfile
from pydub import AudioSegment

audio = "sig100.wav"
audio1 = "sig100_16.wav"

#read wav file and export with 16bit bitrate
s = AudioSegment.from_file(audio, format = "wav" )
s.export(audio1 , bitrate="16", format="wav")

#read modified file
rate, data = wavfile.read(audio1)

Result:

>>> rate
360
>>> data
array([[ -928,  -416],
       [ -928,  -416],
       [ -928,  -416],
       ...,
       [-4320, -2336],
       [-4896, -2144],
       [-8192,     0]], dtype=int16)
>>> 

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM