@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
50 lines (49 loc) • 2.66 kB
TypeScript
/**
* Dictionary matching for transcript correction.
*
* A dictionary entry names a term (a person, product, acronym …), the ways
* speech engines mis-hear it, and what it means. Every alias found in a
* transcript becomes a *candidate*: it is not applied blindly, because the
* alias of a name is usually an ordinary word too ("part" for a name that
* sounds like it). The guard (`guard.ts`) decides per candidate; this module
* only finds them and applies the verdicts.
*
* Matching is whole-word and script-agnostic: a word boundary is any
* character that is not a letter, a combining mark or a digit. Marks matter
* for Indic scripts, where vowel signs and viramas are `\p{M}`, not `\p{L}` —
* a letters-only boundary would let an alias match the first half of a word.
*
* @module voice/correction/dictionary
*/
import type { STTDecisionRecord, STTDictionaryCandidate, STTDictionaryEntry } from "../../types/index.js";
/** Whether `text` contains any Indic-script character. */
export declare function hasIndicScript(text: string): boolean;
/**
* Every alias of every entry that occurs in `text` as a whole word.
*
* An entry whose term already appears in the text contributes no candidates:
* the engine heard the term itself, so an alias elsewhere in the same text is
* more likely the ordinary word. An alias in an Indic script is skipped when
* the text has none (it cannot match, and the check is cheaper than a regex).
* Each (entry, alias) pair is reported once, however often it occurs.
*/
export declare function findDictionaryCandidates(text: string, dictionary: readonly STTDictionaryEntry[] | undefined): STTDictionaryCandidate[];
/**
* Replace every candidate the guard did not call `"literal"` with its term.
*
* `decisions[i]` belongs to `candidates[i]`; a missing decision applies the
* term, which is the same fail-open default the guard uses. Every occurrence
* is replaced — the decision was asked about the alias in this transcript, so
* all of its occurrences share the answer.
*/
export declare function applyDictionary(text: string, candidates: readonly STTDictionaryCandidate[], decisions: readonly STTDecisionRecord[]): string;
/**
* The dictionary as a table for the rewrite model's system prompt, or `""`
* when there is nothing to show.
*/
export declare function dictionaryBlock(dictionary: readonly STTDictionaryEntry[] | undefined): string;
/**
* Distinct dictionary terms, in dictionary order, for engines that bias
* recognition on a vocabulary or a context prompt.
*/
export declare function dictionaryVocabulary(dictionary: readonly STTDictionaryEntry[] | undefined): string[];