Skip to content

AudioManager

Inherits: Resource

Manage system volume and audio devices

Description

The AudioManager is responsible for managing the system volume and audio devices if the host supports it.

Properties

Type Name Default
float current_volume

Methods

Returns Signature
bool supports_audio()
int set_volume(value: float, type: int = 0)
int toggle_mute()
int set_output_device(device: String)
String get_current_output_device()
float get_current_volume()
PackedStringArray get_output_devices()

Property Descriptions

current_volume

float current_volume

Current volume


Method Descriptions

supports_audio()

bool supports_audio()

Returns true if the system has audio controls we support

set_volume()

int set_volume(value: float, type: int = 0)

Sets the current audio device volume based on the given value. The volume value should be in the form of a percent where 1.0 equals 100%. The type can be either absolute (default) or relative volume values.

    const AudioManager := preload("res://core/global/audio_manager.tres")
    ...
    AudioManager.set_volume(1.0) # Set volume to 100%
    AudioManager.set_volume(-0.06, AudioManager.TYPE.RELATIVE) # Decrease volume by 6%

toggle_mute()

int toggle_mute()

Toggles mute on the current audio device

set_output_device()

int set_output_device(device: String)

Sets the current output device to the given device

get_current_output_device()

String get_current_output_device()

Returns the currently set output device

get_current_volume()

float get_current_volume()

Returns the current volume as a percentage. E.g. 0.52 is 52%

get_output_devices()

PackedStringArray get_output_devices()

Returns a list of audio output devices