keenasr-web - v2.1.2
    Preparing search index...

    Class TextAligner

    TextAligner provides language-aware text alignment between a reference text and recognized (hypothesis) text from ASR.

    Features:

    • Language-aware text normalization
    • Incremental alignment for partial results (better performance)
    • Rich AlignmentResult with WER stats and oral-reading views
    • Proper lifecycle management
    const aligner = new TextAligner(referenceText, 'en-us');
    try {
    // For partial results (streaming)
    const partial = aligner.incrementalAlign(partialText);
    console.log(`Furthest word: ${partial.furthestMatchedIndex}`);

    // For final result
    aligner.reset();
    const result = aligner.align(finalText);
    console.log(`WER: ${result.wordErrorRate}`);
    } finally {
    aligner.close();
    }
    Index

    Constructors

    • Create a TextAligner using the language from an initialized recognizer.

      Parameters

      • reference: string

        The reference text to align against.

      • recognizer: KeenASRBase

        An initialized KeenASR recognizer instance.

      Returns TextAligner

    Accessors

    • get referenceTokens(): string[]

      Get the reference tokens after normalization.

      Returns string[]

      Array of normalized reference tokens.

    • get isClosed(): boolean

      Check if the TextAligner has been closed.

      Returns boolean

    Methods

    • Perform stateless alignment of the recognized text against the reference.

      Use this method when you have the complete recognized text and don't need to track incremental progress.

      Parameters

      • recognized: string

        The recognized text to align.

      • Optionalconfig: Partial<AlignmentConfig>

        Optional alignment configuration.

      Returns AlignmentResult

      An immutable AlignmentResult snapshot.

    • Perform incremental alignment for streaming partial results.

      This method maintains state between calls for better performance when processing streaming ASR results. The alignment builds on previous results, making it efficient for real-time updates.

      Parameters

      • recognized: string

        The recognized text (typically a partial result).

      • Optionalconfig: Partial<AlignmentConfig>

        Optional alignment configuration.

      Returns AlignmentResult

      An immutable AlignmentResult snapshot.

    • Reset the incremental alignment state.

      Call this when starting a new recognition session to clear any cached state from previous incremental alignments.

      Returns void

    • Release native resources.

      Always call this method when done with the TextAligner to prevent memory leaks. After calling close(), the TextAligner cannot be used.

      Returns void

    • Support for using statement (Symbol.dispose).

      Enables usage with the using keyword:

      using aligner = new TextAligner(reference, 'en-us', core);
      const result = aligner.align(recognized);
      // aligner.close() is called automatically

      Returns void