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

63 lines (62 loc) • 2.65 kB
/** * OpenAI Whisper Speech-to-Text Handler * * Implementation of STT using OpenAI's Whisper model. * * @module voice/providers/OpenAISTT */ import type { TTSAudioFormat, STTCredentials, STTHandler, STTLanguage, STTOptions, STTResult } from "../../types/index.js"; export declare class OpenAISTT implements STTHandler { private readonly apiKey; private readonly baseUrl; private readonly defaultTimeoutMs; /** The `model` sent when the request names none. */ private readonly defaultModel; /** * Maximum audio duration in seconds (25 minutes) */ readonly maxAudioDuration: number; /** * Whisper does not support streaming */ readonly supportsStreaming = false; /** * @param apiKeyOrCredentials - The `credentials.stt.whisper` slice * (`apiKey`, `baseURL`, `timeoutMs`), or — the original positional form — * an API key. Anything left out falls back to the environment. * @param baseUrl - Base URL, positional form only. */ constructor(apiKeyOrCredentials?: string | STTCredentials["whisper"], baseUrl?: string); /** True when pointed at OpenAI itself rather than a compatible server. */ private get isOfficialEndpoint(); /** * OpenAI itself needs a key. A compatible server at another base URL may * not (a self-hosted engine on the local network), so a base URL alone * configures the handler and the request goes without an Authorization header. */ isConfigured(): boolean; getSupportedFormats(): TTSAudioFormat[]; getSupportedLanguages(): Promise<STTLanguage[]>; transcribe(audio: Buffer | ArrayBuffer, options?: STTOptions): Promise<STTResult>; /** * The context prompt: the caller's own text, then the vocabulary as one * sentence. Whisper-style decoders treat the prompt as preceding text, so a * plain list of names biases spelling without being read as an instruction. */ private static buildPrompt; /** * Optional language-identification fields a self-hosted server may add to * `verbose_json`. Each is read only when it has the expected shape; a * server that sends none (OpenAI itself) contributes nothing. */ private static readLanguageExtensions; /** * Get MIME type for audio format. Whisper auto-detects from headers, but * sending a correct MIME helps providers / proxies that sniff Content-Type. * Must stay aligned with `getSupportedFormats()`. */ private getMimeType; } export { OpenAISTT as WhisperSTT }; export { OpenAISTT as WhisperSTTHandler }; export { OpenAISTT as OpenAISTTHandler };