# TextSummarizer

    class TextSummarizer: NSObject

Performs summarization on text.

This API expects a LiteRT-LM model asset bundle.
- `
  ### [init(modelPath:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/TextSummarizer.md.txt#/c:objc(cs)MPPTextSummarizer(im)initWithModelPath:error:)

  ` Creates a new instance of `MPPTextSummarizer` from an absolute path to a model asset bundle stored locally on the device and the default `MPPTextSummarizerOptions`.

  #### Declaration

  Swift

      convenience init(modelPath: String) throws

  #### Parameters

  |---|---|
  | `modelPath` | An absolute path to a model file stored locally on the device. |
  | `error` | An optional error parameter populated when there is an error in initializing the text summarizer. |

  #### Return Value

  A new instance of `MPPTextSummarizer` with the given model path. `nil` if there is an error in initializing the text summarizer.
- `
  ### [init(options:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/TextSummarizer.md.txt#/c:objc(cs)MPPTextSummarizer(im)initWithOptions:error:)

  ` Creates a new instance of `MPPTextSummarizer` from the given `MPPTextSummarizerOptions`.

  #### Declaration

  Swift

      init(options: TextSummarizerOptions) throws

  #### Parameters

  |---|---|
  | `options` | The options of type `MPPTextSummarizerOptions` to use for configuring the `MPPTextSummarizer`. |
  | `error` | An optional error parameter populated when there is an error in initializing the text summarizer. |

  #### Return Value

  A new instance of `MPPTextSummarizer` with the given options. `nil` if there is an error in initializing the text summarizer.
- `
  ### [close()](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/TextSummarizer.md.txt#/c:objc(cs)MPPTextSummarizer(im)closeWithError:)

  ` Shuts down the `MPPTextSummarizer` when all the work is done.

  #### Declaration

  Swift

      func close() throws

  #### Parameters

  |---|---|
  | `error` | An optional error parameter populated when there is an error in shutting down the text summarizer. |

  #### Return Value

  `YES` if the `MPPTextSummarizer` was successfully closed, `NO` otherwise.
- `
  ### [summarize(text:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/TextSummarizer.md.txt#/c:objc(cs)MPPTextSummarizer(im)summarizeText:error:)

  ` Performs summarization on the input text.

  #### Declaration

  Swift

      func summarize(text: String) throws -> TextSummarizerResult

  #### Parameters

  |---|---|
  | `text` | The `NSString` on which summarization is to be performed. |
  | `error` | An optional error parameter populated when there is an error in performing summarization on the input text. |

  #### Return Value

  A `MPPTextSummarizerResult` object that contains the complete summary result.
- `
  ### [summarizeStreaming(text:completion:)](https://developers.google.com/edge/api/mediapipe/swift/text/Classes/TextSummarizer.md.txt#/c:objc(cs)MPPTextSummarizer(im)summarizeStreamingWithText:completionHandler:error:)

  ` Performs summarization on the input `text` and returns the result incrementally via the callback.

  #### Declaration

  Swift

      func summarizeStreaming(text: String, completion completionHandler: @escaping (TextSummarizerStreamResult?, (any Error)?) -> Void) throws

  #### Parameters

  |---|---|
  | `text` | The input text to be summarized. |
  | `completionHandler` | The completion handler invoked with the incremental summarization result or an error. |
  | `error` | An optional error parameter populated when there is an error in initiating the summarization on the input text. |

  #### Return Value

  `YES` if the stream summarization was successfully initiated, `NO` otherwise.