@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
90 lines (89 loc) • 2.85 kB
JavaScript
/**
* Speech-to-Text (STT) Type Definitions for NeuroLink
*
* All STT-specific types: options, results, handlers,
* provider-specific options, error codes, defaults, and type guards.
*
* @module types/stt
*/
// ============================================================================
// STT ERROR CODES
// ============================================================================
/**
* STT error codes
*/
export const STT_ERROR_CODES = {
AUDIO_EMPTY: "STT_AUDIO_EMPTY",
AUDIO_TOO_LONG: "STT_AUDIO_TOO_LONG",
INVALID_AUDIO_FORMAT: "STT_INVALID_AUDIO_FORMAT",
LANGUAGE_NOT_SUPPORTED: "STT_LANGUAGE_NOT_SUPPORTED",
TRANSCRIPTION_FAILED: "STT_TRANSCRIPTION_FAILED",
PROVIDER_NOT_CONFIGURED: "STT_PROVIDER_NOT_CONFIGURED",
PROVIDER_NOT_SUPPORTED: "STT_PROVIDER_NOT_SUPPORTED",
STREAM_ERROR: "STT_STREAM_ERROR",
STREAMING_NOT_SUPPORTED: "STT_STREAMING_NOT_SUPPORTED",
};
// ============================================================================
// STT DEFAULTS
// ============================================================================
/**
* Default STT options
*/
export const DEFAULT_STT_OPTIONS = {
language: "en-US",
punctuation: true,
profanityFilter: false,
sampleRate: 16000,
};
// ============================================================================
// STT TYPE GUARDS
// ============================================================================
/**
* Type guard for STTResult
*/
export function isSTTResult(value) {
if (!value || typeof value !== "object") {
return false;
}
const obj = value;
return (typeof obj.text === "string" &&
typeof obj.confidence === "number" &&
obj.confidence >= 0 &&
obj.confidence <= 1);
}
/**
* Type guard for valid STTOptions
*/
export function isValidSTTOptions(options) {
if (!options || typeof options !== "object") {
return false;
}
const opts = options;
if (opts.sampleRate !== undefined) {
if (typeof opts.sampleRate !== "number" || opts.sampleRate <= 0) {
return false;
}
}
if (opts.speakerCount !== undefined) {
if (typeof opts.speakerCount !== "number" ||
opts.speakerCount < 1 ||
opts.speakerCount > 10) {
return false;
}
}
return true;
}
/**
* Type guard for TranscriptionSegment
*/
export function isTranscriptionSegment(value) {
if (!value || typeof value !== "object") {
return false;
}
const obj = value;
// `index` is optional on the type — accept either undefined or a number,
// otherwise valid segments without an index would fail the guard.
return ((obj.index === undefined || typeof obj.index === "number") &&
typeof obj.text === "string" &&
typeof obj.isFinal === "boolean");
}