Skip to main content

Get and Set On-Device Mode

Read the active on-device voice-assistant mode and request a mode supported by the device capability.

Prerequisites

  • The device is connected and conforms to OnDeviceVoiceAssistantAPI.
  • onDeviceVoiceAssistantCapability is not .none.
  • The target mode is compatible with the reported capability and is not .unknown.

API Reference

Framework

AIBuds.xcframework

Declaration

Swift
/// The protocol for the on-device voice assistant API.
protocol OnDeviceVoiceAssistantAPI: DeviceAPI {
    /// The current mode of the on-device voice assistant.
    var onDeviceVoiceAssistantMode: OnDeviceVoiceAssistantMode { get }

    /// Sets the mode of the on-device voice assistant.
    /// - Parameters:
    ///   - mode: The desired mode to set.
    ///   - completion: Called when the operation completes.
    ///     - success: `true` when the operation succeeds.
    ///     - error: Error details on failure; otherwise `nil`.
    func setOnDeviceVoiceAssistantMode(_ mode: OnDeviceVoiceAssistantMode,
                                   completion: AIBudsCompletionHandler?)
}

See onDeviceVoiceAssistantMode, setOnDeviceVoiceAssistantMode, and OnDeviceVoiceAssistantMode.

Compatible Modes

CapabilityModes to present
.noneNo mode controls
.keywordWakeup.disabled, .basic
.common.disabled, .basic, .advanced

Usage Examples

Swift
guard let voiceAssistant = device as? OnDeviceVoiceAssistantAPI else {
    print("On-device voice assistant is not supported")
    return
}

print("Current mode: \(voiceAssistant.onDeviceVoiceAssistantMode)")

guard voiceAssistant.onDeviceVoiceAssistantCapability == .common else {
    print("Advanced mode is not supported")
    return
}

voiceAssistant.setOnDeviceVoiceAssistantMode(.advanced) { success, error in
    guard success else {
        print(error?.localizedDescription ?? "Unable to change mode")
        return
    }
    print("Mode changed to advanced")
}

Notes

  • .unknown represents unavailable state and must not be sent as a target mode.
  • A successful callback confirms the request. Refresh UI from the device property or mode-change delegate callback.
  • .advanced includes call-state voice control and should only be offered for .common capability.