Skip to main content

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.

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.
View official skill

API Reference

Framework

AIBudsAI.xcframework

Import

Swift
import AIBudsAI

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

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

Cancel an in-progress request when its result is no longer needed:

Swift
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.