UNPKG

@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

70 lines (69 loc) • 4.19 kB
/** * Transcript correction: dictionary candidates → decision-model guard → LLM * rewrite. * * Every layer fails open and none may lose words. With no decision provider, * on a guard timeout or error, the dictionary is applied as is; on a rewrite * timeout or error, or a rewrite that drops too many words, the * dictionary-applied text is kept. The result's `steps` say which of those * happened, so a silently degraded path is still visible to the caller. * * @module voice/correction */ import { applyDictionary, dictionaryBlock, dictionaryVocabulary, findDictionaryCandidates } from "./dictionary.js"; import { decideCandidates } from "./guard.js"; import { buildRewriteSystemPrompt, buildRewriteUserPrompt, rewriteLines, rewriteTranscript, rewriteWanted } from "./rewrite.js"; import type { STTCorrectionDeps, STTCorrectionInput, STTCorrectionOptions, STTCorrectionOutput, STTDecisionRecord, STTDictionaryEntry } from "../../types/index.js"; export { applyDictionary, buildRewriteSystemPrompt, buildRewriteUserPrompt, decideCandidates, dictionaryBlock, dictionaryVocabulary, findDictionaryCandidates, rewriteLines, rewriteTranscript, rewriteWanted, }; /** Correction is on when asked for, or by default when a dictionary or a rewrite is configured. */ export declare function isCorrectionEnabled(dictionary: readonly STTDictionaryEntry[] | undefined, options: STTCorrectionOptions | undefined): boolean; /** * Correct one transcript (a whole short recording, or one final utterance * when streaming). Never throws on a layer's failure and never returns empty * text when either transcript had words. * * When the primary engine reported a low language score * (`languageDetected === false`) and a second opinion exists, the second * opinion leads: an Indic engine on English speech produces confident-looking * nonsense, and the English-oriented engine's text is the better base. The * engine text then goes to the rewrite as the secondary transcript, so * Indian-language words it did catch are not lost. */ export declare function correctTranscript(input: STTCorrectionInput, deps: STTCorrectionDeps): Promise<STTCorrectionOutput>; /** * Split a transcript into sentences on terminal punctuation (., !, ?, the * danda, an ellipsis), keeping the marks. Text without any mark is one * sentence; a split that would leave a fragment under three words glues it * to its neighbour so a stray "No." never travels alone. */ export declare function splitSentences(text: string): string[]; /** * Correct one final sentence by sentence: each sentence gets its own * dictionary pass, its own "does this need the rewrite" decision (an * English sentence that is already clean costs nothing; a Devanagari one * is romanised) and sentences run three at a time. The joined text has the * same sentences in the same order; a sentence whose correction fails keeps * its words. `onPartial` receives the whole utterance with the sentences * corrected so far, so a caption can update progressively. * * Falls back to a single whole-text pass when there is one sentence or a * second opinion (whole-utterance by nature) to reconcile. */ export declare function correctTranscriptSentences(input: STTCorrectionInput, deps: STTCorrectionDeps): Promise<STTCorrectionOutput & { sentences: number; }>; /** * Correct a long transcript line by line (file transcription, diarized * turns). With the rewrite on, lines go to the model in numbered batches of * 25 and the dictionary travels in the prompt — the model sees each alias in * its sentence, which is the context the guard would otherwise supply. With * `rewrite: false`, each line with candidates gets its own guard call (up to * four at a time) and the dictionary is applied per line. The result always * has exactly as many lines as the input. */ export declare function correctTranscriptLines(lines: readonly string[], dictionary: readonly STTDictionaryEntry[] | undefined, options: STTCorrectionOptions | undefined, deps: STTCorrectionDeps, language?: string): Promise<{ lines: string[]; decisions: STTDecisionRecord[]; steps: string[]; timings: STTCorrectionOutput["timings"]; }>;