SoundGetVolume

Retrieves a volume setting of a sound device.

Setting := SoundGetVolume(Component, Device)

Parameters

Component

Type: String or Integer

If blank or omitted, it defaults to the master volume setting. Otherwise, specify the component's display name and/or index, e.g. 1, "Line in" or "Line in:2".

For further details, see Component (Sound Functions).

Device

Type: String or Integer

If blank or omitted, it defaults to the system's default device for playback (which is not necessarily device 1). Otherwise, specify the device's display name and/or index, e.g. 1, "Speakers", "Speakers:2" or "Speakers (Example HD Audio)".

For further details, see Device (Sound Functions).

Return Value

Type: Float

This function returns a floating point number between 0.0 and 100.0.

On Linux, this is the system mixer's slider percentage of the loudest channel. Readings above 100% are clamped to 100.

Error Handling

A TargetError is thrown if the device or component could not be found or if the component does not support this control type. Otherwise, an OSError is thrown on failure.

Remarks

To discover the capabilities of the sound devices installed on the system -- such as the names and available components -- run the soundcard analysis script.

macOS

Volume uses the selected input or output direction. If only channel controls are available, the first channel is read. This fallback is unverified on hardware.

Sound Functions

Examples

Retrieves and reports the master volume.

master_volume := SoundGetVolume()
MsgBox "Master volume is " master_volume " percent."

Retrieves and reports the microphone listening volume.

mic_volume := SoundGetVolume("Microphone")
MsgBox "Microphone listening volume is " mic_volume " percent."

Retrieves and reports the microphone recording volume.

mic_volume := SoundGetVolume( , "Microphone")
MsgBox "Microphone recording volume is " mic_volume " percent."