diff --git a/lib/tjbot.js b/lib/tjbot.js index a0c97dd..ffe6b76 100644 --- a/lib/tjbot.js +++ b/lib/tjbot.js @@ -154,7 +154,8 @@ TJBot.prototype.defaultConfiguration = { servoPin: 7 // corresponds to BCM 7 / physical PIN 26 }, speak: { - language: 'en-US' // see TJBot.prototype.languages.speak + language: 'en-US', // see TJBot.prototype.languages.speak + voice: undefined // use a specific voice; if undefined, a voice is chosen based on robot.gender and speak.language }, see: { confidenceThreshold: { @@ -1067,13 +1068,22 @@ TJBot.prototype.speak = function(message) { throw new Error("TJBot tried to speak an empty message."); } - // figure out which voice to use - var voice = "en-US_MichaelVoice"; // default voice - for (var i in this._ttsVoices) { - if (this._ttsVoices[i]["language"] == this.configuration.speak.language && - this._ttsVoices[i]["gender"] == this.configuration.robot.gender) { - voice = this._ttsVoices[i]["name"]; - break; + // default voice + var voice = "en-US_MichaelVoice"; + + // check to see if the user has specified a voice + if (this.configuration.speak.voice != undefined) { + voice = this.configuration.speak.voice; + } else { + // choose a voice based on robot.gender and speak.language + // do this each time just in case the user changes robot.gender or + // speak.language during execution + for (var i in this._ttsVoices) { + if (this._ttsVoices[i]["language"] == this.configuration.speak.language && + this._ttsVoices[i]["gender"] == this.configuration.robot.gender) { + voice = this._ttsVoices[i]["name"]; + break; + } } }