tardis-bot/tts/sam/index.js

25 lines
763 B
JavaScript
Raw Permalink Normal View History

2021-07-03 15:09:19 +00:00
const BaseEngine = require('../BaseEngine')
const Sam = require('sam-js');
const wavefile = require('wavefile');
const fs = require('fs');
module.exports = class extends BaseEngine {
constructor() {
super('sam', 'Software Automatic Mouth', 'wav')
}
getDefaultVoice() {
2021-07-03 20:51:19 +00:00
return 'sam';
2021-07-03 15:09:19 +00:00
}
async getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
2021-07-03 15:11:28 +00:00
let sam = new Sam();
2021-07-03 23:06:42 +00:00
let phonetic = false;
if (text[0] == "$") {
text = text.slice(1);
phonetic = true;
}
const buf = sam.buf8(text, phonetic);
2021-07-03 15:09:19 +00:00
const file = new wavefile.WaveFile();
file.fromScratch(1, 22050, 8, buf);
fs.writeFileSync(filepath, file.toBuffer());
}
}