TextProofreader class

MediaPipe Task that performs text proofreading.

Signature:

export declare class TextProofreader extends TaskRunner 

Extends: TaskRunner

Methods

Method Modifiers Description
close() Closes the TextProofreader and frees resources.
createFromModelBuffer(wasmFileset, modelAssetBuffer, maxNumTokens) static Initializes the Wasm runtime and creates a new text proofreader based on the provided model asset buffer.
createFromModelPath(wasmFileset, modelAssetPath, maxNumTokens) static Initializes the Wasm runtime and creates a new text proofreader based on the path to the model asset.
createFromOptions(wasmFileset, textProofreaderOptions) static Initializes the Wasm runtime and creates a new text proofreader based on the provided options.
proofread(text) Proofreads the given text.
proofreadStreaming(text, progressListener) Proofreads the given text and invokes progressListener with each newly generated part of the proofread text.Only one proofread can be in flight at a time. As the underlying Wasm engine runs single-threaded, the calling browser thread remains blocked for the duration of this inference call, and the listener is invoked synchronously. Run the task in a Web Worker to keep the UI thread responsive.
setOptions(options) Sets the initial options for the text proofreader. LiteRT LM Tasks do not support updating options after initialization.

TextProofreader.close()

Closes the TextProofreader and frees resources.

Signature:

close(): void;

Returns:

void

TextProofreader.createFromModelBuffer()

Initializes the Wasm runtime and creates a new text proofreader based on the provided model asset buffer.

Signature:

static createFromModelBuffer(wasmFileset: WasmFileset, modelAssetBuffer: Uint8Array | ReadableStreamDefaultReader, maxNumTokens?: number): Promise<TextProofreader>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetBuffer Uint8Array | ReadableStreamDefaultReader An array or a stream containing a binary representation of the model.
maxNumTokens number The maximum number of tokens.

Returns:

Promise<TextProofreader>

TextProofreader.createFromModelPath()

Initializes the Wasm runtime and creates a new text proofreader based on the path to the model asset.

Signature:

static createFromModelPath(wasmFileset: WasmFileset, modelAssetPath: string, maxNumTokens?: number): Promise<TextProofreader>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
modelAssetPath string The path to the model asset.
maxNumTokens number The maximum number of tokens.

Returns:

Promise<TextProofreader>

TextProofreader.createFromOptions()

Initializes the Wasm runtime and creates a new text proofreader based on the provided options.

Signature:

static createFromOptions(wasmFileset: WasmFileset, textProofreaderOptions: TextProofreaderOptions): Promise<TextProofreader>;

Parameters

Parameter Type Description
wasmFileset WasmFileset A configuration object that provides the location of the Wasm binary and its loader.
textProofreaderOptions TextProofreaderOptions The options for TextProofreader.

Returns:

Promise<TextProofreader>

TextProofreader.proofread()

Proofreads the given text.

Signature:

proofread(text: string): TextProofreaderResult;

Parameters

Parameter Type Description
text string The input text to be proofread. The proofread text and the corrections.

Returns:

TextProofreaderResult

TextProofreader.proofreadStreaming()

Proofreads the given text and invokes progressListener with each newly generated part of the proofread text.

Only one proofread can be in flight at a time. As the underlying Wasm engine runs single-threaded, the calling browser thread remains blocked for the duration of this inference call, and the listener is invoked synchronously. Run the task in a Web Worker to keep the UI thread responsive.

Signature:

proofreadStreaming(text: string, progressListener?: ProofreaderProgressListener): Promise<TextProofreaderResult>;

Parameters

Parameter Type Description
text string The input text to be proofread.
progressListener ProofreaderProgressListener An optional listener that receives each newly generated part of the proofread text. A promise that resolves to the complete proofread text and the corrections.

Returns:

Promise<TextProofreaderResult>

TextProofreader.setOptions()

Sets the initial options for the text proofreader. LiteRT LM Tasks do not support updating options after initialization.

Signature:

setOptions(options: TextProofreaderOptions): Promise<void>;

Parameters

Parameter Type Description
options TextProofreaderOptions The options for the text proofreader.

Returns:

Promise<void>