j'ai écrit un petit script d'emballage, basé sur l'entrée ci-dessus:
#!/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
Il faut une seconde supplémentaire pour démarrer la lecture du fichier, et repose sur alsamixer pour régler le volume, mais il fait un vraiment bon travail de vous empêcher d'avoir à constamment modifier le volume principal. Et peu importe le format d'entrée, car si mplayer peut le lire, il peut extraire l'audio, donc ça devrait marcher avec MP3, Ogg, AVI, peu importe.
Vous n'avez pas besoin du volume moyen mais de l'amplitude de crête pour normaliser un fichier son. –