简体   繁体   English

从.wav文件中提取数据

[英]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 我有包含的ECG信号的.wav文件,Iwant使用提取该文件中的数据scipy.io.wavfile.read('sig100.wav')但我得到这个错误

"has {}-bit data.".format(bit_depth)) “具有{}位数据。”。format(bit_depth))

ValueError: Unsupported bit depth: the wav file has 11-bit data. ValueError:不支持的位深度:wav文件具有11位数据。

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 当我对此进行一些研究时,我发现该函数仅接受8位深度文件,但是我不知道如何修改它以接受我的文件,我在stackoverflow上找到了文件,但没有得到它

As per scipy.io.wavfile source code , it accepts (8, 16, 32, 64, 96, 128) bit data. 根据scipy.io.wavfile源代码 ,它接受(8、16、32、64、96、128)位数据。

While you can modify wavfile source code to accept the data, an easier alternative is to use external libraries like pydub . 虽然您可以修改wavfile源代码以接受数据,但更简单的选择是使用pydub这样的外部库。 See API and installation details here. 在此处查看API和安装详细信息

First, we take your file, convert bitrate to 16bit and export it. 首先,我们获取您的文件,将比特率转换为16bit并导出。
Then, simply import modified wav file using scipy to get data and frame-rate. 然后,只需使用scipy导入修改后的wav文件即可获取数据和帧频。

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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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