update voice

This commit is contained in:
Luke Pulverenti 2016-02-23 12:53:04 -05:00
parent b13e561c6c
commit c6ba4e2a10
3 changed files with 59 additions and 50 deletions

View File

@ -29,7 +29,7 @@
html += '</div>';
}
html += '<paper-icon-button icon="mic" class="headerButton headerButtonRight headerVoiceButton hide" onclick="VoiceInputManager.startListening();"></paper-icon-button>';
html += '<paper-icon-button icon="mic" class="headerButton headerButtonRight headerVoiceButton hide"></paper-icon-button>';
html += '<paper-button class="headerButton headerButtonRight btnNotifications subdued" type="button" title="Notifications"><div class="btnNotificationsInner">0</div></paper-button>';
@ -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, {

View File

@ -8,56 +8,56 @@
"sourceid": "group",
"groupid": "movie",
"command": "(?<action>show|display|view)\\s?(?<source>Movie)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show Movie based commands" ]
"commandtemplates": [ "Show movie commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "music",
"command": "(?<action>show|display|view)\\s?(?<source>Music)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show Music based commands" ]
"commandtemplates": [ "Show music commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "picture",
"command": "(?<action>show|display|view)\\s?(?<source>Picture)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show Picture based commands" ]
"commandtemplates": [ "Show photo commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "tvseries",
"command": "(?<action>show|display|view)\\s?(?<source>TV series)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show TV series based commands" ]
"commandtemplates": [ "Show tv library commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "home",
"command": "(?<action>show|display|view)\\s?(?<source>home page)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show home page based commands" ]
"commandtemplates": [ "Show home screen commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "general",
"command": "(?<action>show|display|view)\\s?(?<source>general)?\\s?(?<text>group commands)",
"commandtemplates": [ "Show general group commands" ]
"commandtemplates": [ "Show general commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "devices",
"command": "(?<action>show|display|view)\\s?(?<source>devices)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show devices based commands" ]
"commandtemplates": [ "Show device commands" ]
},
{
"actionid": "show",
"sourceid": "group",
"groupid": "livetv",
"command": "(?<action>show|display|view)\\s?(?<source>live tv)?\\s?(?<text>based commands)",
"commandtemplates": [ "Show Live TV based commands" ]
"commandtemplates": [ "Show live tv commands" ]
}
]
},

View File

@ -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();
});
}
/// <summary> Shuffle array. </summary>
/// <param name="array"> The array. </param>
@ -32,12 +58,11 @@ define(['paperdialoghelper'], function (paperDialogHelper) {
/// <returns> The sample commands. </returns>
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);
});
}
/// <summary> Gets command group. </summary>
@ -82,7 +105,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) {
/// <returns> . </returns>
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 += '<div class="defaultVoiceHelp">';
html += '<h1>' + Globalize.translate('HeaderSaySomethingLike') + '</h1>';
html += '<h1 style="margin-bottom:1.25em;">' + Globalize.translate('HeaderSaySomethingLike') + '</h1>';
html += '<div class="exampleCommands">';
html += '</div>';
@ -301,31 +324,6 @@ define(['paperdialoghelper'], function (paperDialogHelper) {
}
}
/// <summary> Getgrammars the given language. </summary>
/// <param name="language"> The language. </param>
/// <returns> . </returns>
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;
}
/// <summary> Speaks the given text. </summary>
/// <param name="text"> The text. </param>
/// <returns> . </returns>
@ -353,7 +351,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) {
/// <summary> An enum constant representing the window. voice input manager option. </summary>
window.VoiceInputManager = {
return {
isSupported: function () {
@ -371,7 +369,7 @@ define(['paperdialoghelper'], function (paperDialogHelper) {
window.msSpeechRecognition;
},
startListening: startListening,
startListening: startListening
};
});