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

115 lines (114 loc) 3.54 kB
import { AbstractTTSClient } from "../core/abstract-tts"; import type { SpeakOptions, TTSCredentials, UnifiedVoice, WordBoundaryCallback } from "../types"; /** * Google TTS credentials */ export interface GoogleTTSCredentials extends TTSCredentials { /** * Google Cloud project ID */ projectId?: string; /** * Google Cloud credentials JSON */ credentials?: any; /** * Google Cloud credentials file path */ keyFilename?: string; } /** * Google TTS client */ export declare class GoogleTTSClient extends AbstractTTSClient { /** * Google Cloud Text-to-Speech client */ private client; /** * Whether to use the beta API for word timings */ private useBetaApi; /** * Google Cloud credentials */ private googleCredentials; /** * Create a new Google TTS client * @param credentials Google Cloud credentials */ constructor(credentials: GoogleTTSCredentials); /** * Get available voices from the provider * @returns Promise resolving to an array of voice objects */ protected _getVoices(): Promise<any[]>; /** * Convert 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 * @param text Text or SSML to synthesize * @param options Synthesis options * @returns Promise resolving to a readable stream of audio bytes or stream with word boundaries */ synthToBytestream(text: string, options?: SpeakOptions): Promise<ReadableStream<Uint8Array> | { 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>; /** * Get available voices * @returns Promise resolving to an array of available voices */ /** * Map Google voice objects to unified format * @param rawVoices Array of Google voice objects * @returns Promise resolving to an array of unified voice objects */ protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>; /** * Prepare SSML for synthesis * @param text Text or SSML to prepare * @param options Synthesis options * @returns SSML ready for synthesis */ private prepareSSML; /** * Add SSML mark tags for word timing * @param ssml SSML to add mark tags to * @returns SSML with mark tags */ private addWordTimingMarks; /** * Process timepoints from Google TTS response * @param timepoints Timepoints from Google TTS response * @param text Original text */ private processTimepoints; /** * Map Google SSML gender to unified gender format * @param ssmlGender Google SSML gender * @returns Unified gender format */ private mapGender; /** * Check if credentials are valid * @returns Promise resolving to true if credentials are valid */ checkCredentials(): Promise<boolean>; }