Skip to content

Ai Ai Audio Recording

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

AI Audio Recording

Start an AI audio recording service session, coordinate recording on a connected device, receive live transcription and session events, and collect the final recording report.

See AI Session Events for the AIAudioRecordingEventType lifecycle shared by this callback model.

AI audio recording session lifecycle

Start the AI service before device-side audio, keep both lifecycles coordinated, and finish through the service report callback.

  1. Configure Session — Choose the recording scene, language, offline behavior, and diarization.
  2. Start AI Service — Create the provider-backed AI audio recording session first.
  3. Retain Session — Store the session returned by onStartSuccess for its complete lifetime.
  4. Start Device Audio — After service startup succeeds, ask the connected device to send recording audio.
  5. Consume Live Results — Render transcript updates and handle session events or runtime errors.
  6. Stop Device Audio — Stop the device-side recording when the user ends the session.
  7. Stop AI Service — Stop the current AIBudsAISDK audio recording session.
  8. Receive Final Report — Consume the AIAudioRecordingReportModel delivered to onFinish.
  9. Release Session — Clear the retained session and return the UI to its idle state.

Prerequisites

  • AIBudsAISDK is initialized and a registered AI service provider is selected.
  • Provider authentication is complete when required.
  • The device is connected and conforms to DeviceAudioRecordingAPI.
  • The selected provider supports AIAudioRecordingServiceAPI.

API Reference

Framework

AIBudsAI.xcframework

Import

Swift

import AIBuds
import AIBudsAI
import AIBudsAIFoundation

Objective-C

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

Declaration

Swift

/// Starts an AI audio recording session.
/// - Parameters:
///   - config: The session configuration.
///   - onStartSuccess: Called with the started session.
///   - onStartFailure: Called when the session cannot start.
///   - onTranscript: Called when speech is transcribed.
///   - onEvent: Called for session-level events.
///   - onError: Called when the running session encounters an error.
///   - onFinish: Called with the completed session report.
static func startAIAudioRecording(
    _ config: AIAudioRecordingSessionConfig = .default,
    onStartSuccess: ((
        AIAudioRecordingSessionConvertible
    ) -> Void)? = nil,
    onStartFailure: ((
        Error
    ) -> Void)? = nil,
    onTranscript: ((
        StreamSpeechASRModel
    ) -> Void)? = nil,
    onEvent: ((
        AIAudioRecordingEventModel
    ) -> Void)? = nil,
    onError: ((
        NSError
    ) -> Void)? = nil,
    onFinish: ((
        AIAudioRecordingReportModel
    ) -> Void)? = nil
)

/// Stops the current AI audio recording service session.
static func stopAIAudioRecording()

Objective-C

/// Starts an AI audio recording session.
/// - Parameters:
///   - config: The session configuration.
///   - onStartSuccess: Called with the started session.
///   - onStartFailure: Called when the session cannot start.
///   - onTranscript: Called when speech is transcribed.
///   - onEvent: Called for session-level events.
///   - onError: Called when the running session encounters an error.
///   - onFinish: Called with the completed session report.
+ (void)startAIAudioRecordingWithConfig:
    (AIBudsAIAudioRecordingSessionConfig *)config
    onStartSuccess:
    (void (^ _Nullable)(id<AIBudsAIAudioRecordingSessionConvertible>))onStartSuccess
        onStartFailure:(void (^ _Nullable)(NSError *))onStartFailure
    onTranscript:
    (void (^ _Nullable)(AIBudsStreamSpeechASRModel *))onTranscript
    onEvent:
    (void (^ _Nullable)(AIBudsAIAudioRecordingEventModel *))onEvent
        onError:(void (^ _Nullable)(NSError *))onError
    onFinish:
    (void (^ _Nullable)(AIBudsAIAudioRecordingReportModel *))onFinish;

/// Stops the current AI audio recording service session.
+ (void)stopAIAudioRecording;

See startAIAudioRecording and stopAIAudioRecording.

Configuration

