Skip to content

Core Audio Ai Recording

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

AI Audio Recording

Start and stop an AI audio recording for a specific RecordingScene.

Prerequisites

  • The device is connected and ready.
  • The device conforms to DeviceAudioRecordingAPI.
  • Use the same scene when stopping the recording that you used when starting it.

API Reference

Framework

AIBuds.xcframework

Import

Swift

import AIBuds
import AIBudsFoundation

Objective-C

#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>

Protocol

Swift

/// The protocol for device API that supports audio recording.
protocol DeviceAudioRecordingAPI: DeviceAPI {
    /// Starts an AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func startAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )

    /// Stops the AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    func stopAIAudioRecording(
        _ scene: RecordingScene,
        completion: AIBudsCompletionHandler?
    )
}

Objective-C

/// The protocol for device API that supports audio recording.
@protocol AIBudsDeviceAudioRecordingAPI <AIBudsDeviceAPI>
    /// Starts an AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    - (void)startAIAudioRecordingWithScene:(enum AIBudsRecordingScene)scene
        completion:(AIBudsCompletionHandler _Nullable)completion;

    /// Stops the AI audio recording for the specified scene.
    /// - Parameters:
    ///   - scene: The recording scenario context.
    ///   - completion: A closure that is called when the operation completes.
    ///     - success: `true` if the operation was successful; otherwise `false`.
    ///     - error: An `NSError` object that describes the error that occurred, or `nil` if the operation was successful.
    - (void)stopAIAudioRecordingWithScene:(enum AIBudsRecordingScene)scene
        completion:(AIBudsCompletionHandler _Nullable)completion;
@end

Instance Methods

Method Purpose
startAIAudioRecording Start an AI recording for a scene.
stopAIAudioRecording Stop the AI recording for that scene.

Recording Scenes

Swift Objective-C Description
.onSite AIBudsRecordingSceneOnSite Ambient or on-site recording.
.call AIBudsRecordingSceneCall Recording during a phone call.

The completion handler reports success and an optional NSError. These methods do not return transcription text or a recording file path.

Usage Examples

Swift

import AIBuds

guard let device = device as? DeviceAudioRecordingAPI else {
    print("Device does not support audio recording")
    return
}

let scene: RecordingScene = .onSite
device.startAIAudioRecording(scene) { success, error in
    guard success else {
        print("AI recording failed to start: \(error?.localizedDescription ?? "Unknown error")")
        return
    }
    print("AI recording started")
}

// Stop using the same scene.
device.stopAIAudioRecording(scene) { success, error in
    if !success {
        print(error?.localizedDescription ?? "AI recording failed to stop")
    }
}

Objective-C

#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>

id<AIBudsDeviceAudioRecordingAPI> device =
    (id<AIBudsDeviceAudioRecordingAPI>)self.device;
if (![device conformsToProtocol:@protocol(AIBudsDeviceAudioRecordingAPI)]) {
    NSLog(@"Device does not support audio recording");
    return;
}

AIBudsRecordingScene scene = AIBudsRecordingSceneOnSite;
[device startAIAudioRecordingWithScene:scene completion:^(BOOL success, NSError * _Nullable error) {
    if (!success) {
        NSLog(@"AI recording failed to start: %@", error.localizedDescription);
        return;
    }
    NSLog(@"AI recording started");
}];

// Stop using the same scene.
[device stopAIAudioRecordingWithScene:scene completion:^(BOOL success, NSError * _Nullable error) {
    if (!success) {
        NSLog(@"AI recording failed to stop: %@", error.localizedDescription);
    }
}];

Error Handling

Track the active scene in your app so the matching scene can be passed to the stop request. If a callback fails, keep the UI state conservative until the device reports its next recording-state update.

AIBuds SDK iOS Wiki

Clone this wiki locally