Read .sph files in Python

I was against converting to a .wav file as I assumed it would take a lot of time. That is not the case. So, converting using SoX suited my needs.

The following script when run in a windows folder converts all the files in that folder to a .wav file.

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

After this, the following command can be used to read the file.

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

Based on The answer of ben, I was able to read a .sph file with librosa, as it can read everything that audioread and ffmpeg can read.

import librosa
import librosa.display # You need this in librosa to be able to plot

import matplotlib.pyplot as plt

clip_dir = os.path.join("..","babel","LDC2016S10.sph") 
audio,sr = librosa.load(clip_dir,sr=16000) # audio is a numpy array

fig, ax = plt.subplots(figsize=(15,8))
librosa.display.waveplot(audio, sr=sr, ax=ax) 
ax.set(title="LDC2016S10.sph waveform")

Waveform of the .sph file

Tags:

Python

Audio