-
Notifications
You must be signed in to change notification settings - Fork 0
Ai 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.
- Configure Session — Choose the recording scene, language, offline behavior, and diarization.
- Start AI Service — Create the provider-backed AI audio recording session first.
- Retain Session — Store the session returned by onStartSuccess for its complete lifetime.
- Start Device Audio — After service startup succeeds, ask the connected device to send recording audio.
- Consume Live Results — Render transcript updates and handle session events or runtime errors.
- Stop Device Audio — Stop the device-side recording when the user ends the session.
- Stop AI Service — Stop the current AIBudsAISDK audio recording session.
- Receive Final Report — Consume the AIAudioRecordingReportModel delivered to onFinish.
- Release Session — Clear the retained session and return the UI to its idle state.
-
AIBudsAISDKis 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.
AIBudsAI.xcframework
import AIBuds
import AIBudsAI
import AIBudsAIFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBudsAI/AIBudsAI-Swift.h>/// 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()/// 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 * _Nonnull)config
onStartSuccess:(void (^ _Nullable)(id <AIBudsAIAudioRecordingSessionConvertible> _Nonnull))onStartSuccess
onStartFailure:(void (^ _Nullable)(NSError * _Nonnull))onStartFailure
onTranscript:(void (^ _Nullable)(AIBudsStreamSpeechASRModel * _Nonnull))onTranscript
onEvent:(void (^ _Nullable)(AIBudsAIAudioRecordingEventModel * _Nonnull))onEvent
onError:(void (^ _Nullable)(NSError * _Nonnull))onError
onFinish:(void (^ _Nullable)(AIBudsAIAudioRecordingReportModel * _Nonnull))onFinish;
/// Stops the current AI audio recording service session.
+ (void)stopAIAudioRecording;See startAIAudioRecording and stopAIAudioRecording.
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. |
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.
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)
}
)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().
- The final callback returns an
AIAudioRecordingReportModel, not a local recording file path. - Retain the session returned by
onStartSuccessfor the duration of the operation. -
onStartFailurecovers startup failures;onErrorcovers 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 documentation · Full documentation · API Reference
- Introduction
- Getting Started
- Core Concepts
-
Core Features
- Basic Features
- Device Info
- Find Device
- Physical Operations
- Work Mode
- Work Status
- Wear Detection
- Volume Control
- Music Control
- TWS
- Equalizer
- ANC
- Audio
- Camera
- Remote Camera
- File Import
- Teleprompter
- Segment Navigation
- Live Streaming
- Device Applications
- OTA
- Camera OTA
- Service Auth
- AI Services
- Voice Assistant
- Logging
- Advanced Topics
- Releases
- Troubleshooting