2021-04-06 23:36:35 +00:00
|
|
|
const fs = require('fs');
|
2021-04-06 00:16:09 +00:00
|
|
|
|
2021-04-06 23:36:35 +00:00
|
|
|
module.exports = class {
|
|
|
|
constructor(longName, fileExtension, supportedParameters = []) {
|
|
|
|
this.longName = longName;
|
|
|
|
this.fileExtension = fileExtension;
|
2021-04-06 00:16:09 +00:00
|
|
|
}
|
2021-04-06 23:33:47 +00:00
|
|
|
getInternalVoiceName(str) {
|
2021-04-06 23:36:35 +00:00
|
|
|
return this.voices ? this.voices[str] : str;
|
2021-04-06 23:33:47 +00:00
|
|
|
}
|
2021-04-06 23:36:35 +00:00
|
|
|
getDefaultVoice() { }
|
|
|
|
validateVoice(voice) { return this.voices ? this.voices[voice] : true; }
|
|
|
|
async getSpeech(text, voice = this.getDefaultVoice(), params) { }
|
2021-04-06 00:16:09 +00:00
|
|
|
async getSpeechFile(text, filepath, voice, params) {
|
|
|
|
const data = await this.getSpeech(text, voice, params);
|
2021-04-06 23:36:35 +00:00
|
|
|
const contents = await data.arrayBuffer();
|
|
|
|
const buf = Buffer.from(contents);
|
|
|
|
fs.writeFileSync(filepath, buf);
|
2021-04-06 00:16:09 +00:00
|
|
|
return filepath;
|
|
|
|
}
|
|
|
|
}
|