How to record a sound and play the reverse of that in Mathematica?

Let's first try with a sound sample from MMA examples repository:

s = Import["ExampleData/rule30.wav"]

A FullForm of s reveals that this object has the structure Sound[SampledSoundList[{listOfSounds},samplesRate]]. From this it looks like to play the sound in reverse we just need to Reverse listOfSounds, which we can do for example like this:

s /. SampledSoundList[{soundsList_}, r_] :> SampledSoundList[{Reverse@soundsList}, r]

Let's wrap this up in a function:

playInReverse[Sound[SampledSoundList[{soundsList_}, r_]]] := Sound[
   SampledSoundList[{Reverse@soundsList}, r]
   ];
playInReverse[Sound[SampledSoundList[{soundsLists__}, r_]]] := Sound[
   SampledSoundList[
    Reverse /@ {soundsLists},
    r
    ]
   ];

where I used a very specific pattern assignment because this method works only for that specific structure of a Sound object, and the second assignment rule is for tracks over more than one channel.

Here you can see how it works:

enter image description here

The exact same procedure works with sounds recorded from inside Mathematica. See for example this answer for some methods to record sound. A simple way is to use SystemDialogInput["RecordSound"], which brings up a dialog to record the sound. The generated object is exactly of the form mentioned above, so that you can use

playInReverse[SystemDialogInput["RecordSound"]]

to record a sound and have it directly reversed.

Just for the heck of it, I tried this with a Beatles song (Yesterday) in mp3 format, and it works (no hidden messages though).


In version 11, *.wav files are now imported as Audio[] objects. Thus, using glS's example:

s = Import["ExampleData/rule30.wav"];
Audio[Reverse[AudioData[s]]];

click to hear


So that people who were hoping to hear actual backmasking would not be disappointed, let me give another example: the opening theme from the Disney animated series Gravity Falls. Using the last 5 seconds of the theme:

gf5 = Import["https://a.clyp.it/1mftdou4.mp3"];

As this is a stereo (two-channel) sound file, Reverse[] has to be mapped across the two channels:

Audio[Reverse /@ AudioData[gf5]];

click to listen

You should be hearing something like "three letters back" being whispered.

Tags:

Sound