Skip to content

Commit

Permalink
Merge pull request #76 from nullabork/betabot
Browse files Browse the repository at this point in the history
Betabot
  • Loading branch information
wootosmash committed Nov 7, 2019
2 parents 99b27f9 + 90f4034 commit eef2750
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/models/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,20 +236,27 @@ class Server {
.join()
.then(connection => {
// success

// when closing stop the voices and clear the neglect timeout
connection.on('closing', () => {
server.leaving = true;
server.stop('voiceClosing'); // stop playing
clearTimeout(server.neglect_timeout);
});

// when disconnect clear the master - note that d/c may happen without a closing event
connection.on('disconnect', () => {
server.stop('disconnect'); // stop playing
server.bound_to = null;
server.permitted = {};
server.leaving = false;
});

// if an error occurs treat it like a d/c but capture the error
// reset the state to as if there was no connection
connection.on('error', error => {
server.bound_to = null;
server.permitted = {};
server.leaving = false;
server.connecting = false; // this might cause a race condition
Common.error(error);
Expand All @@ -260,8 +267,13 @@ class Server {
server.save();
server.world.setPresence();
commands.notify('joinVoice', {server: server});

}, error => {

// on an error treat it like a error on the connection
server.stop('joinError');
server.bound_to = null;
server.permitted = {};
server.connecting = false;
Common.error(error);
});
Expand Down Expand Up @@ -408,7 +420,7 @@ class Server {
language: options.language == 'default' ? 'en-AU' : options.language || server.language
}

if (options.name != 'default') settings.name = options.name;
if (options.name != 'default') settings.name = options.name;
if (options.pitch != 'default') settings.pitch = options.pitch;
if (options.speed != 'default') settings.speed = options.speed;
if (options.voice_provider) settings.voice_provider = options.voice_provider;
Expand Down
6 changes: 5 additions & 1 deletion src/services/tts/AmazonTextToSpeechAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class AmazonTextToSpeechAPI extends TextToSpeechService {
msg = ssmlvalid.correct(msg);
if ( !settings['amazon-breaths-disabled'] )
msg = '<amazon:auto-breaths>' + msg + '</amazon:auto-breaths>';

var ssml = new MessageSSML(msg, { server: server }).build();
var self = this;
let options = {
Expand Down Expand Up @@ -154,6 +154,10 @@ class AmazonTextToSpeechAPI extends TextToSpeechService {
getDefaultVoice(gender, lang_code) {
var voices = AmazonTextToSpeechAPI.voices.filter(voice => voice.code == lang_code && voice.gender == gender);
if ( voices.length > 0 ) return voices[0].voice;
var voices = AmazonTextToSpeechAPI.voices.filter(voice => voice.code == lang_code);
if ( voices.length > 0 ) return voices[0].voice;
var voices = AmazonTextToSpeechAPI.voices.filter(voice => voice.code == 'en-US' && voice.gender == gender);
if ( voices.length > 0 ) return voices[0].voice;
return 'Kimberly';
}

Expand Down

0 comments on commit eef2750

Please sign in to comment.