Change the future

Using Python To Generate Art And Sound

Audrey M. Roy

Audience level:


The trick to navigating the overwhelming Python audio/imaging landscape is understanding how the fundamentals work, using common data processing/visualization libraries, in-depth code samples, and simple math operations.

I use the stdlib, NumPy, SciPy, Matplotlib, PIL, and PyCairo to create building blocks, which I then combine to demonstrate advanced sound and image generation techniques.


The current landscape of audio and imaging in Python is overwhelming. The trick to navigating it is understanding how sound and graphics work at a fundamental level, using first the built-in libraries and then the most common data processing/visualization libraries.

Through a series of in-depth code samples, I rapidly build up from simple math to advanced sound and image generation techniques. I use the Python standard library, NumPy, SciPy, Matplotlib, PIL, and PyCairo to create building blocks, which I then combine in interesting ways to design complex sounds and images.

From waves to music:

  1. I start with a demo that uses the built-in wave, array, and math modules to produce a sine wave tone and output it to a .wav file.
  2. How to turn this into a notes module, complete with an implementation of piano keys.
  3. Use NumPy and SciPy to drastically simplify the code.
  4. Math/implementation for chord generation.
  5. Math/implementation for melody sequence generation.

What sounds look like:

  1. Plots of notes, chords, and melody sequences using matplotlib.
  2. Other types of waves.

Creative sound generation techniques:

  1. Generating random blips using notes.
  2. Generating interesting waveform variations to create sound effects.
  3. Applying statistical distributions to sound.

Using the same tricks on graphics instead:

  1. Applying statistical distributions to color and positioning, using PIL and PyCairo.
  2. Illustration using Gaussians.

Putting it all together:

  1. Combining the techniques with video.
  2. Spotlight on selected higher-level Python tools/libraries for creating sound and images.