22 lines
723 B
JavaScript
22 lines
723 B
JavaScript
const fs = require('fs');
|
|
|
|
module.exports = class {
|
|
constructor(shortName, longName, fileExtension, supportedParameters = []) {
|
|
this.shortName = shortName;
|
|
this.longName = longName;
|
|
this.fileExtension = fileExtension;
|
|
}
|
|
getInternalVoiceName(str) {
|
|
return this.voices ? this.voices[str] : str;
|
|
}
|
|
getDefaultVoice() { }
|
|
validateVoice(voice) { return this.voices ? this.voices[voice] : true; }
|
|
async getSpeech(text, voice = this.getDefaultVoice(), params) { }
|
|
async getSpeechFile(text, filepath, voice, params) {
|
|
const data = await this.getSpeech(text, voice, params);
|
|
const contents = await data.arrayBuffer();
|
|
const buf = Buffer.from(contents);
|
|
fs.writeFileSync(filepath, buf);
|
|
return filepath;
|
|
}
|
|
} |