js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
129 lines (128 loc) • 3.9 kB
TypeScript
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;
}
/**
* Extended options for Google TTS
*/
export interface GoogleTTSOptions extends SpeakOptions {
format?: 'mp3' | 'wav';
}
/**
* 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);
/**
* Initialize the Google TTS client
* @param credentials Google TTS credentials
*/
private initializeClient;
/**
* 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?: GoogleTTSOptions): 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 word boundaries
*/
synthToBytestream(text: string, options?: GoogleTTSOptions): 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?: GoogleTTSOptions): 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;
/**
* Check if credentials are valid
* @returns Promise resolving to true if credentials are valid
*/
checkCredentials(): Promise<boolean>;
/**
* Check if credentials are valid with detailed response
* @returns Promise resolving to an object with success flag and optional error message
*/
checkCredentialsDetailed(): Promise<{
success: boolean;
error?: string;
voiceCount?: number;
}>;
}