tardis-bot/tts/sam/index.js

25 lines
763 B
JavaScript

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() {
return 'sam';
}
async getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
let sam = new Sam();
let phonetic = false;
if (text[0] == "$") {
text = text.slice(1);
phonetic = true;
}
const buf = sam.buf8(text, phonetic);
const file = new wavefile.WaveFile();
file.fromScratch(1, 22050, 8, buf);
fs.writeFileSync(filepath, file.toBuffer());
}
}