Create Ringtones For Your iPhone Using Linux

In this howto, I’ll show how to create and install ringtones on your iPhone. There are a bunch of howtos around the internets on how to do this using Windows, and possibly on Linux with jailbroken phones. However, I haven’t seen one showing how to do it using just Linux, without having to jailbreak your phone. So here goes.

Pre-Requisites

To do this, you’ll need:

  • A working installation of libimobiledevice – howto here.
  • You’ll need to have the following applications installed:
    • audacity;
    • faac;
    • ffmpeg;
    • id3v2;
    • mplayer;
  • An mp3 file you want to make into a ringtone.

Create the Ringtone

A ringtone for the iPhone has to be 30 seconds or less, so the first thing you need to do to create a ringtone is to cut your .mp3 file down to 30 seconds or less if your file is over 30 seconds long. To do this, open audacity and then open the .mp3 file you want to use. Use your mouse to select 30 seconds (or less) of the track:

 

Then press ctrl+t to trim the rest of the track. Then use the Export… option from the File menu to create a new .mp3 file of your clip. One thing you need to write down now is the length of the clip in milliseconds. You can find this below the wave representation of the clip at the bottom of the window. The middle number should show you the length of the clip – make sure you have 3 decimal places (change the format to milliseconds to get 3 decimal places).

Once you have your 30 second (or less) .mp3 file, we need to create it to an .m4a file. You can skip this step altogether if your version of audacity has the ability to save to .m4a format, in which case, rather than saving your clip to .mp3 as above, save to .m4a. However, there seems to be some sort of incompatibility between audacity and the latest ffmpeg libraries, which means if you’ve got the latest ffmpeg, you may not be able to save as an .m4a file. However, never fear, the good old commandline will save you. This is a simple script that will convert your .mp3 file to an .m4a file. Just copy the following into a text editor like kate and save it as mp32aac.sh:

#!/bin/bash
# Azakus 2007
# Requires mplayer, faac, and id3v2
echo "Input name of mp3 file, excluding .mp3"
echo -n ">"
read IN
OUT="`ls | grep $IN.mp3`"
echo "Dumping mp3 to wav"
mplayer -vo null -vc null -ao pcm:fast:file=$IN.wav $OUT
echo "Converting id3v1 tags to id3v2 for easier transition to m4a tags" 
id3v2 -C $OUT
#"Coverting id3 tag from mp3 to m4a tag" --requires id3v2 tags.
TITLE="`id3v2 -l $OUT | grep TIT2 | awk '{ORS=" "} {for (i = 4; i <= NF; i++) print $i}'`"
ARTIST="`id3v2 -l $OUT | grep TPE1 | awk '{ORS=" "} {for (i = 4; i <= NF; i++) print $i}'`"
ALBUM="`id3v2 -l $OUT | grep TALB | awk '{ORS=" "} {for (i = 4; i <= NF; i++) print $i}'`"
TRACK="`id3v2 -l $OUT | grep TRCK | awk '{ORS=" "} {for (i = 6; i <= NF; i++) print $i}'`"
YEAR="`id3v2 -l $OUT | grep TYER | awk '{ORS=" "} {for (i = 3; i <= NF; i++) print $i}'`"
faac -b 128 -c 44100 -w --title "$TITLE" --artist "$ARTIST" --year "$YEAR" --album "$ALBUM" --track "$TRACK" $IN.wav
rm $IN.wav
echo "AAC transcode complete!"

…or download it from here. Once you’ve saved it, you’ll need to make it executable:

chmod +x mp32aac.sh

If you want to be able to use it simply by typing mp32aac, copy it to /usr/local/bin:

sudo cp mp32aac /usr/local/bin

Then to convert the .mp3 file you’ve just created, type mp32aac.sh and at the > prompt enter the name of your .mp3 clip without the “.mp3″ bit:

