Wednesday, February 20, 2008

AMR to mp3

Here is a code that you can use to convert AMR file to various other files:

Pre-requisites

Emerge sox, Vorbis-tools and lame. Build the the 3GPP reference converter files (compiled with these changes: make file without -DETSI and add #include "sp_dec.h" to decoder.c).

Convert AMR to OGG Vorbis

File: /usr/local/bin/amrtoogg

#!/bin/bash
 
# By Aquarion - Aquarion@Aquarionics.com
# Do what you want with it, it's not rocket science.
 
##Change these:
#Wherever you put encode and decode when you compiled them:
CODEC=/usr/local/bin
 
#Temporary directory. Chances are you've already got this set
TEMP=/tmp
 
#Where do the final MP3s go?
FINAL=/home/user/media/siemens/ogg
 
for file in *.amr; do 
        FILE=`echo $file | sed -e "s/.amr//"`; 
        echo -n "$FILE [AMR] -> [RAW]"
        $CODEC/decoder $file $TEMP/$FILE.raw > log.std 2> log.err; 
        echo -n " -> [WAV] "
        sox -r 8000 -w -c 1 -s $TEMP/$FILE.raw -r 44100 \
               -w -c 1 $TEMP/$FILE.wav > log.std 2> log.err; 
        echo -n " -> [OGG] "
        oggenc $TEMP/$FILE.wav -q 5 -o $FINAL/$FILE.ogg --quiet \
               -t "$FILE" -a "Sanda" -l "Anul nou" -d `date +%Y`
        echo  " :-) "
        rm $TEMP/$FILE.wav;
        rm $TEMP/$FILE.raw;
done

Convert AMR to MP3

File: /usr/local/bin/amrtomp3

#!/bin/bash
 
# By Aquarion - Aquarion@Aquarionics.com
# Do what you want with it, it's not rocket science.
 
##Change these:
#Wherever you put encode and decode when you compiled them:
CODEC=/usr/local/bin
 
#Temporary directory. Chances are you've already got this set
TEMP=/tmp
 
#Where do the final MP3s go?
FINAL=/home/user/media/siemens/mp3
 
for file in *.amr; do 
        FILE=`echo $file | sed -e "s/.amr//"`; 
        echo -n "$FILE [AMR] -> [RAW]"
        $CODEC/decoder $file $TEMP/$FILE.raw > log.std 2> log.err; 
        echo -n " -> [WAV] "
        sox -r 8000 -w -c 1 -s $TEMP/$FILE.raw -r 44100 \
               -w -c 1 $TEMP/$FILE.wav > log.std 2> log.err; 
        echo -n " -> [MP3] "
        lame $TEMP/$FILE.wav $FINAL/$FILE.mp3 --preset standard --silent \
               --tt $FILE --ta Sanda --tl Anul\ Nou --ty `date +%Y`
        echo  " :-) "
        rm $TEMP/$FILE.wav;
        rm $TEMP/$FILE.raw;
done

No comments: