How to batch convert .sph files to .wav with sox

Laura picture Laura · Sep 4, 2013 · Viewed 12.9k times · Source

I have a directory with many folders containing hundreds of .SPH files. I need to convert all .SPH files into .wav format. I have adopted the following code:

cd %~dp0
mkdir converted
FOR %%A IN (%*) DO sox -t raw -s -2 -r 22050 -c 2 %%A "converted/%%~nA.wav"
pause

However, it doesn't do anything on Windows 7. When I try the code on CMD inside a folder where some of .SPH are:

sox *.SPH output.wav

It embeds all *.SPH into output.wav file, which is not what I want. I need name1.SPH to name1.wav, name2.SPH to name2.wav

Please help.

Answer

Kazi Nazmul Haque Shezan picture Kazi Nazmul Haque Shezan · Jul 23, 2017

For Linux consider this:

for f in *.SPH; do sox -t sph "$f" -b 16  -t wav "${f%.*}.wav"; done