@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
65 lines (64 loc) • 3.25 kB
TypeScript
/**
* Batch transcription orchestration behind `neurolink.transcribe()`:
*
* load audio → resolve provider → transcribe (+ second opinion in parallel)
* → fallback → correction → TranscribeResult
*
* Everything that touches the SDK (handlers, credentials, `tryDecide`, the
* rewrite model) arrives through `TranscribeDeps`, so this module stays free
* of provider plumbing. Nothing here may lose words: a failed second opinion
* or fallback keeps the primary text, and a correction that comes back empty
* keeps the engine text.
*
* @module voice/transcribe
*/
import type { AttachmentPolicy, STTOptions, STTStreamingOptions, TranscribeAudioInput, TranscribeDeps, TranscribeOptions, TranscribeResult, TTSAudioFormat } from "../types/index.js";
/**
* The first `seconds` of a PCM WAV as a smaller WAV, so a language probe
* uploads kilobytes instead of the whole recording. Anything that is not a
* plain RIFF/WAVE with a readable `fmt ` and `data` chunk is returned as is.
*/
export declare function wavHead(buffer: Buffer, seconds: number): Buffer;
/** The container a path or URL names by its extension, if it is a known one. */
export declare function audioFormatFromName(name: string): TTSAudioFormat | undefined;
/**
* The container a buffer's leading bytes identify: WAV, MP3 and Ogg via the
* shared detector, plus FLAC, WebM/Matroska and ISO-BMFF (m4a/mp4).
*/
export declare function audioFormatFromBytes(buffer: Buffer): TTSAudioFormat | undefined;
/**
* Read a batch audio input into a Buffer: bytes as they are, a local path or
* `file://` URL from disk, an `http(s)://` URL over the network. A format
* implied by the path or URL is returned alongside.
*
* @throws STTError when the input is a frame stream, or cannot be read
*/
export declare function loadTranscribeAudio(input: TranscribeAudioInput, timeoutMs?: number, attachmentPolicy?: AttachmentPolicy): Promise<{
buffer: Buffer;
formatHint?: TTSAudioFormat;
}>;
/**
* The handler options for one engine. Fields only the orchestration reads
* (dictionary, correction, fallback, streaming, credentials) are dropped;
* the correction context rides along in the prompt for engines that take one.
*/
export declare function buildEngineOptions(options: Omit<TranscribeOptions, "audio">, format: TTSAudioFormat | undefined, model: string | undefined): STTOptions;
/**
* Transcribe one recording with every configured layer. See the module
* comment for the order of operations.
*
* @throws STTError when the audio cannot be loaded, the provider is unknown,
* or the primary engine fails with no fallback that covers errors
*/
export declare function runTranscribe(options: TranscribeOptions, deps: TranscribeDeps): Promise<TranscribeResult>;
/**
* The stream options a recording gets when it goes through the live
* pipeline, whether by `chunking: "utterances"` or over the WebSocket with
* `mode: "file"`: no interim passes, several utterances at a time, one retry
* of a failed final, file-sized engine timeouts and shorter cuts. Anything
* the caller set explicitly is kept.
*/
export declare function fileModeStreamOptions<T extends {
streaming?: STTStreamingOptions;
timeoutMs?: number;
}>(options: T): T;