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.
Prerequisites
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.
Implement with AI Assistance
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.API Reference
Framework
AIBudsAI.xcframework
Import
- Swift
- Objective-C
import AIBuds
import AIBudsAI
import AIBudsAIFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBudsAI/AIBudsAI-Swift.h>Declaration
- Swift
- 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.
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.
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
- Objective-C
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().
Notes
- 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.