Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python WAV "TypeError: data type not understood" error

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:

  1. File: Guitar.ff.sul_E.C5Bb5.wav
    • Size: 38.87 MB
    • Length: 1 minute 10 seconds
    • Sample Rate: 96 KHz
    • Sample Size: 24 bit
    • Bit Rate: 4,608 kbps
    • Channels: tried 1 and 2
  2. File: 440hzAtone.wav
    • Size: 173 KB
    • Length : 2 seconds
    • Sample Rate: 44.1 KHz
    • Sample Size: 16 bit
    • Bit Rate: 705 kbps
    • Channels: 1

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.

like image 584
Recursion Avatar asked Jun 15 '26 05:06

Recursion


1 Answers

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

like image 161
Warren Weckesser Avatar answered Jun 17 '26 18:06

Warren Weckesser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!