Skip to main content

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.

Animated workflow

AI audio recording session lifecycle

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

Host app

Configure Session

Choose the recording scene, language, offline behavior, and diarization.

AI service

Start AI Service

Create the provider-backed AI audio recording session first.

Host app

Retain Session

Store the session returned by onStartSuccess for its complete lifetime.

Device

Start Device Audio

After service startup succeeds, ask the connected device to send recording audio.

AI service → app

Consume Live Results

Render transcript updates and handle session events or runtime errors.

transcript + events
Device

Stop Device Audio

Stop the device-side recording when the user ends the session.

AI service

Stop AI Service

Stop the current AIBudsAISDK audio recording session.

Final callback

Receive Final Report

Consume the AIAudioRecordingReportModel delivered to onFinish.

Host app

Release Session

Clear the retained session and return the UI to its idle state.

Startup failures and errors from an already-running session are reported by different callbacks.

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.

Implement with AI Assistance

Build with AI

Implement this workflow with AI

Use the official Implement AIBuds AI Audio Recording skill to adapt this workflow to your app.

Read and follow https://docs-aibuds.github.io/skills/implement-aibuds-ai-audio-recording. Use it to implement Implement AIBuds AI Audio Recording in this iOS project and verify the result.
View official skill

API Reference

Framework

AIBudsAI.xcframework

Import

Swift
import AIBuds
import AIBudsAI
import AIBudsAIFoundation

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.
public static func startAIAudioRecording(_ config: AIAudioRecordingSessionConfig = .default,
                                   onStartSuccess: ((_ session: AIAudioRecordingSessionConvertible) -> Void)? = nil,
                                   onStartFailure: ((_ error: Error) -> Void)? = nil,
                                     onTranscript: ((_ transcriptData: StreamSpeechASRModel) -> Void)? = nil,
                                          onEvent: ((_ event: AIAudioRecordingEventModel) -> Void)? = nil,
                                          onError: ((_ error: NSError) -> Void)? = nil,
                                         onFinish: ((_ report: AIAudioRecordingReportModel) -> Void)? = nil) -> Void

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

See startAIAudioRecording and stopAIAudioRecording.

Configuration

AIAudioRecordingSessionConfig provides:

PropertyDescription
recordingSceneRecording scene, such as .onSite.
allowRecordingWhileOfflineWhether the service may start while the network is unavailable. Defaults to false.
enableSpeakerDiarizationWhether speaker diarization is enabled. Defaults to false.
languageForSpeechInputOptional 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)
    }
)

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.