How to batch convert .sph files to .wav with sox
Asked Answered
F

4

6

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.

Fescue answered 4/9, 2013 at 18:16 Comment(1)
sox *.sph output.wav is supposed to convert all files into one so that doesn't work. So you need to try to get the above batch code to run correctly with the CMD window.Startling
C
7

For Linux consider this:

for f in *.SPH; do sox -t sph "$f" -b 16  -t wav "${f%.*}.wav"; done
Cableway answered 23/7, 2017 at 6:29 Comment(0)
G
3

In Windows 7, I need to provide the entire path for the destination files, and the mdkir command got a permission error even though I was running as Administrator, so pre-make your destination directory and delete the mkdir command, and then your SOX command should look similar to this (with your own flags based on the conversion or edit you are trying to accomplish):

FOR %%A IN (%*) DO sox  -t raw -e mu-law -c 1 -r 8000 %%A c:\converted\%%~nA.wav

The cmd file should not be in the folder where the files are, it should be in the folder where SOX is installed, and then drag the files you want converted onto the cmd (or bat) file.

Genetic answered 7/10, 2013 at 18:1 Comment(0)
O
0
for %%a in (*.sph) do sox "%%~a" "%%~na.wav"
Opuntia answered 4/9, 2013 at 19:35 Comment(4)
do you mean sox options? Pls. add this by yourself.Opuntia
No, I mean the code as it is doesn't work. It doesn't do anything.Fescue
set your sph folder, eg. cd /d c:\data\sphOpuntia
and? why don't you kindly post entire working answer with details?Fescue
G
0

Make a .bat file in your sox directory with the contents

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

Select and drag the files that you want to convert onto this .bat file and the .wav files with the same names as the .sph files will appear in the same folder as the .sph files.

Galvanic answered 20/2, 2014 at 3:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.