Attention

You are viewing PyUnity docs under the develop branch. As such, they are only applicable if you installed from source. Go to https://docs.pyunity.x10.bz/en/latest/ for the most recent release.

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.

class pyunity.audio.AudioClip[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[source]

Bases: Component

Manages playback on an AudioSource.

clip = None

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

Type

AudioClip

playOnStart = False

Whether it plays on start or not.

Type

bool

loop = False

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.

property Playing

Gets if the AudioSource is playing.

class pyunity.audio.AudioListener[source]

Bases: SingleComponent

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.