@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
71 lines (70 loc) • 1.79 kB
JavaScript
/**
* Text-to-Speech (TTS) Type Definitions for NeuroLink
*
* This module defines types for TTS audio generation and output.
*
* @module types/ttsTypes
*/
/** Valid audio formats as an array for runtime validation */
export const VALID_AUDIO_FORMATS = [
"mp3",
"wav",
"ogg",
"opus",
"m4a",
"flac",
"webm",
"mp4",
"mpeg",
"mpga",
"pcm16",
];
/** Valid TTS quality levels as an array for runtime validation */
export const VALID_TTS_QUALITIES = ["standard", "hd"];
/**
* Type guard to check if an object is a TTSResult
*/
export function isTTSResult(value) {
if (!value || typeof value !== "object") {
return false;
}
const obj = value;
return (Buffer.isBuffer(obj.buffer) &&
typeof obj.format === "string" &&
VALID_AUDIO_FORMATS.includes(obj.format) &&
typeof obj.size === "number" &&
obj.size >= 0);
}
/**
* Type guard to check if TTSOptions are valid
*/
export function isValidTTSOptions(options) {
if (!options || typeof options !== "object") {
return false;
}
const opts = options;
if (opts.speed !== undefined) {
if (typeof opts.speed !== "number" ||
opts.speed < 0.25 ||
opts.speed > 4.0) {
return false;
}
}
if (opts.format !== undefined) {
if (!VALID_AUDIO_FORMATS.includes(opts.format)) {
return false;
}
}
if (opts.quality !== undefined) {
if (!VALID_TTS_QUALITIES.includes(opts.quality)) {
return false;
}
}
if (opts.streamingBufferSize !== undefined) {
if (!Number.isInteger(opts.streamingBufferSize) ||
opts.streamingBufferSize < 1) {
return false;
}
}
return true;
}