Skip to content

Voice Assistant Get Offline Mode

Mr.P edited this page Aug 29, 2026 · 2 revisions

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?)
}

Objective-C

/// The protocol for the on-device voice assistant API.
@protocol AIBudsOnDeviceVoiceAssistantAPI <AIBudsDeviceAPI>
/// The current mode of the on-device voice assistant.
@property(nonatomic, readonly) AIBudsOnDeviceVoiceAssistantMode onDeviceVoiceAssistantMode;

/// Sets the mode of the on-device voice assistant.
/// - Parameters:
///   - mode: The desired mode to set.
///   - completion: Called when the operation completes.
///     - success: `YES` when the operation succeeds.
///     - error: Error details on failure; otherwise `nil`.
- (void)setOnDeviceVoiceAssistantMode:(enum AIBudsOnDeviceVoiceAssistantMode)mode
                           completion:(AIBudsCompletionHandler _Nullable)completion;
@end

See onDeviceVoiceAssistantMode, setOnDeviceVoiceAssistantMode, and OnDeviceVoiceAssistantMode.

Compatible Modes

Capability Modes to present
.none No 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")
}

Objective-C

id<AIBudsOnDeviceVoiceAssistantAPI> voiceAssistant =
    (id<AIBudsOnDeviceVoiceAssistantAPI>)self.device;

if (![voiceAssistant conformsToProtocol:@protocol(AIBudsOnDeviceVoiceAssistantAPI)]) {
    NSLog(@"On-device voice assistant is not supported");
    return;
}

NSLog(@"Current mode: %ld", (long)voiceAssistant.onDeviceVoiceAssistantMode);

if (voiceAssistant.onDeviceVoiceAssistantCapability !=
    AIBudsOnDeviceVoiceAssistantCapabilityCommon) {
    NSLog(@"Advanced mode is not supported");
    return;
}

[voiceAssistant
    setOnDeviceVoiceAssistantMode:AIBudsOnDeviceVoiceAssistantModeAdvanced
                       completion:^(BOOL success, NSError *error) {
                           if (!success) {
                               NSLog(@"%@", error.localizedDescription ?: @"Unable to change mode");
                               return;
                           }
                           NSLog(@"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.

AIBuds SDK iOS Wiki

Clone this wiki locally