photons.audio module

Play WAV tones.

class photons.audio.Theme(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Short theme clips to play as a WAV file.

MARIO = 'mario'

Mario completes a level.

TETRIS = 'tetris'

The Tetris theme.

CONTRA = 'contra'

The Jungle theme from Contra.

class photons.audio.Song(sample_rate=44100, tempo=100)[source]

Bases: object

Create a song.

Parameters:
  • sample_rate (float) – The sample rate, in Hz.

  • tempo (float) – The tempo (beats per minute). This parameter creates class-instance constants that can be useful when adding notes and rests.

add(duration, left=None, right=None, volume=0.5)[source]

Add a rest, note or chord to the song.

Parameters:
  • duration (float) – The number of seconds the note will play for, or, the number of seconds to rest.

  • left (str | list[str]) – The name(s) of the note(s) to add to the left channel (e.g., ‘A4’ or [‘C4’, ‘G3’, ‘E3’] for a chord). Do not specify a value to add a rest.

  • right (str | list[str]) – The name(s) of the note(s) to add to the right channel (e.g., ‘C3’). If not specified then equals the left channel.

  • volume (float) – The amplitude of the sine wave. Should be between 0 and 1.

Return type:

None

play()[source]

Play the song.

Return type:

None

photons.audio.play(wav, wait=True)[source]

Play a WAV file or theme.

Parameters:
  • wav (str | Theme) – A file or theme to play.

  • wait (bool) – Whether to wait for the WAV file to finish playing before returning. Only used if wav is a file. Specifying a Theme will always wait, since the audio data is stored in memory.

Return type:

None

photons.audio.random()[source]

Play a random Theme.

Return type:

None