Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a audio file in Python similar to Matlab audioread?

I'm using wavefile.read() in Python to import a audio file to Python. What I want is read a audio file where every sample is in double and normalized to -1.0 to +1.0 similar to Matlab audioread() function. How can I do it ?

like image 598
TharinduRanathunga Avatar asked Dec 11 '22 15:12

TharinduRanathunga


2 Answers

Use read function of the PySoundFile package. By default it will return exactly what you request: a numpy array containing the sound file samples in double-precision (Float64) format in the range -1.0 to +1.0.

like image 112
TheBlackCat Avatar answered Apr 28 '23 11:04

TheBlackCat


Use Scipy:

import scipy.io.wavfile as wav

fs,signal=wav.read(file_name)

signal /= 32767

You need to divided by max int if you want exactly the same thing as in Matlab. Warning: if the wav file is int32 encoded, you need to normalize by max int32

like image 20
Maulik Madhavi Avatar answered Apr 28 '23 09:04

Maulik Madhavi