AI Summary
Generate a concise summary from text and update the UI as the selected provider returns incremental results.
Prerequisites
AIBudsAISDKis initialized and a registered provider is selected.- The provider supports
AISummaryServiceAPI. - Provider authentication and network access are available when required.
- The input text is non-empty.
Implement with AI Assistance
Build with AI
Implement this workflow with AI
Use the official Implement AIBuds AI Summary skill to adapt this workflow to your app.
Read and follow https://docs-aibuds.github.io/skills/implement-aibuds-ai-summary. Use it to implement Implement AIBuds AI Summary in this iOS project and verify the result.API Reference
Framework
AIBudsAI.xcframework
Import
- Swift
- Objective-C
import AIBudsAI#import <AIBudsAI/AIBudsAI-Swift.h>Declaration
- Swift
- Objective-C
/// Generates a concise summary for the provided text.
/// - Parameters:
/// - text: The text to summarize.
/// - streamResultHandler: Called repeatedly with the current summary.
/// - isFinal: `true` when the summary is complete; otherwise `false`.
/// - transcript: The current incremental summary text.
/// - error: The operation error, or `nil` when no error occurred.
public static func summary(withText text: String,
streamResultHandler: ((_ isFinal: Bool, _ transcript: String?, _ error: Error?) -> Void)? = nil)
/// Cancels the current summary operation before it completes.
public static func cancelSummary()/// Generates a concise summary for the provided text.
/// - Parameters:
/// - text: The text to summarize.
/// - streamResultHandler: Called repeatedly with the current summary.
/// - isFinal: `YES` when the summary is complete; otherwise `NO`.
/// - transcript: The current incremental summary text.
/// - error: The operation error, or `nil` when no error occurred.
+ (void)summaryWithText:(NSString * _Nonnull)text
streamResultHandler:(void (^ _Nullable)(BOOL, NSString * _Nullable, NSError * _Nullable))streamResultHandler;
/// Cancels the current summary operation before it completes.
+ (void)cancelSummary;See summary and cancelSummary.
Usage Examples
- Swift
- Objective-C
let sourceText = """
The AIBuds SDK connects supported devices to an iOS application and exposes
device control, media, AI, voice assistant, and diagnostic capabilities.
"""
AIBudsAISDK.summary(withText: sourceText) { isFinal, transcript, error in
DispatchQueue.main.async {
if let error {
summaryLabel.text = "Summary failed: \(error.localizedDescription)"
return
}
if let transcript {
summaryLabel.text = transcript
}
if isFinal {
summaryActivityIndicator.stopAnimating()
}
}
}NSString *sourceText = @"The AIBuds SDK connects supported devices to an iOS application and "
"exposes device control, media, AI, voice assistant, and diagnostic "
"capabilities.";
[AIBudsAISDK summaryWithText:sourceText
streamResultHandler:^(BOOL isFinal, NSString *transcript, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error != nil) {
self.summaryLabel.text = [NSString
stringWithFormat:@"Summary failed: %@", error.localizedDescription];
return;
}
if (transcript != nil) {
self.summaryLabel.text = transcript;
}
if (isFinal) {
[self.summaryActivityIndicator stopAnimating];
}
});
}];Cancel an in-progress request when its result is no longer needed:
- Swift
- Objective-C
AIBudsAISDK.cancelSummary()[AIBudsAISDK cancelSummary];Notes
- The API summarizes text only. It does not accept a file path or expose a
maxLengthparameter. - Each transcript can replace the previous displayed value because the provider returns an incrementally growing summary.
- Treat a non-
nilerror as failure even if a transcript was received earlier. cancelSummary()does not provide a completion callback; update application state when cancellation is requested.