Background
I listen to a lot of tech podcasts, and a while back I started not being able to keep up with all of them on a weekly basis. The thought of dropping some of them to make room wasn’t really an option. So I started fast forwarding through some of the “dead air” in an attempt to speed up their playback. This got old pretty quickly. Being a pretty tech. savvy person, I thought there had to be a programmatic way to solve my dilema. I initially latched on to the idea that a program could remove/compress this “dead air” automatically so that its effect would be minimized. This would in theory condense a 1 hour podcast to something less than an hour. Although my final solution didn’t exactly go this route, there was enough of a kernel of an idea that ultimately led me to a workable solution.
Initial Concept
The biggest irony in my solution? it came while I was listening to a podcast, The Linux Outlaws. I think it was this episode. One of the listeners had either emailed or called in with the crux of the solution that I ultimately utilized to get exactly what I wanted. The key concept that this listener had mentioned was changing the tempo of an audio file. Now I’m no audiophile but I had heard the term tempo before, I just never really put much thought into exactly what it was. This listener claimed that you could increase/decrease the tempo of an audio file but still maintain its listenability. My previous experience with speeding up audio, was taking 45 and 78 RPM records and cranking up the speed dial on my turntable so that they sounded like Alvin and the Chimpmunks, an effect called resampling.
Subsequent googling turned up this Wikipedia article. In a nutshell, tempo is similar to the beats per minute (bpm) in music. So what we’re doing when we manipulate the tempo, is we’re increasing/decreasing the beats per minute, but we’re maintaining the pitch of those beats. The key component in maintaining the original quality of an audio file, is to maintain its pitch. Increasing the pitch is the effect you are hearing when you simply turn up the playback speed, as in the turntable example.
mp3faster
So how do you affect the tempo without messing with the pitch? Several tools can do this. Audacity is one of them. However I wanted to develop a script that would do this, because I ultimately wanted to have my podcatching software, bashpodder, automatically speed up all the MP3 files that it downloads. Some more googling turned up exactly what I was looking for, a page on the gPodder wiki” about time stretching . This wiki page had a script on it called mp3faster that did exactly what I wanted. The centerpiece to this script is a command-line tool called soundstretch, which is part of a suite of tools called SoundTouch. The mp3faster script was originally developed to run on Ubuntu, I’ve since modified it with the following enhancements:
- runs on Redhat Distros (RHEL, Fedora, & CentOS)
- improved method for converting the initial MP3 file to WAV
- improved the copying of the original MP3′s id3 tags over to the new MP3 file
- variablized the tempo so that it can be passed in as a command line arguement
- force the replacement of the original MP3 file with the newly modified version
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 | % more mp3faster.bash #!/bin/bash # mp3faster - script for making mp3 playback faster with soundstretch # # debian/ubuntu package requirements # apt-get install mpg321 soundstretch lame libid3-3.8.3-dev # # rhel/centos/fedora package requirements # yum install mpg321 soundtouch lame id3lib # # sample usage for converting all mp3 files in a directory structure: # find -name "*.mp3" -print0 | xargs -0 -i mp3faster {} # # decode mp3 to wav file #mpg321 --wav "$1.wav" "$1" # the above decoding technique doesn't always work, and can sometimes # create a wav file that plays back too fast. Seems to happen with mp3 files that # have a low bitrate (< 80kbps). Using the lame alternative below get's around this. # alternative #1 to decoding an mp3 to wav lame --decode "$1" "$1.wav" # alternative #2 to decoding an mp3 to wav # mpg321 -b 10000 -s -r 44100 $1 | sox -t raw -r 44100 -s -w -c2 - "$1.wav" # process file with soundstretch #soundstretch "$1.wav" "$1.fast.wav" -tempo=+65 soundstretch "$1.wav" "$1.fast.wav" -tempo=+$2 # encode mp3 file lame --preset fast medium "$1.fast.wav" "$1.2.mp3" # copy id3 tags from old file id3cp -1 "$1" "$1.2.mp3" # remove temp files rm "$1.wav" "$1.fast.wav" # rename original mp3 file to .bak extension # mv "$1" "$1.bak" # rename processed mp3 file to original name mv -f "$1.2.mp3" "$1" |
Prerequisites
To install the prerequisite software on my CentOS 5 system, I used the following command:
…. Continue reading → Speeding up the Playback of Audio Podcasts »»
