js-tts-wrapper
Version:
A JavaScript/TypeScript library that provides a unified API for working with multiple cloud-based Text-to-Speech (TTS) services
81 lines (80 loc) • 2.57 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types";
/**
* 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);
/**
* 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 for synthesis
* @param text Text to prepare
* @param options Synthesis options
* @returns Prepared text
*/
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";
}