Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (24 sloc) 775 Bytes

Using Python in music

Examples of audio and MIDI with Python 3.

The examples are being published in the wiki at LinuxCabal:úsica

Audio has a simple function that generates a sine wave at a given frequency, with a specified sampling rate, for a certain duration.

The data is stored in a simple file that can be reproduced with a standard audio player.

To run:


This produces the file sine.raw. Each data is 16-bit signed little endian, with a sampling rate of 44,100Hz and a single channel (mono).

To playback on the ALSA default PCM device:

aplay -f S16 -r 44100 -c 1 sine.raw
The meaning of the options:
  • -f = format
  • -r = sampling rate
  • -c = channels