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.66 kB
TypeScript
import { AbstractTTSClient } from "../core/abstract-tts";
import type { SpeakOptions, TTSCredentials, UnifiedVoice } from "../types";
export interface CereVoiceTTSCredentials extends TTSCredentials {
email?: string;
password?: string;
accessToken?: string;
refreshToken?: string;
baseURL?: string;
voice?: string;
sampleRate?: number;
audioFormat?: "wav" | "mp3" | "ogg";
properties?: Record<string, unknown> | string;
propertiesJson?: string;
}
export interface CereVoiceTTSOptions extends SpeakOptions {
voice?: string;
audioFormat?: "wav" | "mp3" | "ogg";
sampleRate?: number;
language?: string;
accent?: string;
metadata?: boolean;
providerOptions?: Record<string, string | number | boolean | undefined>;
}
type WordBoundaryResult = Array<{
text: string;
offset: number;
duration: number;
}>;
export declare class CereVoiceTTSClient extends AbstractTTSClient {
private email;
private password;
private accessToken;
private refreshToken;
private baseUrl;
private audioFormat;
private outputSampleRate?;
private language?;
private accent?;
private metadata;
private tokenExpiresAt;
constructor(credentials?: CereVoiceTTSCredentials);
private applyCredentialProperties;
setVoice(voiceId: string, lang?: string): void;
getProperty(property: string): any;
setProperty(property: string, value: any): void;
checkCredentials(): Promise<boolean>;
protected getRequiredCredentials(): string[];
protected _getVoices(): Promise<any[]>;
protected _mapVoicesToUnified(rawVoices: any[]): Promise<UnifiedVoice[]>;
synthToBytes(text: string, options?: CereVoiceTTSOptions): Promise<Uint8Array>;
synthToBytestream(text: string, options?: CereVoiceTTSOptions): Promise<{
audioStream: ReadableStream<Uint8Array>;
wordBoundaries: WordBoundaryResult;
}>;
private requestSynthesis;
private prepareInput;
private shouldApplyProsody;
private shouldRequestMetadata;
private getWordBoundariesFromResponse;
private parseMetadataXml;
private fillMissingDurations;
private parseXmlAttributes;
private createWordBoundary;
private fetchWithAuth;
private ensureAccessToken;
private login;
private refreshAccessToken;
private buildUrl;
private resolveAudioFormat;
private isSupportedAudioFormat;
private acceptHeaderForFormat;
private mapGender;
private isXmlLike;
private escapeXml;
private decodeXmlEntities;
private getHeader;
private encodeBasicCredentials;
private safeReadErrorText;
}
export {};