sound — Sound effects and music playback

The sound module contains functions for playing simple sound effects on iOS.


sound.play_effect(name[, volume, pitch])

Play the sound effect with the given name. You can access a list of built-in sound effect names using the asset picker ([+] button in the toolbar), but name can also be a file path if you want to use your own sound effects.

Playback is asynchronous, i.e. the function returns before the sound has finished playing. The return value is an opaque identifier that can be used with the stop_effect() function. The volume and pitch arguments are optional, by default, the effect is played with the global volume, as set by set_volume().


Stops playback of a sound effect. The effect_id is the return value of play_effect().


Sets the default volume for all sound effects (between 0.0 and 1.0, the default is 0.5).


Determines whether the silent (mute) switch is honored when playing sounds (True by default).

Player Class

class sound.Player(file_path)

The Player class provides an easy-to-use interface for playing audio files from disk. Using this class is recommended for music and other audio that doesn’t require very low latency. For sound effects in games, play_effect() is more suitable.

Player Methods

Start playing audio.


Stop playing audio and reset the playback position.


Stop playing audio, but keep the current playback position.

Player Attributes


The duration of the loaded audio track in seconds (read-only).


The current playback position in seconds.


The duration of the audio track (read-only).


The number of times the audio track should be repeated. Set to -1 to repeat forever.

MIDIPlayer Class

class sound.MIDIPlayer(file_path[, sound_bank_path])

A MIDIPlayer provides simple playback functions for MIDI (.mid) files, using either the built-in “Merlin Silver” sound bank or one that you provide. If you provide a custom sound bank, it must be in sf2 format.

MIDIPlayer Methods

Start playback.


Stop playback.

MIDIPlayer Attributes


The current playback position.


The duration of the loaded MIDI file.


The playback rate (1.0 for normal speed).