Welcome What's new in Chrome extensions Getting started API Reference Samples
Welcome What's new in Chrome extensions Getting started API Reference Samples

chrome.audio

This API is part of the deprecated Chrome Apps platform. Learn more about migrating your app.
  • Description

    The chrome.audio API is provided to allow users to get information about and control the audio devices attached to the system. This API is currently only available in kiosk mode for ChromeOS.

  • Permissions
    audio
  • Availability
    Dev channel

Summary

Types

AudioDeviceInfo

Properties

  • deviceName
    string

    Device name.

  • deviceType

    Type of the device.

  • displayName
    string

    The user-friendly name (e.g. "USB Microphone").

  • id
    string

    The unique identifier of the audio device.

  • isActive
    boolean

    True if this is the current active device.

  • level
    number

    The sound level of the device, volume for output, gain for input.

  • stableDeviceId
    string optional

    The stable/persisted device id string when available.

  • streamType

    Stream type associated with this device.

DeviceFilter

Properties

  • isActive
    boolean optional

    If set, only audio devices whose active state matches this value will satisfy the filter.

  • streamTypes
    StreamType[] optional

    If set, only audio devices whose stream type is included in this list will satisfy the filter.

DeviceIdLists

Properties

  • input
    string[] optional

    List of input devices specified by their ID.

    To indicate input devices should be unaffected, leave this property unset.

  • output
    string[] optional

    List of output devices specified by their ID.

    To indicate output devices should be unaffected, leave this property unset.

DeviceProperties

Properties

  • level
    number optional

    The audio device's desired sound level. Defaults to the device's current sound level.

    If used with audio input device, represents audio device gain.

    If used with audio output device, represents audio device volume.

DeviceType

Available audio device types.

Enum

"HEADPHONE", "MIC", "USB", "BLUETOOTH", "HDMI", "INTERNAL_SPEAKER", "INTERNAL_MIC", "FRONT_MIC", "REAR_MIC", "KEYBOARD_MIC", "HOTWORD", "LINEOUT", "POST_MIX_LOOPBACK", "POST_DSP_LOOPBACK", "ALSA_LOOPBACK", or "OTHER"

LevelChangedEvent

Properties

  • deviceId
    string

    ID of device whose sound level has changed.

  • level
    number

    The device's new sound level.

MuteChangedEvent

Properties

  • isMuted
    boolean

    Whether or not the stream is now muted.

  • streamType

    The type of the stream for which the mute value changed. The updated mute value applies to all devices with this stream type.

StreamType

Type of stream an audio device provides.

Enum

"INPUT", or "OUTPUT"

Methods

getDevices

getDevices(filter?: DeviceFilter, callback: function): void

Gets a list of audio devices filtered based on filter.

Parameters

  • filter
    DeviceFilter optional

    Device properties by which to filter the list of returned audio devices. If the filter is not set or set to {}, returned device list will contain all available audio devices.

  • callback
    function

    Reports the requested list of audio devices.

    The parameter should be a function that looks like this:

    (devices: AudioDeviceInfo[]) => {...}

getMute

getMute(streamType: StreamType, callback: function): void

Gets the system-wide mute state for the specified stream type.

Parameters

  • streamType

    Stream type for which mute state should be fetched.

  • callback
    function

    Callback reporting whether mute is set or not for specified stream type.

    The parameter should be a function that looks like this:

    (value: boolean) => {...}
    • value
      boolean

setActiveDevices

setActiveDevices(ids: DeviceIdLists | string[], callback: function): void

Sets lists of active input and/or output devices.

Parameters

  • ids
    DeviceIdLists | string[]

    Specifies IDs of devices that should be active. If either the input or output list is not set, devices in that category are unaffected.

    It is an error to pass in a non-existent device ID.

    NOTE: While the method signature allows device IDs to be passed as a list of strings, this method of setting active devices is deprecated and should not be relied upon to work. Please use DeviceIdLists instead.

  • callback
    function

    The parameter should be a function that looks like this:

    () => {...}

setMute

setMute(streamType: StreamType, isMuted: boolean, callback?: function): void

Sets mute state for a stream type. The mute state will apply to all audio devices with the specified audio stream type.

Parameters

  • streamType

    Stream type for which mute state should be set.

  • isMuted
    boolean

    New mute value.

  • callback
    function optional

    If you specify the parameter, it should be a function that looks like this:

    () => {...}

setProperties

setProperties(id: string, properties: DeviceProperties, callback: function): void

Sets the properties for the input or output device.

Parameters

  • id
    string
  • callback
    function

    The parameter should be a function that looks like this:

    () => {...}

Events

onDeviceListChanged

onDeviceListChanged.addListener(listener: function)

Fired when audio devices change, either new devices being added, or existing devices being removed.

Event

  • listener
    function

    The listener parameter should be a function that looks like this:

    (devices: AudioDeviceInfo[]) => {...}
    • List of all present audio devices after the change.

onLevelChanged

onLevelChanged.addListener(listener: function)

Fired when sound level changes for an active audio device.

Event

onMuteChanged

onMuteChanged.addListener(listener: function)

Fired when the mute state of the audio input or output changes. Note that mute state is system-wide and the new value applies to every audio device with specified stream type.

Event

We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.