I have a large amount of mp3 files that are not the correct sample rate for the external hardware I want to use them in. Is there any way of changing them all in one go rather than file by file through audacity?
问问题
1268 次
1 回答
0
你应该提到你正在使用什么操作系统......这适用于linux
sudo apt install libav-tools # install needed tool
// 显示一个文件的内容
avprobe mysong.mp3
其输出的底部说
Duration: 00:00:01.65, start: 0.000000, bitrate: 192 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, mono, s16p, 192 kb/s
好的,它是一个正常的 CD 质量 44.1kHz,所以让采样率降低一半到 22050kHz
avconv -i mysong.mp3 -ar 22050 mysong_22k.mp3
验证我们现在拥有的
avprobe mysong_22k.mp3
Duration: 00:00:01.70, start: 0.050113, bitrate: 33 kb/s
Stream #0:0: Audio: mp3, 22050 Hz, mono, s16p, 32 kb/s
到目前为止一切顺利,现在让我们将其包装起来以查看一个目录中的所有文件
#!/bin/bash
for curr_song in $( ls *mp3 ); do
echo
echo "current specs on song -->${curr_song}<--"
echo
curr_song_base_name=${curr_song%.*}
echo curr_song_base_name $curr_song_base_name
curr_new_output=${curr_song_base_name}_22k.mp3
echo "avprobe $curr_song "
avprobe "$curr_song"
echo
avconv -i ${curr_song} -ar 22050 ${curr_new_output}
echo now confirm it worked
echo
avprobe ${curr_new_output}
done
这应该让你启动并运行......它对于没有空格的歌曲名称运行良好......代码在处理文件名中的空格时涉及更多......如果你有空格,那么我会修改代码.. . 它通过在文件名末尾添加 _22k 来剪切每个输出文件,因此
input songhere.mp3
output songhere_22k.mp3
它很容易给它一个不同的输出目录
于 2018-03-16T03:51:44.127 回答