AIAudioRecordingSessionConfig provides:

Property Description
recordingScene Recording scene, such as .onSite.
allowRecordingWhileOffline Whether the service may start while the network is unavailable. Defaults to false.
enableSpeakerDiarization Whether speaker diarization is enabled. Defaults to false.
languageForSpeechInput Optional speech language identifier. When omitted, the SDK uses the app localization language.

Usage Examples

The AI service session should start before the device begins sending AI recording audio. Stop both sides when the user ends the recording or an error occurs.

Swift

let config = AIAudioRecordingSessionConfig(
    recordingScene: .onSite,
    allowRecordingWhileOffline: true,
    enableSpeakerDiarization: true,
    languageForSpeechInput: "en-US"
)

AIBudsAISDK.startAIAudioRecording(
    config,
    onStartSuccess: { session in
        currentSession = session

        guard let recordingDevice = device as? DeviceAudioRecordingAPI else {
            AIBudsAISDK.stopAIAudioRecording()
            return
        }

        recordingDevice.startAIAudioRecording(.onSite) { success, error in
            if !success {
                print(error?.localizedDescription ?? "Device recording failed")
                AIBudsAISDK.stopAIAudioRecording()
            }
        }
    },
    onStartFailure: { error in
        print("Session start failed: \(error)")
    },
    onTranscript: { transcript in
        print(transcript.transcript ?? "")
    },
    onEvent: { event in
        print(event)
    },
    onError: { error in
        print(error.localizedDescription)
    },
    onFinish: { report in
        currentSession = nil
        print(report)
    }
)

Objective-C

AIBudsAIAudioRecordingSessionConfig *config =
    [[AIBudsAIAudioRecordingSessionConfig alloc]
        initWithRecordingScene:AIBudsRecordingSceneOnSite
        allowRecordingWhileOffline:YES
        enableSpeakerDiarization:YES
        languageForSpeechInput:@"en-US"];

[AIBudsAISDK startAIAudioRecordingWithConfig:config
    onStartSuccess:^(id<AIBudsAIAudioRecordingSessionConvertible> session) {
        self.currentSession = session;
        id<AIBudsDeviceAudioRecordingAPI> recordingDevice =
            (id<AIBudsDeviceAudioRecordingAPI>)self.device;

        if (![recordingDevice conformsToProtocol:
                @protocol(AIBudsDeviceAudioRecordingAPI)]) {
            [AIBudsAISDK stopAIAudioRecording];
            return;
        }

        [recordingDevice startAIAudioRecordingWithScene:AIBudsRecordingSceneOnSite
            completion:^(BOOL success, NSError *error) {
                if (!success) {
                    NSLog(@"%@", error.localizedDescription ?: @"Device recording failed");
                    [AIBudsAISDK stopAIAudioRecording];
                }
            }];
    }
    onStartFailure:^(NSError *error) {
        NSLog(@"Session start failed: %@", error);
    }
    onTranscript:^(AIBudsStreamSpeechASRModel *transcript) {
        NSLog(@"%@", transcript.transcript ?: @"");
    }
    onEvent:^(AIBudsAIAudioRecordingEventModel *event) {
        NSLog(@"%@", event);
    }
    onError:^(NSError *error) {
        NSLog(@"%@", error.localizedDescription);
    }
    onFinish:^(AIBudsAIAudioRecordingReportModel *report) {
        self.currentSession = nil;
        NSLog(@"%@", report);
    }];

To stop, call the connected device's stopAIAudioRecording(_:completion:), clear the retained session, and then call AIBudsAISDK.stopAIAudioRecording().

Notes

  • The final callback returns an AIAudioRecordingReportModel, not a local recording file path.
  • Retain the session returned by onStartSuccess for the duration of the operation.
  • onStartFailure covers startup failures; onError covers errors after the session has started.
  • The SDK does not expose an isRecording() method for this AI service. Track the retained session in your application state.

AIBuds SDK iOS Wiki

Clone this wiki locally