I've had a problem reading a .wav file using Python. I want to read the amplitude and sampling rate of the file.
I tried reading the file using the following code:
import os
folder = os.getcwd() + '\\WAV'
file_name = 'Guitar.ff.sul_E.C5Bb5'
path = folder + '\\' + file_name + '.wav'
rate,data=read(path)
Before the above code, I imported the read
function from the scipy
library as follows:
from scipy.io.wavfile import read,write
And from numpy
I imported:
from numpy import linspace,sin,pi,int16
I received the error "TypeError: data type not understood".
The code worked perfectly for a different .wav file, and I'd like to know how (if it's possible) I can change the code to read this one, or if I must change the .wav file before I can read it.
Below are the properties of the files:
The first file didn't work and the second file did.
I got the exact same error for 1 and 2 channels.
Changing the file name so that it doesn't have dots doesn't matter. It seems to reach the file either way but not be able to read it.
Edit:
After changing the bit depth from 24 to 16 the problem is gone. Thank you Warren Weckesser for the comment.
Unfortunately, scipy's wavfile reader can't read 24 bit files: scipy issue 1930 on github
Check out https://pypi.python.org/pypi/wavio or get the source at https://github.com/WarrenWeckesser/wavio
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.