edge-tts-generator
Version:
Generate text-to-speech narration for free, leveraging the Read Aloud feature in Microsoft Edge
106 lines (102 loc) • 3.07 kB
text/typescript
declare enum OUTPUT_FORMAT {
AUDIO_24KHZ_48KBITRATE_MONO_MP3 = "audio-24khz-48kbitrate-mono-mp3",
AUDIO_24KHZ_96KBITRATE_MONO_MP3 = "audio-24khz-96kbitrate-mono-mp3",
WEBM_24KHZ_16BIT_MONO_OPUS = "webm-24khz-16bit-mono-opus"
}
declare enum PITCH {
X_LOW = "x-low",
LOW = "low",
MEDIUM = "medium",
HIGH = "high",
X_HIGH = "x-high",
DEFAULT = "default"
}
declare enum RATE {
X_SLOW = "x-slow",
SLOW = "slow",
MEDIUM = "medium",
FAST = "fast",
X_FAST = "x-fast",
DEFAULT = "default"
}
declare enum VOLUME {
SILENT = "silent",
X_SOFT = "x-soft",
SOFT = "soft",
MEDIUM = "medium",
LOUD = "loud",
X_LOUD = "x-LOUD",
DEFAULT = "default"
}
type EventType = "data" | "close" | "end" | "error";
declare class EventEmitter {
private eventListeners;
constructor();
on(event: EventType, callback: (...args: any[]) => void): void;
emit(event: EventType, data: any): void;
}
type Voice = {
Name: string;
ShortName: string;
Gender: string;
Locale: string;
SuggestedCodec: string;
FriendlyName: string;
Status: string;
};
declare class ProsodyOptions {
pitch: PITCH | string;
rate: RATE | string | number;
volume: VOLUME | string | number;
}
declare class EdgeTTSClient {
static OUTPUT_FORMAT: typeof OUTPUT_FORMAT;
private static CLIENT_TOKEN;
private static VOICES_URL;
private static SYNTH_URL;
private static BINARY_DELIM;
private static VOICE_LANG_REGEX;
private enableLogging;
private ws;
private voice;
private voiceLocale;
private outputFormat;
private requestQueue;
private connectionStartTime;
constructor(enableLogging?: boolean);
private log;
private sendMessage;
private initWebSocket;
private handleMessage;
private handleClose;
private cacheAudioData;
private findDelimiterIndex;
private getConfigMessage;
getVoices(): Promise<Voice[]>;
setMetadata(voiceName: string, outputFormat: OUTPUT_FORMAT, voiceLocale?: string): Promise<void>;
private inferLocaleFromVoiceName;
close(): void;
toStream(text: string, options?: ProsodyOptions): EventEmitter;
private buildSSML;
private sendSSMLRequest;
}
type TextToSpeechOptions = {
voice?: string;
speed?: number;
enableLogging?: boolean;
disableFilter?: boolean;
};
type TextToSpeechProps = {
text: string;
outputPath: string;
fileName: string;
options?: TextToSpeechOptions;
};
declare function textToSpeechMp3({ text, outputPath, fileName, options, }: TextToSpeechProps): Promise<void>;
type TextToSpeechInput = {
text: string;
title: string;
options?: TextToSpeechOptions;
};
declare function batchTextToSpeechMp3(inputs: TextToSpeechInput[], outputPath: string, globalOptions?: TextToSpeechOptions): Promise<void>;
export { EdgeTTSClient, OUTPUT_FORMAT, PITCH, ProsodyOptions, RATE, type TextToSpeechInput, type TextToSpeechOptions, type TextToSpeechProps, VOLUME, type Voice, batchTextToSpeechMp3, textToSpeechMp3 };