mp3 ファイルの平均音量を知る必要があるので、(異なるビットレートで) mp3 に変換するときに、音量もスケーリングして正規化できます...
したがって、平均音量を dB で表示するコマンド ライン ツール / ruby ライブラリが必要です。
mp3 ファイルの平均音量を知る必要があるので、(異なるビットレートで) mp3 に変換するときに、音量もスケーリングして正規化できます...
したがって、平均音量を dB で表示するコマンド ライン ツール / ruby ライブラリが必要です。
sox(オープンソースのコマンドラインオーディオツールhttp://sox.sourceforge.net/sox.html)を使用して、ファイルの正規化とトランスコードを同時に行うことができます。
編集
ビットレートのオプションがないようです。とにかく、LAMEが正規化を行う場合、soxはおそらくやり過ぎです。
LAMEを使用して mp3 にエンコードできます。正規化、スケーリング、およびビットレートのオプションがあります。LAME は、ほぼすべてのプラットフォームにコンパイルできます。
上記の入力に基づいて、小さなラッパー スクリプトを作成しました。
#!/bin/sh
# Get the current volume (will reset to this later).
current=`amixer -c 0 get Master 2>&1 |\
awk '/%/ {
p=substr($4,2,length($4)-2);
if( substr(p,length(p)) == "%" )
{
p = substr(p,1,length(p)-1)
}
print p
}'`
# Figure out how loud the track is. The normal amplitude for a track is 0.1.
# Ludicrously low values are 0.05, high is 0.37 (!!?)
rm -f /tmp/$$.out
/usr/bin/mplayer -vo null -ao pcm:file=/tmp/$$.out $1 >/dev/null 2>&1
if [ $? = 0 ] ; then
amplitude=`/usr/bin/sox /tmp/$$.out -n stat 2>&1 | awk '/RMS.+amplitude/ {print $NF}'`
fi
rm -f /tmp/$$.out
# Set an appropriate volume for the track.
to=`echo $current $amplitude | awk '{printf( "%.0f%%", $1 * 0.1/$2 );}'`
echo $current $amplitude | awk '{print "Amplitude:", $2, " Setting volume to:", 10/$2 "%, mixer volume:", $1 * 0.1/$2}'
amixer -c 0 set Master $to >/dev/null 2>&1
mplayer -quiet -cache 2500 $1
# Reset the volume for next time.
amixer -c 0 set Master "$current%" >/dev/null 2>&1
ファイルの再生を開始するにはさらに 1 秒かかり、ボリュームの調整は alsamixer に依存しますが、マスター ボリュームを常に微調整する必要がなくなるという非常に優れた機能を果たします。mplayer がそれを再生できれば、オーディオを抽出できるので、入力フォーマットが何であるかはあまり気にしません。そのため、MP3、Ogg、AVI などで問題なく動作するはずです。
http://mp3gain.sourceforge.net/は、よく考え抜かれたソリューションです。