pyunity.audio module

Classes to manage the playback of audio. It uses the pygame.mixer library, and if it cannot be initialized, then dummy classes are made to prevent stop of program. A variable in the config module called audio will be set to False if this happens.

class pyunity.audio.AudioClip(file)[source]

Bases: object

Class to store information about an audio file.

file

Name of the file

Type

str

sound

Sound file that can be played with a pygame.mixer.Channel. Only set when the AudioClip is in an AudioSource n a running scene.

Type

pygame.mixer.Sound

SetSound(file)[source]

Changes the audio file.

Parameters

file (str) – Name of the audio file Must be a .ogg file, which can work on any platform.

Raises
  • PyUnityException – If the provided file is not an OGG audio file

  • TypeError – If the provided file is not of type str

class pyunity.audio.AudioSource[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

AddComponent(component)

Calls AddComponent on the component’s GameObject.

Parameters

component (Component) – Component to add. Must inherit from Component

GetComponent(component)

Calls GetComponent on the component’s GameObject.

Parameters

componentClass (Component) – Component to get. Must inherit from Component

Pause()[source]

Pauses the current clip.

Play()[source]

Plays the current clip.

SetClip(clip)[source]

Sets the clip to play.

Parameters

clip (AudioClip) – Clip to set

Raises

TypeError – If the provided clip is not of type AudioClip

Stop()[source]

Stop the current clip.

UnPause()[source]

Unpauses the current clip.