diff --git a/dashboard-ui/scripts/librarymenu.js b/dashboard-ui/scripts/librarymenu.js index 82d98a07a5..3e4eb22017 100644 --- a/dashboard-ui/scripts/librarymenu.js +++ b/dashboard-ui/scripts/librarymenu.js @@ -29,7 +29,7 @@ html += ''; } - html += ''; + html += ''; html += '
0
'; @@ -136,9 +136,9 @@ } } - requirejs(['voice/voice'], function () { + require(['voice/voice'], function (voice) { - if (VoiceInputManager.isSupported()) { + if (voice.isSupported()) { header.querySelector('.headerVoiceButton').classList.remove('hide'); } else { header.querySelector('.headerVoiceButton').classList.add('hide'); @@ -159,6 +159,12 @@ } } + function showVoice() { + require(['voice/voice'], function (voice) { + voice.startListening(); + }); + } + function bindMenuEvents() { var mainDrawerButton = document.querySelector('.mainDrawerButton'); @@ -172,6 +178,11 @@ headerBackButton.addEventListener('click', onBackClick); } + var headerVoiceButton = document.querySelector('.headerVoiceButton'); + if (headerVoiceButton) { + headerVoiceButton.addEventListener('click', showVoice); + } + var viewMenuBar = document.querySelector(".viewMenuBar"); initHeadRoom(viewMenuBar); @@ -904,7 +915,7 @@ return; } - requirejs(["headroom"], function () { + require(["headroom"], function () { // construct an instance of Headroom, passing the element var headroom = new Headroom(elem, { diff --git a/dashboard-ui/voice/grammar/grammar.json b/dashboard-ui/voice/grammar/grammar.json index 7c3e4f07e9..cc97e515ad 100644 --- a/dashboard-ui/voice/grammar/grammar.json +++ b/dashboard-ui/voice/grammar/grammar.json @@ -8,56 +8,56 @@ "sourceid": "group", "groupid": "movie", "command": "(?show|display|view)\\s?(?Movie)?\\s?(?based commands)", - "commandtemplates": [ "Show Movie based commands" ] + "commandtemplates": [ "Show movie commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "music", "command": "(?show|display|view)\\s?(?Music)?\\s?(?based commands)", - "commandtemplates": [ "Show Music based commands" ] + "commandtemplates": [ "Show music commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "picture", "command": "(?show|display|view)\\s?(?Picture)?\\s?(?based commands)", - "commandtemplates": [ "Show Picture based commands" ] + "commandtemplates": [ "Show photo commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "tvseries", "command": "(?show|display|view)\\s?(?TV series)?\\s?(?based commands)", - "commandtemplates": [ "Show TV series based commands" ] + "commandtemplates": [ "Show tv library commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "home", "command": "(?show|display|view)\\s?(?home page)?\\s?(?based commands)", - "commandtemplates": [ "Show home page based commands" ] + "commandtemplates": [ "Show home screen commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "general", "command": "(?show|display|view)\\s?(?general)?\\s?(?group commands)", - "commandtemplates": [ "Show general group commands" ] + "commandtemplates": [ "Show general commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "devices", "command": "(?show|display|view)\\s?(?devices)?\\s?(?based commands)", - "commandtemplates": [ "Show devices based commands" ] + "commandtemplates": [ "Show device commands" ] }, { "actionid": "show", "sourceid": "group", "groupid": "livetv", "command": "(?show|display|view)\\s?(?live tv)?\\s?(?based commands)", - "commandtemplates": [ "Show Live TV based commands" ] + "commandtemplates": [ "Show live tv commands" ] } ] }, diff --git a/dashboard-ui/voice/voice.js b/dashboard-ui/voice/voice.js index ac8b7b5f71..1094ed77a6 100644 --- a/dashboard-ui/voice/voice.js +++ b/dashboard-ui/voice/voice.js @@ -1,10 +1,36 @@ define(['paperdialoghelper'], function (paperDialogHelper) { var currentRecognition; - var lang = 'grammar'; - //var lang = 'en-US'; + var lang = 'en-US'; - var commandgroups = getGrammarCommands(lang); + var commandgroups; + + function getCommandGroups() { + + if (commandgroups) { + return Promise.resolve(commandgroups); + } + + return new Promise(function (resolve, reject) { + + var file = "grammar"; + //if (language && language.length > 0) + // file = language; + + var xhr = new XMLHttpRequest(); + xhr.open('GET', "voice/grammar/" + file + ".json", true); + + xhr.onload = function (e) { + + commandgroups = JSON.parse(this.response); + resolve(commandgroups); + } + + xhr.onerror = reject; + + xhr.send(); + }); + } /// Shuffle array. /// The array. @@ -32,12 +58,11 @@ define(['paperdialoghelper'], function (paperDialogHelper) { /// The sample commands. function getSampleCommands(groupid) { - return new Promise(function (resolve, reject) { - + return getCommandGroups().then(function (commandGroups) { groupid = typeof (groupid) !== 'undefined' ? groupid : ''; var commands = []; - commandgroups.map(function (group) { + commandGroups.map(function (group) { if ((group.items && group.items.length > 0) && (groupid == group.groupid || groupid == '')) { group.items.map(function (item) { @@ -53,10 +78,8 @@ define(['paperdialoghelper'], function (paperDialogHelper) { } }); - resolve(shuffleArray(commands)); - + return shuffleArray(commands); }); - } /// Gets command group. @@ -82,7 +105,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) { /// . function renderSampleCommands(elem, commands) { - commands.length = Math.min(commands.length, 6); + commands.length = Math.min(commands.length, 4); commands = commands.map(function (c) { @@ -124,7 +147,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) { html += '
'; - html += '

' + Globalize.translate('HeaderSaySomethingLike') + '

'; + html += '

' + Globalize.translate('HeaderSaySomethingLike') + '

'; html += '
'; html += '
'; @@ -301,31 +324,6 @@ define(['paperdialoghelper'], function (paperDialogHelper) { } } - /// Getgrammars the given language. - /// The language. - /// . - function getGrammarCommands(language) { - - var file = "grammar"; - if (language && language.length > 0) - file = language; - - var grammar = (function () { - var grm = null; - $.ajax({ - async: false, - global: false, - url: "voice/grammar/" + file + ".json", - dataType: "json", - success: function (data) { - grm = data; - } - }); - return grm; - })(); - return grammar; - } - /// Speaks the given text. /// The text. /// . @@ -353,7 +351,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) { /// An enum constant representing the window. voice input manager option. - window.VoiceInputManager = { + return { isSupported: function () { @@ -371,7 +369,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) { window.msSpeechRecognition; }, - startListening: startListening, + startListening: startListening }; }); \ No newline at end of file