pyunity.audio module

Classes to manage the playback of audio. It uses the sdl2.sdlmixer library. A variable in the config module called audio will be set to False if the mixer module cannot be initialized.

pyunity.audio.mixer
class pyunity.audio.AudioClip(path)[source]

Bases: object

Class to store information about an audio file.

path

Path to the file

Type:str
music

Sound chunk that can be played with an SDL2 Mixer Channel. Only set when the AudioClip is played in an AudioSource.

Type:sdl2.sdlmixer.mixer.Mix_Chunk
class pyunity.audio.AudioSource(transform)[source]

Bases: pyunity.core.Component

Manages playback on an AudioSource.

clip

Clip to play. Best way to set the clip is to use the SetClip() function.

Type:AudioClip
playOnStart

Whether it plays on start or not.

Type:bool
loop

Whether it loops or not. This is not fully supported.

Type:bool
SetClip(clip)[source]

Sets a clip for the AudioSource to play.

Parameters:clip (AudioClip) – AudioClip to play
Play()[source]

Plays the AudioClip attached to the AudioSource.

Stop()[source]

Stops playing the AudioClip attached to the AudioSource.

Pause()[source]

Pauses the AudioClip attached to the AudioSource.

UnPause()[source]

Unpauses the AudioClip attached to the AudioSource.

Playing

Gets if the AudioSource is playing.

class pyunity.audio.AudioListener(transform)[source]

Bases: pyunity.core.Component

Class to receive audio events and to base spatial sound from. By default the Main Camera has an AudioListener, but you can also remove it and add a new one to another GameObject in a Scene. There can only be one AudioListener, otherwise sound is disabled.

Init()[source]

Initializes the AudioListener.

DeInit()[source]

Stops all AudioSources and frees memory that is used by the AudioClips.