Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »

The Sound of Pi

Play melodies based on the digits of π.

Run the code to create a musical note. Click Play to hear the sound it makes. Try other note numbers:

SHOW/HIDE DETAILS

SoundNote denotes a musical note. Pitch 0 is middle C:

SoundNote[0]

SoundNote by itself doesnt make a sound. Put it inside Sound to make a playable note (click the Play button to play the note):

Sound[SoundNote[0]]

Play the note immediately with EmitSound:

EmitSound[Sound[SoundNote[0]]]

HIDE DETAILS
Sound[SoundNote[0]]

Play a melody. Try other sequences of notes:

SHOW/HIDE DETAILS

Play a sequence of notes by putting them in a list (indicated by the curly braces):

Sound[{SoundNote[0], SoundNote[0], SoundNote[2]}]

If you dont specify otherwise, each note is played for 1 second. To make the melody play faster, specify the duration of the entire sequence in seconds:

Sound[{SoundNote[0], SoundNote[0], SoundNote[2]}, 1]

A more compact way of writing a sequence of notes uses /@ (Map):

SoundNote /@ {0, 0, 2}

Play a sequence of notes using Map:

Sound[SoundNote /@ {0, 0, 2}, 1]

This is how the note numbers correspond to piano keys:

HIDE DETAILS
Sound[SoundNote /@ {0, 0, 2, 0, 5, 4}, 2]

Get the first 12 digits of π. Try longer or shorter sequences:

SHOW/HIDE DETAILS

This gives a list of the first 12 digits of π (in base 10), plus the number of digits to the left of the decimal point:

RealDigits[Pi, 10, 12]

Use First to get just the digits:

First[RealDigits[Pi, 10, 12]]

HIDE DETAILS
First[RealDigits[Pi, 10, 12]]

Play the first 12 digits of π. Try longer or shorter sequences:

SHOW/HIDE DETAILS

This plays a sequence of 3 notes:

Sound[SoundNote /@ {0, 1, 2}, 2]

Replace the note sequence with the digits of Pi to play them as notes:

Sound[SoundNote /@ First[RealDigits[Pi, 10, 12]], 2]

HIDE DETAILS
Sound[SoundNote /@ First[RealDigits[Pi, 10, 12]], 2]

Play the digits of π on a marimba. Try other instruments, such as "Clarinet", "Trumpet" or "ElectricPiano":

SHOW/HIDE DETAILS

Use Style to specify what instrument to play the notes on:

Sound[Style[SoundNote /@ First[RealDigits[Pi, 10, 12]], "Marimba"], 2]

Heres a list of the available instruments:

HIDE DETAILS
Sound[Style[SoundNote /@ First[RealDigits[Pi, 10, 12]], "Marimba"], 2]