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) • 2.6 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types";
/**
* AWS Polly TTS credentials
*/
export interface PollyTTSCredentials extends TTSCredentials {
/**
* AWS region
*/
region: string;
/**
* AWS access key ID
*/
accessKeyId: string;
/**
* AWS secret access key
*/
secretAccessKey: string;
}
/**
* AWS Polly TTS client
*/
export declare class PollyTTSClient extends AbstractTTSClient {
/**
* AWS Polly client
*/
private client;
/**
* Create a new AWS Polly TTS client
* @param credentials AWS credentials
*/
constructor(credentials: PollyTTSCredentials);
/**
* Get available voices from the provider
* @returns Promise resolving to an array of voice objects
*/
protected _getVoices(): Promise<any[]>;
/**
* Map AWS Polly voice objects to unified format
* @param rawVoices Array of AWS Polly voice objects
* @returns Promise resolving to an array of unified voice objects
*/
protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>;
/**
* Prepare SSML for AWS Polly
* @param text Text or SSML to prepare
* @param options Synthesis options
* @returns Prepared SSML
*/
private prepareSSML;
/**
* 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 with word boundaries
* @param text Text or SSML to synthesize
* @param options Synthesis options
* @returns Promise resolving to a readable stream of audio bytes with word boundaries
*/
synthToBytestream(text: string, options?: SpeakOptions): Promise<ReadableStream<Uint8Array> | {
audioStream: ReadableStream<Uint8Array>;
wordBoundaries: Array<{
text: string;
offset: number;
duration: number;
}>;
}>;
/**
* Get speech marks (word boundaries) for text
* @param inputText Text or SSML to get speech marks for
* @param options Synthesis options
* @returns Promise resolving to an array of word boundaries
*/
private getSpeechMarks;
/**
* Check if credentials are valid
* @returns Promise resolving to true if credentials are valid
*/
checkCredentials(): Promise<boolean>;
}