js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
102 lines (101 loc) • 3.4 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types";
/**
* IBM Watson TTS Client Credentials
*/
export interface WatsonTTSCredentials extends TTSCredentials {
apiKey: string;
region: string;
instanceId: string;
disableSSLVerification?: boolean;
}
/**
* IBM Watson TTS Client
*/
export declare class WatsonTTSClient extends AbstractTTSClient {
private apiKey;
private region;
private instanceId;
protected wordBoundaries: Array<{
text: string;
offset: number;
duration: number;
}>;
private iamToken;
private wsUrl;
/**
* Create a new IBM Watson TTS client
* @param credentials Watson credentials object with apiKey, region, and instanceId
*/
constructor(credentials: WatsonTTSCredentials);
/**
* Get raw voices from Watson
* @returns Promise resolving to an array of unified voice objects
*/
protected _getVoices(): Promise<any[]>;
/**
* Map Watson voice objects to unified format
* @param rawVoices Array of Watson voice objects
* @returns Promise resolving to an array of unified voice objects
*/
protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>;
/**
* Refresh the IAM token for Watson API
* @returns Promise resolving when token is refreshed
*/
private _refreshIAMToken;
/**
* Prepare SSML for synthesis
* @param text Text or SSML to prepare
* @param options Synthesis options
* @returns SSML string ready for synthesis
*/
private prepareSSML;
/**
* Synthesize text to audio bytes
* @param text Text or SSML to synthesize
* @param options Synthesis options
* @returns Promise resolving to audio bytes
*/
synthToBytes(text: string, options?: SpeakOptions): Promise<Uint8Array>;
/**
* Synthesize text to a byte stream with word boundary information
* @param text Text or SSML to synthesize
* @param options Synthesis options
* @returns Promise resolving to an object containing the audio stream and word boundary information
*/
synthToBytestream(text: string, options?: SpeakOptions): Promise<{
audioStream: ReadableStream<Uint8Array>;
wordBoundaries: Array<{
text: string;
offset: number;
duration: number;
}>;
}>;
/**
* Synthesize text to a byte stream using the WebSocket API in browser
* @param ssml SSML to synthesize
* @param voice Voice to use
* @returns Promise resolving to an object containing the audio stream and word boundary information
*/
private _synthToBytestreamWithBrowserWebSocket;
/**
* Synthesize text to a byte stream using the REST API
* @param ssml SSML to synthesize
* @param options Synthesis options
* @returns Promise resolving to an object containing the audio stream and word boundary information
*/
private _synthToBytestreamWithREST;
/**
* Set the voice to use for synthesis
* @param voiceId Voice ID to use
* @param lang Language code (not used in Watson)
*/
setVoice(voiceId: string, lang?: string): void;
}
/**
* Extended options for Watson TTS
*/
export interface WatsonTTSOptions extends SpeakOptions {
format?: "mp3" | "wav";
}