Reputation: 81
I am using the following conversion code using SOX for converting all raw files to wav files in 16 KHZ, 16 bits, mono format. I used the following code
I used the following code
#!/bin/bash
OutDir=converted
for input in "$@"
do sox -S $input -r 16000 -c 1 -b 16 -w -s -t raw "$OutDir/$(basename $input)"
done
The following errors are observed although i have mentioned sampling rate -r 16000
bsnayak@ubuntu:~/MLLR/input$ ls
an251-fash-b.raw an254-fash-b.raw cen1-fash-b.raw cen4-fash-b.raw cen7-fash-b.raw convert.sh
an253-fash-b.raw an255-fash-b.raw cen2-fash-b.raw cen5-fash-b.raw converted
bsnayak@ubuntu:~/MLLR/input$ ./convert.sh /home/bsnayak/MLLR/input/*.raw
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/an251-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/an253-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/an254-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/an255-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/cen1-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/cen2-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/cen4-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/cen5-fash-b.raw': sampling rate was not specified
sox FAIL formats: bad input format for file `/home/bsnayak/MLLR/input/cen7-fash-b.raw': sampling rate was not specified
Feel free for suggestions.
Solved using followinf command:
#!/bin/bash
SAVEIF=$IFS
IFS=$(echo -en "\n\b")
for file in $(ls *raw)
do
name=${file%%.raw}
sox -S -V -r 16k -e signed -c 1 -b 16 $name.raw $name.wav
done
IFS=$SAVEIFS
Upvotes: 1
Views: 3380
Reputation: 9341
The command line for sox requires that the file options precede the name of the file to which they apply. You've not put any arguments before $input so sox has no idea what the format of the input file is.
Assuming the input file is 16k, 16-bit signed and 1 channel then the rearranging the file arguments to precede the input file would get you past your error. You also need to indicate the output format is wav by appending a .wav extension:
sox -S -r 16000 -c 1 -b 16 -w -s -t raw $input "$OutDir/$(basename $input).wav"
By default the input format will be replicated in the output format unless you explicitly override it by adding arguments before the output filename.
Upvotes: 4