34 lines
875 B
TypeScript
34 lines
875 B
TypeScript
import { spawn } from "node:child_process";
|
|
import { BaseEngine, type VoiceParams } from "./BaseEngine.js";
|
|
|
|
export class EspeakEngine extends BaseEngine {
|
|
constructor() {
|
|
super("espeak", "ESpeak", "wav");
|
|
}
|
|
|
|
override getDefaultVoice(): string {
|
|
return "en";
|
|
}
|
|
|
|
override validateVoice(_voice: string): boolean {
|
|
return true;
|
|
}
|
|
|
|
override async getSpeechFile(
|
|
text: string,
|
|
filepath: string,
|
|
voice: string = this.getDefaultVoice(),
|
|
_params: VoiceParams = {},
|
|
): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
const proc = spawn("espeak", ["-v", voice, "-w", filepath, "--stdin"]);
|
|
proc.on("error", reject);
|
|
proc.on("close", (code) => {
|
|
if (code === 0) resolve(filepath);
|
|
else reject(new Error(`espeak exited with code ${code}`));
|
|
});
|
|
proc.stdin.end(text);
|
|
});
|
|
}
|
|
}
|