Reading .sph files in Python

I am working on a project where I need to extract Mel-Cepstral Frequency Coefficients (MFCC) from audio signals. The first step for this process is to read the audio file in python.

The audio files I have are stored in .sph format. I cannot find a way to read these files directly in python. I would like to have a sample rate and a numpy array with data, similar to how wav reading works.

Since the audio files I will be dealing with are large, I would rather not convert to .wav format for reading. Could you please suggest a possible method for this?

+3


source to share


1 answer


I was against converting to a .wav file as I assumed it would take a long time. This is beside the point. So the conversion using SoX suited my needs.

The following script, when run in a Windows folder, will convert all files in that folder to a .wav file.

cd %~dp0
for %%a in (*.sph) do sox "%%~a" "%%~na.wav"
pause

      



After that, you can use the following command to read the file.

import scipy.io.wavfile as wav
(rate,sig) = wav.read("file.wav")

      

PS: I posted an answer rather than deleting my question as I received very little help on the internet regarding .sph files.

+4


source







All Articles