Skip to content

Commit

Permalink
Merge pull request #11 from ibmtjbot/feature/jw-speechVoice
Browse files Browse the repository at this point in the history
added configuration option to force TTS to use a specific voice
  • Loading branch information
jweisz authored Mar 27, 2017
2 parents bf6c93f + 3add1d8 commit 81e9446
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/tjbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down

0 comments on commit 81e9446

Please sign in to comment.