在python中导入音频文件以进行分析,例如信号分析

时间:2016-11-16 02:05:00

标签: python git ipython signal-processing jupyter

I am trying to import a .wav file to perform Signal analysis on it. I have used all the Ipython,wave libraries that i am meant to import but its still showing me error.Some of the libraries were gotten from a book downloaded from git hub repository(https://github.com/AllenDowney/ThinkDSP). Can anyone one show me what is wrong with the code?

(This is after importing all necessary libraries in the book and in python)

错误回溯(最近一次调用最后一次)  in() ----> 1 wave = thinkdsp.read_wave(' 365515__noedell__noedell-shady-scheme-01.wav')

C:\ Users \ Ademola \ Desktop \ 500 Level \ DSP \ DSP_Python \ ThinkDSP-master \ ThinkDSP-master \ code \ thinkdsp.py in read_wave(filename)      99返回:Wave     100""" - > 101 fp = open_wave(文件名,' r')     102     103个nchannels = fp.getnchannels()

C:\ Users \ Ademola \ Anaconda3 \ lib \ wave.py in open(f,mode)     497模式=' rb'     498如果模式在(' r',' rb')中: - > 499返回Wave_read(f)     500 elif模式(' w',' wb'):     501返回Wave_write(f)      init 中的C:\ Users \ Ademola \ Anaconda3 \ lib \ wave.py(self,f)         161#else,假设它已经是一个打开的文件对象         162尝试:      - > 163 self.initfp(f)         164除外:         165如果是self._i_opened_the_file:

C:\Users\Ademola\Anaconda3\lib\wave.py in initfp(self, file)
    141             chunkname = chunk.getname()
    142             if chunkname == b'fmt ':
--> 143                 self._read_fmt_chunk(chunk)
    144                 self._fmt_chunk_read = 1
    145             elif chunkname == b'data':
C:\Users\Ademola\Anaconda3\lib\wave.py in _read_fmt_chunk(self, chunk)
    258             self._sampwidth = (sampwidth + 7) // 8
    259         else:
--> 260             raise Error('unknown format: %r' % (wFormatTag,))
    261         self._framesize = self._nchannels * self._sampwidth
    262         self._comptype = 'NONE'

Error: unknown format: 3

1 个答案:

答案 0 :(得分:0)

如果没有看到你的代码很难回答你的问题......你可以使用python中标准的wav模块读取wav文件。基本语法如下:

import wave

wav = wave.open('wavFile.wav', 'r')

这是文档:

https://docs.python.org/2/library/wave.html

如果这有帮助,请告诉我!