I read a post1 on FriendFeed about listening to MP3 backwards, it uses Audacity to do the trick.

I came out with this command:

ffmpeg -i src.mp3 /tmp/src.wav && python -c "import wave ; s = wave.open('/tmp/src.wav', 'rb') ; r= wave.open('/tmp/rev.wav', 'wb') ; r.setparams(s.getparams()) ; count = s.getnframes()
while count > 0:
 count -= 1
 s.setpos(count)
 r.writeframes(s.readframes(1))" && ffmpeg -i /tmp/rev.wav rev.mp3

It uses ffmpeg to convert mp3 to wave, then convert reversed wave back to mp3. The reversing process uses Python’s wave module. Here is a better formatting of code:

import wave

s = wave.open('/tmp/src.wav', 'rb')
r= wave.open('/tmp/rev.wav', 'wb')
r.setparams(s.getparams())

count = s.getnframes()
while count > 0:
        count -= 1
        s.setpos(count)
        r.writeframes(s.readframes(1))

If readframes() returned a list of frames, line count would be reduced by four, and it could run much faster. It runs pretty slow, because it reverses frame by frame, I think Audacity could do this in a blink of second. But my point is to make the code one-liner (it actually is five lines).

Boom De YaDa is the audio file I used to test, the result is pretty interesting (or creepy?). You can listen it here (Hope Discovery wouldn’t mind).

1   Updated

Now this is a true one-liner:

ffmpeg -i src.mp3 /tmp/src.wav &&  python -c "import wave ; s = wave.open('/tmp/src.wav', 'rb') ; r= wave.open('/tmp/rev.wav', 'wb') ; r.setparams(s.getparams()) ; d = [s.readframes(1) for i in range(s.getnframes())] ; d.reverse() ; r.writeframes(''.join(d))"  && ffmpeg -i /tmp/rev.wav rev.mp3

Python part:

import wave

s = wave.open('/tmp/src.wav', 'rb')
r= wave.open('/tmp/rev.wav', 'wb')
r.setparams(s.getparams())

d = [s.readframes(1) for i in range(s.getnframes())]
d.reverse()

r.writeframes(''.join(d))

And it runs much faster!


[1]http://friendfeed.com/no-future/a29546e7/how-to-listen-mp3s-backwards-wikihow is gone.