Skip to content

Ai Ai Summary

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

AI Summary

Generate a concise summary from text and update the UI as the selected provider returns incremental results.

Prerequisites

  • AIBudsAISDK is 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.

API Reference

Framework

AIBudsAI.xcframework

Import

Swift

import AIBudsAI

Objective-C

#import <AIBudsAI/AIBudsAI-Swift.h>

Declaration

Swift

/// 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.
static func summary(
    withText text: String,
    streamResultHandler: ((
        _ isFinal: Bool,
        _ transcript: String?,
        _ error: Error?
    ) -> Void)? = nil
)

/// Cancels the current summary operation before it completes.
static func cancelSummary()

Objective-C

/// 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 *)text
        streamResultHandler:(void (^ _Nullable)(BOOL isFinal, NSString * _Nullable transcript, NSError * _Nullable error))streamResultHandler;

/// Cancels the current summary operation before it completes.
+ (void)cancelSummary;

See summary and cancelSummary.

Usage Examples

Swift

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()
        }
    }
}

Objective-C

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

AIBudsAISDK.cancelSummary()

Objective-C

[AIBudsAISDK cancelSummary];

Notes

  • The API summarizes text only. It does not accept a file path or expose a maxLength parameter.
  • Each transcript can replace the previous displayed value because the provider returns an incrementally growing summary.
  • Treat a non-nil error as failure even if a transcript was received earlier.
  • cancelSummary() does not provide a completion callback; update application state when cancellation is requested.

AIBuds SDK iOS Wiki

Clone this wiki locally