From 43d7f60a7afc0cda60b2b6f6f12bcd2d4d118c93 Mon Sep 17 00:00:00 2001 From: Talon Date: Sat, 3 Jul 2021 17:09:19 +0200 Subject: [PATCH] Add sam as speech synth --- modules/announcer/index.js | 2 +- package-lock.json | 34 +++++++++++++++++++++++++++++++++- package.json | 4 +++- tts/sam/index.js | 20 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tts/sam/index.js diff --git a/modules/announcer/index.js b/modules/announcer/index.js index 2de4bf5..d62658e 100644 --- a/modules/announcer/index.js +++ b/modules/announcer/index.js @@ -26,6 +26,6 @@ module.exports = function (bot, api) { str = printf(api.strings.USER_JOINED, username); } api.queue.add(__dirname + "/sysmsg.wav"); - api.speak(channel, str); + api.queue.add(channel, str); }) } diff --git a/package-lock.json b/package-lock.json index c594ece..4dccff7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,9 +17,11 @@ "node-google-translate-skidz": "^1.1.2", "opusscript": "^0.0.8", "printf": "^0.6.1", + "sam-js": "^0.1.2", "sha1": "^1.1.1", "sqlite": "^4.0.21", - "sqlite3": "^5.0.2" + "sqlite3": "^5.0.2", + "wavefile": "^11.0.0" } }, "node_modules/@angular/common": { @@ -1830,6 +1832,15 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/sam-js": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/sam-js/-/sam-js-0.1.2.tgz", + "integrity": "sha512-xK9BrzJGfKVsbteyXGUMlYyJPI1RKDZEqD3KRT1PSBhZ5YDfxkKLpeWeN7RIu3/zbHHyW4lisqCcRbugygT4jg==", + "engines": { + "node": ">= 4.0.0", + "yarn": ">= 1.17.3" + } + }, "node_modules/sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", @@ -2084,6 +2095,17 @@ "extsprintf": "^1.2.0" } }, + "node_modules/wavefile": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/wavefile/-/wavefile-11.0.0.tgz", + "integrity": "sha512-/OBiAALgWU24IG7sC84cDO/KfFuvajWc5Uec0oV2zrpOOZZDgGdOwHwgEzOrwh8jkubBk7PtZfQBIcI1OaE5Ng==", + "bin": { + "wavefile": "bin/wavefile.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -3649,6 +3671,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "sam-js": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/sam-js/-/sam-js-0.1.2.tgz", + "integrity": "sha512-xK9BrzJGfKVsbteyXGUMlYyJPI1RKDZEqD3KRT1PSBhZ5YDfxkKLpeWeN7RIu3/zbHHyW4lisqCcRbugygT4jg==" + }, "sax": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", @@ -3853,6 +3880,11 @@ "extsprintf": "^1.2.0" } }, + "wavefile": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/wavefile/-/wavefile-11.0.0.tgz", + "integrity": "sha512-/OBiAALgWU24IG7sC84cDO/KfFuvajWc5Uec0oV2zrpOOZZDgGdOwHwgEzOrwh8jkubBk7PtZfQBIcI1OaE5Ng==" + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", diff --git a/package.json b/package.json index c77ef04..fa6b072 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,10 @@ "node-google-translate-skidz": "^1.1.2", "opusscript": "^0.0.8", "printf": "^0.6.1", + "sam-js": "^0.1.2", "sha1": "^1.1.1", "sqlite": "^4.0.21", - "sqlite3": "^5.0.2" + "sqlite3": "^5.0.2", + "wavefile": "^11.0.0" } } diff --git a/tts/sam/index.js b/tts/sam/index.js new file mode 100644 index 0000000..e3b2f15 --- /dev/null +++ b/tts/sam/index.js @@ -0,0 +1,20 @@ +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 'en'; + } + async getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) { + let sam = new samjs(); + const buf = sam.buf8(text); + const file = new wavefile.WaveFile(); + file.fromScratch(1, 22050, 8, buf); + fs.writeFileSync(filepath, file.toBuffer()); + } +} \ No newline at end of file