js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
93 lines (92 loc) • 2.96 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice, WordBoundaryCallback } from "../types";
/**
* Extended options for ElevenLabs TTS
*/
export interface ElevenLabsTTSOptions extends SpeakOptions {
format?: "mp3" | "wav";
}
/**
* ElevenLabs TTS credentials
*/
export interface ElevenLabsCredentials extends TTSCredentials {
/**
* ElevenLabs API key
*/
apiKey?: string;
}
/**
* ElevenLabs TTS client
*/
export declare class ElevenLabsTTSClient extends AbstractTTSClient {
/**
* ElevenLabs API key
*/
private apiKey;
/**
* Base URL for ElevenLabs API
*/
private baseUrl;
/**
* Create a new ElevenLabs TTS client
* @param credentials ElevenLabs credentials
*/
constructor(credentials?: ElevenLabsCredentials);
/**
* Check if the credentials are valid
* @returns Promise resolving to true if credentials are valid, false otherwise
*/
checkCredentials(): Promise<boolean>;
/**
* Get available voices from the provider
* @returns Promise resolving to an array of voice objects
*/
protected _getVoices(): Promise<any[]>;
/**
* Prepare text for synthesis by stripping SSML tags
* @param text Text to prepare
* @param options Synthesis options
* @returns Prepared text
*/
private prepareText;
/**
* Convert text to audio bytes
* @param text Text to synthesize
* @param options Synthesis options
* @returns Promise resolving to audio bytes
*/
synthToBytes(text: string, options?: ElevenLabsTTSOptions): Promise<Uint8Array>;
/**
* Synthesize text to a byte stream
* @param text Text to synthesize
* @param options Synthesis options
* @returns Promise resolving to an object containing the audio stream and an empty word boundaries array
*/
synthToBytestream(text: string, options?: ElevenLabsTTSOptions): Promise<{
audioStream: ReadableStream<Uint8Array>;
wordBoundaries: Array<{
text: string;
offset: number;
duration: number;
}>;
}>;
/**
* Start playback with word boundary callbacks
* @param text Text to speak
* @param callback Callback function for word boundaries
* @param options Synthesis options
*/
startPlaybackWithCallbacks(text: string, callback: WordBoundaryCallback, options?: SpeakOptions): Promise<void>;
/**
* Map ElevenLabs voice objects to unified format
* @param rawVoices Array of ElevenLabs voice objects
* @returns Promise resolving to an array of unified voice objects
*/
protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>;
/**
* Get voice by ID
* @param voiceId Voice ID
* @returns Promise resolving to voice details
*/
getVoice(voiceId: string): Promise<UnifiedVoice | null>;
}