STEAM blog

Computing, maths and art in education

Sound synthesis in Python - getting started

In this project we will use pysound to create sounds and music in Python.

pysound lets you create primitive waveforms, and combine them to produce more complex sounds, instruments and compositions. It is like a very simplified version of CSound, but written entirely in Python. It is designed for exploration and experiment, rather than producing recording quality sound files, but it is still a lot of fun to play with.

This project can probably run on any computer which supports Python and numpy. Here are instructions for setting it up on either a PC or a Raspberry Pi.

There are three steps (assuming you already have Python 3 installed):

  • Install the numpy Python package.
  • Install pysound.
  • Install Audacity (optional but recommended).

Installing numpy

Computer sound typically uses around 40,000 samples per second, so even a fairly short sound can contain millions of samples. Using Python lists to store such a large number of samples is very inefficient. numpy provides data arrays which store large collections of numbers very efficiently - taking less memory, and quicker to access.

Installing numpy on a Windows PC

numpy is not a pure Python library, it includes C code which needs to be compiled. This isn’t an easy task on Windows.

It is best to obtain a pre-compiled binary version. A good place to look is the Unofficial Windows Binaries site. You can download binaries for the most recent Python versions. The binaries are stored as Wheel (.whl) files.

Download the file and install it with pip in the cmd window:

pip install

Installing numpy on a Pi

Installation is much easier on the Raspberry Pi. Just use:

sudo apt-get install python-numpy

Installing pysound

First decide on a working folder - the folder where you will keep the files you create as part of this project. Create the folder anywhere you like on your disk.

pysound is available from github. Copy the pysound folder and examples folder undr your working folder like this:

  |-- pysound
  |-- examples

Installing Audacity

Audacity is a well known sound editing application. You can use it to open the sound files you create in this project. It allows you to play the sound, and also to zoom in and view the waveform in detail.

Installing Audacity on a Windows PC

You can download Audacity for Windows from here. It uses a windows installer.

Installing Audacity on a Pi

To install, use this in a terminal window:

sudo apt-get install audacity

To run, type audacity into a terminal window. The GUI will open on the desktop.