采样率误差与SOX

时间:2015-04-22 00:21:41

标签: linux audio sh audio-recording sox

我使用以下转换代码使用SOX将所有原始文件转换为16 KHZ,16位,单声道格式的wav文件。我使用了以下代码

我使用了以下代码

#!/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

虽然我已经提到了采样率-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

随意提出建议。

使用followinf命令解决:

#!/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

1 个答案:

答案 0 :(得分:2)

sox的命令行要求文件选项位于它们应用的文件名前面。你没有在$ input之前放置任何参数,所以sox不知道输入文件的格式是什么。

假设输入文件是16k,16位签名和1个通道,那么重新排列输入文件之前的文件参数将使您超过错误。您还需要通过附加.wav扩展名来指示输出格式为wav:

sox -S  -r 16000 -c 1 -b 16 -w -s -t raw $input "$OutDir/$(basename $input).wav"

默认情况下,输入格式将以输出格式复制,除非您通过在输出文件名之前添加参数来显式覆盖它。