Ren'Py supports playing music and sound effects in the background, using the following audio file formats
Ren'Py supports an arbitrary number of audio channels. Three are defined by default:
New channels can be registeres with renpy.register_channel().
The 'Music Volume', 'Sound Volume', and 'Voice Volume' settings of the in-game preferences menu are used to set individual volumes for these channels.
Sounds can also be set to play when buttons, menu choices, or imagemaps enter their hovered or activated states. See Button Style Properties. Two configuration variables, config.main_menu_music and config.game_menu_music allow for the given music files to be played as the main and game menu music, respectively.
In-game, the usual way to play music and sound in Ren'Py is using the three music/sound statements.
The play statement is used to play sound and music. If a file is currently playing, it is interrupted and replaced with the new file.
The name of a channel is expected following keyword play, (Usually, this is either "sound", "music", or "voice"). This is followed by audiofile(s), where audiofile(s) can be one file or list of files. When the list is given, the item of it is played in order.
The fadein and fadeout clauses are optional. Fadeout gives the fadeout time for currently playing music, in seconds, while fadein gives the time it takes to fade in the new music. If fadeout is not given, config.fade_music is used.
The loop and noloop clauses are also optional. The loop clause causes the music to loop, while noloop causes it to play only once. If both of them isn't given, the default of the channel is used.
play music "mozart.ogg"
play sound "woof.mp3"
play myChannel "punch.wav" # 'myChannel' needs to be defined with renpy.music.register_channel().
"We can also play a list of sounds, or music."
play music [ "a.ogg", "b.ogg" ] fadeout 1.0 fadein 1.0
The stop statement begin with keyword stop, followed by the the name of a channel to stop sound on. It may optionally have a fadeout clause.
stop sound
stop music fadeout 1.0
The queue statement is used to queue up audio files. They will be played when the channel finishes playing the currently playing file.
The queue statement begin with keyword queue, followed by the the name of a channel to play sound on. It optionally takes the loop and noloop clauses.
queue sound "woof.ogg"
queue music [ "a.ogg", "b.ogg" ]
The advantage of using these statements is that your program will be checked for missing sound and music files when lint is run. The functions below exist to allow access to allow music and sound to be controlled from python, and to expose advanced (rarely-used) features.
Returns True if the given filename has been played at least once on the current user's system.
Returns true if the given channel is playing.
Returns True if the channel is currently playing a sound, False if it is not, or if the sound system isn't working.
This stops the music currently playing on the numbered channel, dequeues any queued music, and begins playing the specified file or files.
This queues the given filenames on the specified channel.
This registers a new audio channel named name. Audio can then be played on the channel by supplying the channel name to the play or queue statements.
Sets the pan of this channel.
This sets a callback that is called when the queue is empty. This callback is called when the queue first becomes empty, and at least once per interaction while the queue is empty.
The callback is called with no parameters. It can queue sounds by calling renpy.music.queue with the appropriate arguments. Please note that the callback may be called while a sound is playing, as long as a queue slot is empty.
Sets the volume of this channel, as a fraction of the volume of the mixer controlling the channel.
This stops the music that is currently playing, and dequeues all queued music. If fadeout is None, the music is faded out for the time given in config.fade_music, otherwise it is faded for fadeout seconds.
This sets the last queued file to None.
Most renpy.music functions have aliases in renpy.sound. These functions are similar, except they default to the sound channel rather than the music channel, and default to not looping.