js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
91 lines (90 loc) • 2.95 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts.js";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types.js";
/**
* WitAI TTS Client Credentials
*/
export interface WitAITTSCredentials extends TTSCredentials {
token: string;
}
/**
* WitAI TTS Client
*/
export declare class WitAITTSClient extends AbstractTTSClient {
private token;
private baseUrl;
private apiVersion;
private headers;
protected sampleRate: number;
/**
* Create a new WitAI TTS client
* @param credentials WitAI credentials object with token
*/
constructor(credentials: WitAITTSCredentials);
/**
* Check if credentials are valid
* @returns Promise resolving to true if credentials are valid
*/
checkCredentials(): Promise<boolean>;
/**
* Get the list of required credential types for this engine
* @returns Array of required credential field names
*/
protected getRequiredCredentials(): string[];
/**
* Get raw voices from WitAI
* @returns Promise resolving to an array of unified voice objects
*/
protected _getVoices(): Promise<any[]>;
/**
* Map WitAI voice objects to unified format
* @param rawVoices Array of WitAI voice objects
* @returns Promise resolving to an array of unified voice objects
*/
protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>;
/**
* Prepare text/SSML for synthesis
* @param text Text or SSML to prepare
* @param options Synthesis options
* @returns Prepared text or SSML
*/
private prepareText;
/**
* Get the appropriate Accept header based on the format option
* @param format Format option from WitAITTSOptions
* @returns MIME type string
*/
private getAcceptHeader;
/**
* Synthesize text to audio bytes
* @param text Text 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 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;
}>;
}>;
/**
* Set the voice to use for synthesis
* @param voiceId Voice ID to use
* @param lang Language code (not used in WitAI)
*/
setVoice(voiceId: string, lang?: string): void;
}
/**
* Extended options for WitAI TTS
*/
export interface WitAITTSOptions extends SpeakOptions {
format?: "mp3" | "wav" | "pcm";
}