js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
68 lines (67 loc) • 2.3 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types";
/**
* ModelsLab TTS Client Credentials
*/
export interface ModelsLabTTSCredentials extends TTSCredentials {
/** ModelsLab API key (also reads MODELSLAB_API_KEY env var) */
apiKey?: string;
}
/**
* Extended speak options for ModelsLab TTS
*/
export interface ModelsLabTTSOptions extends SpeakOptions {
/** Language descriptor e.g. "american english", "british english" */
language?: string;
/** Speed multiplier (default 1.0) */
speed?: number;
/** Enable emotion tags in the prompt (English only) */
emotion?: boolean;
}
/**
* ModelsLab TTS Client
*
* Provides text-to-speech via the ModelsLab Voice API.
* API docs: https://docs.modelslab.com/voice-cloning/text-to-speech
*
* @example
* ```ts
* const client = new ModelsLabTTSClient({ apiKey: "your-api-key" });
* await client.synthToFile("Hello world!", "output.mp3");
* ```
*/
export declare class ModelsLabTTSClient extends AbstractTTSClient {
private apiKey;
private defaultLanguage;
private defaultSpeed;
protected sampleRate: number;
constructor(credentials?: ModelsLabTTSCredentials);
/** Check if credentials are present */
checkCredentials(): Promise<boolean>;
protected getRequiredCredentials(): string[];
protected _getVoices(): Promise<UnifiedVoice[]>;
/**
* Synthesize text to audio bytes (Uint8Array).
* Handles async generation — polls until audio is ready.
*/
synthToBytes(text: string, options?: ModelsLabTTSOptions): Promise<Uint8Array>;
/**
* Synthesize text to a ReadableStream of audio chunks.
*/
synthToBytestream(text: string, options?: ModelsLabTTSOptions): Promise<{
audioStream: ReadableStream<Uint8Array>;
wordBoundaries: Array<{
text: string;
offset: number;
duration: number;
}>;
}>;
/** Internal: call ModelsLab API and return audio bytes. */
private _synthesize;
/** Poll the fetch_result URL until audio is ready. */
private _poll;
/** Download audio from URL and return as Uint8Array. */
private _downloadAudio;
private _sleep;
}
export default ModelsLabTTSClient;