matt2@linux-f215 ==>mp32aac.sh
Input name of mp3 file, excluding .mp3                                                                                                 
>Arco_Ring                                                                                                                             
Dumping mp3 to wav                                                                                                                     
MPlayer dev-SVN-r30099-4.4-openSUSE Linux 11.2 (i686)-Packman (C) 2000-2009 MPlayer TeamCan't open joystick device /dev/input/js0: No such file or directory                                                                                                                  
Can't init input joystick                                                                                                              
mplayer: could not connect to socket                                                                                                   
mplayer: No such file or directory                                                                                                     
Failed to open LIRC support. You will not be able to use your remote control.                                                          
 
Playing Arco_Ring.mp3.                                                                                                                 
Audio only file format detected.                                                                                                       
==========================================================================                                                             
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3                                                                                  
AUDIO: 44100 Hz, 2 ch, s16le, 128.0 kbit/9.07% (ratio: 16000->176400)                                                                  
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)                                                                 
==========================================================================                                                             
[AO PCM] File: Arco_Ring.wav (WAVE)                                                                                                    
PCM: Samplerate: 44100Hz Channels: Stereo Format s16le                                                                                 
[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast                                                          
[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).                                                                   
AO: [pcm] 44100Hz 2ch s16le (2 bytes per sample)                                                                                       
Video: no video                                                                                                                        
Starting playback...                                                                                                                   
A:  29.9 (29.9) of 29.0 (29.0)  0.3%                                                                                                   
 
Exiting... (End of file)                                                                                                               
Converting id3v1 tags to id3v2 for easier transition to m4a tags                                                                       
Converting id3v1 tag to id3v2 in Arco_Ring.mp3... converted                                                                            
Freeware Advanced Audio Coder                                                                                                          
FAAC 1.28                                                                                                                              
 
Average bitrate: 128 kbps                                                                                                              
Quantization quality: 100                                                                                                              
Bandwidth: 22050 Hz                                                                                                                    
Object type: Low Complexity(MPEG-4) + M/S                                                                                              
Container format: MPEG-4 File Format (MP4)                                                                                             
Encoding Arco_Ring.wav to Arco_Ring.m4a                                                                                                
   frame          | bitrate | elapsed/estim | play/CPU | ETA                                                                           
 1290/1290  (100%)|  127.9  |    1.1/1.1    |   27.53x | 0.0                                                                           
 
AAC transcode complete!

You should now have your file with the .m4a extension. For this file to be used as a ringtone by your iPhone, you need to change the extension to .m4r, so:

mv your_file.m4a your_file.m4r

Putting The Ringtone On Your Phone

The first thing is you need to make sure your phone is connected to your computer via USB and mounted somewhere on your filesystem – see here for a howto. Then you need to navigate to the iTunes_Control/Ringtones folder within your iphone – I’d suggest using a filemanager to do this. Copy your .m4r file to that folder. Then navigate to the iTunes_Control/iTunes directory and open the file Ringtones.plist in a text editor. Mine looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ringtones</key>
	<dict>
	</dict>
</dict>
</plist>

It is straight XML, and to add your ringtone, you simply need to add a few lines of XML, as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Ringtones</key>
	<dict>
		<key>YYUX.m4r</key>
		<dict>
			<key>GUID</key><string>148F52CB21CF093B</string>
			<key>Name</key><string>Arco_Ring</string>
			<key>Total Time</key><integer>29873</integer>
		</dict>
	</dict>
</dict>
</plist>

The first attribute is the name of your file. It currently shows YYUX.m4r – just change this to the name of your .m4r file. Within the following tags, you need 3 bits of information. The GUID – this is a hexadecimal string. Just cut and paste the jumble of letters and numbers between the tags. If you have more than one ringtone, just use it again, but change one character – remember it must either be a numeral, or a letter from A-E. The Name – this is the name of the ringtone that appears in your iPhone. The Length – this is the length of the ringtone in milliseconds. This is the number that I told you to write down from audacity, just take out the decimal point. That’s it. Save the file and unmount your phone. You should now be able to find your new ringtone under Custom on your phone in Settings -> Sounds -> Ringtone. That’s it – no iTunes, no jailbreak – just pure Linux goodness