UNPKG

js-tts-wrapper

Version:

A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services

85 lines (84 loc) 3.13 kB
import { AbstractTTSClient } from "../core/abstract-tts"; import type { SpeakOptions, UnifiedVoice, WordBoundaryCallback } from "../types"; /** * Azure TTS Client */ export declare class AzureTTSClient extends AbstractTTSClient { private subscriptionKey; private region; /** * Create a new Azure TTS client * @param credentials Azure credentials object with subscriptionKey and region */ constructor(credentials: { subscriptionKey: string; region: string; }); /** * Get raw voices from Azure * @returns Promise resolving to an array of unified voice objects */ protected _getVoices(): Promise<any[]>; /** * Map Azure voice objects to unified format * @param rawVoices Array of Azure voice objects * @returns Promise resolving to an array of unified voice objects */ protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>; /** * 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 speech using the Microsoft Cognitive Services Speech SDK * @param ssml SSML to synthesize * @param options Synthesis options * @returns Promise resolving to an object containing the audio stream and word boundary information */ private synthToBytestreamWithSDK; /** * Synthesize speech 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; /** * Start playback with word boundary callbacks * @param text Text or SSML to speak * @param callback Callback function for word boundaries * @param options Synthesis options */ startPlaybackWithCallbacks(text: string, callback: WordBoundaryCallback, options?: SpeakOptions): Promise<void>; /** * Start playback with word boundary callbacks using the SDK * @param text Text or SSML to speak * @param callback Callback function for word boundaries * @param options Synthesis options */ private startPlaybackWithCallbacksSDK; /** * Prepare SSML for synthesis * @param text Text or SSML to prepare * @param options Synthesis options * @returns SSML ready for synthesis */ private prepareSSML; }