Skip to content

Commit

Permalink
Ensure voices are loaded before use
Browse files Browse the repository at this point in the history
to close #292
  • Loading branch information
Dave Conway-Jones committed Oct 6, 2017
1 parent 2ba847f commit 18bcbc8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
4 changes: 2 additions & 2 deletions dist/css/app.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dashboard.appcache
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ font-awesome/fonts/fontawesome-webfont.woff2
NETWORK:
*

# hash: 8a3c68c3adc0ad0e57c02a6622fbe39dc0db291f730490315b3337f50fd8ff6e
# hash: ed8130948f27380aef44571750ff590fbbc7e55fa62c9fb1bcf20d8e10621d1e
28 changes: 14 additions & 14 deletions dist/js/app.min.js

Large diffs are not rendered by default.

49 changes: 36 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
this.allowSwipe = false;
var main = this;
var audiocontext;
var voices = [];
var tabId = 0;

function moveTab(d) {
Expand Down Expand Up @@ -245,18 +246,23 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
$('meta[name=apple-mobile-web-app-title]').attr('content', name || "Node-RED");

var prevTabIndex = parseInt($location.path().substr(1));
if ('speechSynthesis' in window) {
window.speechSynthesis.onvoiceschanged = function() {
voices = window.speechSynthesis.getVoices();
}
}
var finishLoading = function() {
if (main.selectedTab && typeof(main.selectedTab.theme) === 'object') {
main.selectedTab.theme.themeState["widget-borderColor"] = main.selectedTab.theme.themeState["widget-borderColor"] || main.selectedTab.theme.themeState["group-backgroundColor"];
applyStyle(main.selectedTab.theme);
$mdToast.hide();
}
else if (typeof(ui.theme) === 'object' && ui.theme.themeState['base-color'].value) {
applyStyle(ui.theme);
}
if ((main.selectedTab !== null) && (main.selectedTab.link !== undefined)) {
main.selectedTab.link = $sce.trustAsResourceUrl(main.selectedTab.link);
}
$mdToast.hide();
processGlobals();
done();
}
Expand Down Expand Up @@ -386,20 +392,33 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
);
}
else {
var toastScope = $rootScope.$new();
toastScope.toast = msg;
var opts = {
scope: toastScope,
templateUrl: 'partials/toast.html',
hideDelay: msg.displayTime,
position: msg.position
};
$mdToast.show(opts);
if (msg.hasOwnProperty("message") || msg.hasOwnProperty("title")) {
var toastScope = $rootScope.$new();
toastScope.toast = msg;
var opts = {
scope: toastScope,
templateUrl: 'partials/toast.html',
hideDelay: msg.displayTime,
position: msg.position
};
$mdToast.show(opts);
}
}
});

events.on('ui-control', function(msg) {
if (msg.hasOwnProperty("socketid") && (msg.socketid !== events.id) ) { return; }
if (msg.hasOwnProperty("control")) {
//console.log("MSG",msg);
found = findControl(msg.id, main.menu);
//console.log("FOUND",found);
for (var property in msg.control) {
if (msg.control.hasOwnProperty(property) && found.hasOwnProperty(property)) {
found[property] = msg.control[property];
}
}
//Object.assign(found,msg.control);
}
if (msg.hasOwnProperty("tab")) { // if it's a request to change tabs
if (typeof msg.tab === 'string') {
if (msg.tab === "") { events.emit('ui-refresh', {}); }
Expand Down Expand Up @@ -435,13 +454,17 @@ app.controller('MainController', ['$mdSidenav', '$window', 'UiEvents', '$locatio
if (totab != parseInt($location.path().substr(1))) { return; }
}
if (msg.hasOwnProperty("tts")) {
if ('speechSynthesis' in window) {
var voices = window.speechSynthesis.getVoices();
if (voices.length > 0) {
var words = new SpeechSynthesisUtterance(msg.tts);
words.voice = voices[msg.voice];
window.speechSynthesis.speak(words);
}
else { console.log("Your Browser does not support Text-to-Speech"); }
else {
console.log("Your Browser does not support Text-to-Speech");
var toastScope = $rootScope.$new();
toastScope.toast = {message:msg.tts, title:"Computer says..."};
$mdToast.show({ scope:toastScope, position:'top right', templateUrl:'partials/toast.html' });
}
}
if (msg.hasOwnProperty("audio")) {
if (!window.hasOwnProperty("AudioContext")) {
Expand Down

0 comments on commit 18bcbc8

Please sign in to comment.