批量计算wav文件时长
#!/bin/bash

if [ $# != 1 ];then
    echo "specify the dir to do the calculation."
    exit
fi

output_tmp="$1.tmp"
output="$1.file_duration"

for file in $1/*.wav
do
    dur=`soxi -d ${file}`
    Dur=`soxi -D ${file}`
    echo "$file $dur $Dur" >> ${output_tmp}
done


sort -t ' ' -k3 ${output_tmp} -u > ${output}
rm ${output_tmp}


批量转MP3为wav

注: 其中sox需要额外安装处理MP3的handler

#!/bin/bash

if [ $# != 1 ];then
    echo "specify the dir to do the conversion."
    exit
fi


for file in $1/*.mp3
do
    echo "sox -b 16 -r 8000 -t mp3  $file -t wav $1/$(basename $file .mp3).wav"
    sox -b 16 -r 8000 -t mp3  $file -t wav $1/$(basename $file .mp3).wav
    # 如果需要剥离声道可以在末尾添加remix 1
    # sox -b 16 -r 8000 -t mp3  $file -t wav $1/$(basename $file .mp3).wav remix 1
done

剥离声道也可以使用ffmepg,

ffmpeg -i src.wav -af "pan=mono|FC=FL" -acodec pcm_u8 -ar 8000 output.wav