Nowadays I have a habit of recording my phone conversations through my k750i. The problem is that the files are saved in AMR format and my PC can’t play it.
Googling around reveals that AMR files can be converted to WAV and MP3, so I created a shell script to do this for me.
Prerequisites:
- AMR encoder/decoder – http://www.3gpp.org/ftp/Specs/2003-09/Rel-5/26_series/26104-520.zip
- sox
- lame (to encode mp3. If all you need is wave format, you don’t need lame and you can just change the script up to when it creates a wave)
Before you compile the AMR decoder/encoder, make the following changes:
- Remove all occurences of -DETSI in the Makefile
- Add #include “sp_dec.h” in decoder.c
That’s it. All you have to do is compile it normally. (Otherwise you will get segfault when running the binary)
Now the final part, the script I created (or you can download it here):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
| #!/bin/bash
#
# Script to convert .amr to .mp3
#
# by Ady Romantika (ady at romantika dot name) https://blog.adyromantika.com/
# December 2005
#
# Needs:
# 1. amr encoder/decoder http://www.3gpp.org/ftp/Specs/2003-09/Rel-5/26_series/26104-520.zip
# (to decode amr)
# 2. sox
# (to convert raw file to wave)
# 3. lame
# (to convert wave to mp3)
#
# Usage: amr2mp3.sh <inputfile>
#
# Warning: overwrites previous outfile
#
# Change this to where you place your decoder
CODECLOCATION=/opt/amrcodec
# Set to 1 to delete intermediate raw and wav files
DELINTERMEDIATEFILES=1
INFILE=$1
FILENAME=`echo $INFILE | sed -e "s/.amr//"`
SOX=`which sox`
LAME=`which lame`
# Check prerequisites
if [ x${SOX} == 'x' ];
then
echo I cannot find sox. Are you sure it is installed and in your PATH?
exit
fi
if [ x${LAME} == 'x' ];
then
echo I cannot find lame. Are you sure it is installed and in your PATH?
exit
fi
# Check for arguments
if [ x${INFILE} == 'x' ];
then
echo I need filename as argument
exit
fi
# Check for input file
if [ -e $INFILE ];
then
echo Found input file $INFILE
else
echo Input file $INFILE not found, exiting
exit;
fi
# Start conversion
echo "Converting AMR to WAV ($1 to ${FILENAME}.mp3)"
$CODECLOCATION/decoder $INFILE $FILENAME.raw
$SOX -r 8000 -w -c 1 -s $FILENAME.raw -r 16000 -w -c 1 $FILENAME.wav
$LAME $FILENAME.wav $FILENAME.mp3 --silent --tt $FILENAME --tl AMR --ty `date +%y`
# Delete intermediate files if needed
if [ $DELINTERMEDIATEFILES == 1 ];
then
echo Deleting raw and wave files. Keeping original amr.
rm $FILENAME.raw $FILENAME.wav
fi
if [ -e ${FILENAME}.mp3 ];
then
echo File succesfully created
else
echo File creation failed.
fi
echo Done!
</inputfile> |
#!/bin/bash
#
# Script to convert .amr to .mp3
#
# by Ady Romantika (ady at romantika dot name) https://blog.adyromantika.com/
# December 2005
#
# Needs:
# 1. amr encoder/decoder http://www.3gpp.org/ftp/Specs/2003-09/Rel-5/26_series/26104-520.zip
# (to decode amr)
# 2. sox
# (to convert raw file to wave)
# 3. lame
# (to convert wave to mp3)
#
# Usage: amr2mp3.sh <inputfile>
#
# Warning: overwrites previous outfile
#
# Change this to where you place your decoder
CODECLOCATION=/opt/amrcodec
# Set to 1 to delete intermediate raw and wav files
DELINTERMEDIATEFILES=1
INFILE=$1
FILENAME=`echo $INFILE | sed -e "s/.amr//"`
SOX=`which sox`
LAME=`which lame`
# Check prerequisites
if [ x${SOX} == 'x' ];
then
echo I cannot find sox. Are you sure it is installed and in your PATH?
exit
fi
if [ x${LAME} == 'x' ];
then
echo I cannot find lame. Are you sure it is installed and in your PATH?
exit
fi
# Check for arguments
if [ x${INFILE} == 'x' ];
then
echo I need filename as argument
exit
fi
# Check for input file
if [ -e $INFILE ];
then
echo Found input file $INFILE
else
echo Input file $INFILE not found, exiting
exit;
fi
# Start conversion
echo "Converting AMR to WAV ($1 to ${FILENAME}.mp3)"
$CODECLOCATION/decoder $INFILE $FILENAME.raw
$SOX -r 8000 -w -c 1 -s $FILENAME.raw -r 16000 -w -c 1 $FILENAME.wav
$LAME $FILENAME.wav $FILENAME.mp3 --silent --tt $FILENAME --tl AMR --ty `date +%y`
# Delete intermediate files if needed
if [ $DELINTERMEDIATEFILES == 1 ];
then
echo Deleting raw and wave files. Keeping original amr.
rm $FILENAME.raw $FILENAME.wav
fi
if [ -e ${FILENAME}.mp3 ];
then
echo File succesfully created
else
echo File creation failed.
fi
echo Done!
</inputfile>
Credits:
- http://www.aquarionics.com/article/name/How_to_convert_AMR_files_to_MP3
- http://xa.bi/mms/
A sample file: besok.mp3