Update code to typescript
This commit is contained in:
33
src/tts/espeak.ts
Normal file
33
src/tts/espeak.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user