diff --git a/.DS_Store b/.DS_Store index d116d56..99e6f00 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/example.env b/example.env new file mode 100644 index 0000000..40180df --- /dev/null +++ b/example.env @@ -0,0 +1,13 @@ +TOKEN=DISCORD_BOT_TOKEN_HERE +GUILD=GUILD_ID_HERE +CHANNEL=VOICE_CHANNEL_ID_HERE +STRING_SET=en +VOICE_TMP_PATH=./voice_tmp/ +DB_FILE=DATABASE_PATH_HERE +PREFIX=+ +ANNOUNCEMENT_ENGINE=espeak +ANNOUNCEMENT_VOICE=en +watsonURL=WATSON_URL_HERE +watsonAPIKey=WATSON_API_KEY_HERE +TTS_CHANNEL=CANTTALK_TEXT_CHANNEL_ID_HERE +GOOGLE_APPLICATION_CREDENTIALS=GOOGLE_CLOUD_KEY_HERE \ No newline at end of file diff --git a/index.js b/index.js index 5b6cb33..e697667 100644 --- a/index.js +++ b/index.js @@ -22,6 +22,7 @@ async function initDB() { const api = { db: undefined, queue: undefined, + strings: require('./strings/'+process.env.STRING_SET+'.json'), ttsEngines: (() => { let engines = {}; console.log(`Registering TTS engines...`); diff --git a/modules/.DS_Store b/modules/.DS_Store index 99fe5ec..b27a43c 100644 Binary files a/modules/.DS_Store and b/modules/.DS_Store differ diff --git a/modules/Canttalk/index.js b/modules/Canttalk/index.js index 9ca5d95..6fd0bfa 100644 --- a/modules/Canttalk/index.js +++ b/modules/Canttalk/index.js @@ -1,3 +1,5 @@ +const printf=require('printf'); + module.exports = async (bot, api) => { bot.on('message', async (message) => { if (!message.content.startsWith(process.env.PREFIX)) { @@ -19,20 +21,20 @@ module.exports = async (bot, api) => { api.registerCommand('myvoice', async (args, message) => { let userEngine, userVoice; if (args.length > 3) { - return api.respond(message, "You tried to change your speaking voice with too many arguments."); + return api.respond(message, printf(api.strings.TOO_MANY_ARGUMENTS)); } if (api.ttsEngines[args[1]]) { userEngine = args[1]; if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) { userVoice = args[2].toLowerCase(); - api.respond(message, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName); + api.respond(message, printf(api.strings.USER_VOICE_CHANGED, userVoice, api.ttsEngines[userEngine].longName)); } else { userVoice = api.ttsEngines[userEngine].getDefaultVoice(); - api.respond(message, "Your voice name was invalid, so I switched to the default voice (" + userVoice + ") for " + api.ttsEngines[userEngine].longName + " instead."); + api.respond(message, printf(api.strings.INVALID_VOICE, api.announcementVoice, api.announcementEngine.longName)); } await api.db.run('update TTSPreferences set engine=?, voice=? where user_id=?', userEngine, userVoice, message.author.id); } else { - api.respond(message, args[1] + " is not a valid engine name"); + api.respond(message, printf(api.strings.INVALID_ENGINE, args[1])); } }); } \ No newline at end of file diff --git a/modules/announcer/index.js b/modules/announcer/index.js index 572caf1..2de4bf5 100644 --- a/modules/announcer/index.js +++ b/modules/announcer/index.js @@ -1,3 +1,4 @@ +const printf=require('printf'); const AudioQueue=require('../../AudioQueue.js') module.exports = function (bot, api) { @@ -20,9 +21,9 @@ module.exports = function (bot, api) { let username = newState.member.displayName; let str = ""; if (!joined) { - str = username + " left the channel"; + str = printf(api.strings.USER_LEFT, username); } else { - str = username + " joined the channel"; + str = printf(api.strings.USER_JOINED, username); } api.queue.add(__dirname + "/sysmsg.wav"); api.speak(channel, str); diff --git a/modules/ttsSettings/index.js b/modules/ttsSettings/index.js index 7953a89..50e0ce6 100644 --- a/modules/ttsSettings/index.js +++ b/modules/ttsSettings/index.js @@ -1,20 +1,22 @@ +const printf=require('printf'); + module.exports = function (bot, api) { api.registerCommand('announcevoice', (args, message) => { let channel = bot.voice.connections.first().channel; if (args.length > 3) { - return api.respond(message, "You tried to change my voice with too many arguments."); + return api.respond(message, printf(api.strings.TOO_MANY_ARGUMENTS)); } if (api.ttsEngines[args[1]]) { api.announcementEngine = api.ttsEngines[args[1]]; if (api.announcementEngine.validateVoice(args[2])) { api.announcementVoice = args[2]; - api.respond(message, "My new voice is " + api.announcementVoice + " from " + api.announcementEngine.longName); + api.respond(message, printf(api.strings.SYSTEM_VOICE_CHANGED, api.announcementVoice, api.announcementEngine.longName)); } else { api.announcementVoice = api.announcementEngine.getDefaultVoice(); - api.respond(message, "Your voice name was invalid, so I switched to the default voice (" + api.announcementVoice + ") for " + api.announcementEngine.longName + " instead."); + api.respond(message, printf(api.strings.INVALID_VOICE, api.announcementVoice, api.announcementEngine.longName)); } } else { - api.respond(message, args[1] + " is not a valid engine name"); + api.respond(message, printf(api.strings.INVALID_ENGINE, args[1])); } }); api.registerCommand('flush',()=>api.queue.flush()); diff --git a/modules/welcomer/index.js b/modules/welcomer/index.js index 09c398b..72f5c6c 100644 --- a/modules/welcomer/index.js +++ b/modules/welcomer/index.js @@ -8,6 +8,6 @@ module.exports = function (bot, api) { await api.joinChannel(channel); let conn=api.getConnectionForVoiceChannel(channel); api.queue=new AudioQueue(conn); - api.speak(channel, `Running`); + api.speak(channel, api.strings.WELCOME); }) } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ee7ec89..7e9a4ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "microsoft-cognitiveservices-speech-sdk": "^1.16.0", "node-fetch": "^2.6.1", "opusscript": "^0.0.8", + "printf": "^0.6.1", "sha1": "^1.1.1", "sqlite": "^4.0.21", "sqlite3": "^5.0.2" @@ -1587,6 +1588,14 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "node_modules/printf": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/printf/-/printf-0.6.1.tgz", + "integrity": "sha512-is0ctgGdPJ5951KulgfzvHGwJtZ5ck8l042vRkV6jrkpBzTmb/lueTqguWHy2JfVA+RY6gFVlaZgUS0j7S/dsw==", + "engines": { + "node": ">= 0.9.0" + } + }, "node_modules/prism-media": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz", @@ -1854,7 +1863,6 @@ "hasInstallScript": true, "dependencies": { "node-addon-api": "^3.0.0", - "node-gyp": "3.x", "node-pre-gyp": "^0.11.0" }, "optionalDependencies": { @@ -3425,6 +3433,11 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "printf": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/printf/-/printf-0.6.1.tgz", + "integrity": "sha512-is0ctgGdPJ5951KulgfzvHGwJtZ5ck8l042vRkV6jrkpBzTmb/lueTqguWHy2JfVA+RY6gFVlaZgUS0j7S/dsw==" + }, "prism-media": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.9.tgz", diff --git a/package.json b/package.json index 69425e9..9c91a32 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "microsoft-cognitiveservices-speech-sdk": "^1.16.0", "node-fetch": "^2.6.1", "opusscript": "^0.0.8", + "printf": "^0.6.1", "sha1": "^1.1.1", "sqlite": "^4.0.21", "sqlite3": "^5.0.2" diff --git a/strings/en.json b/strings/en.json new file mode 100644 index 0000000..9df8b39 --- /dev/null +++ b/strings/en.json @@ -0,0 +1,10 @@ +{ + "WELCOME": "Beep boop. I'm a bot. Hi.", + "USER_JOINED": "%s joined the channel.", + "USER_LEFT": "%s left the channel.", + "SYSTEM_VOICE_CHANGED": "My new voice is %s from %s", + "USER_VOICE_CHANGED": "Your new voice is %s from %s", + "INVALID_ENGINE": "%s is not a valid engine name.", + "INVALID_VOICE": "invalid voice name. Using default voice %s for %s instead.", + "TOO_MANY_ARGUMENTS": "too many arguments for command." +} \ No newline at end of file diff --git a/strings/es.json b/strings/es.json new file mode 100644 index 0000000..8a79d64 --- /dev/null +++ b/strings/es.json @@ -0,0 +1,10 @@ +{ + "WELCOME": "Hola hola, soy un bot.", + "USER_JOINED": "%s se ha unido al canal.", + "USER_LEFT": "%s ha salido del canal.", + "SYSTEM_VOICE_CHANGED": "Mi nueva voz es %s de %s", + "USER_VOICE_CHANGED": "Tu nueva voz es %s de %s", + "INVALID_ENGINE": "%s no es un nombre de motor válido.", + "INVALID_VOICE": "Nombre de voz no válido. Usando voz por defecto %s para %s.", + "TOO_MANY_ARGUMENTS": "Demasiados argumentos para el comando." +} \ No newline at end of file diff --git a/tts/.DS_Store b/tts/.DS_Store index 3d43c49..3755d0c 100644 Binary files a/tts/.DS_Store and b/tts/.DS_Store differ