質問

MP3 ファイルを (異なるビットレートで) MP3 に変換するときに、音量を調整して正規化できるように、MP3 ファイルの平均音量を知る必要があります...

したがって、平均音量をdB単位で表示するコマンドラインツール/Rubyライブラリが必要です。

役に立ちましたか?

解決

sox (オープンソースのコマンドラインオーディオツール) を使用できます。 http://sox.sourceforge.net/sox.html) ファイルの正規化とトランスコードを同時に行います。

編集

ビットレートのオプションはないようです。とにかく、LAME が正規化を行う場合、sox はおそらくやりすぎです。

他のヒント

使用できます ラメ mp3にエンコードします。正規化、スケーリング、ビットレートのオプションがあります。LAME は、事実上あらゆるプラットフォームにコンパイルできます。

http://mp3gain.sourceforge.net/ これに対するよく考えられた解決策です。

上記の入力に基づいて、小さなラッパー スクリプトを作成しました。

#!/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 など何でも問題なく動作するはずです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top