jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/voice/voiceprocessor.js

60 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-07-06 12:25:58 -07:00
define(['./voicecommands.js', './grammarprocessor.js', 'require'], function (voicecommands, grammarprocessor, require) {
2016-10-17 22:06:48 -07:00
'use strict';
2016-07-06 11:39:04 -07:00
var commandgroups;
function getCommandGroups() {
if (commandgroups) {
return Promise.resolve(commandgroups);
}
return new Promise(function (resolve, reject) {
var file = "grammar";
2016-07-06 12:25:58 -07:00
require(['text!./grammar/' + file + '.json'], function (response) {
commandgroups = JSON.parse(response);
2016-07-06 11:39:04 -07:00
resolve(commandgroups);
2016-07-06 12:25:58 -07:00
});
2016-07-06 11:39:04 -07:00
});
}
/// <summary> Process the transcript described by text. </summary>
/// <param name="text"> The text. </param>
/// <returns> . </returns>
function processTranscript(text) {
if (text) {
2016-07-20 06:56:24 -07:00
return getCommandGroups().then(function (commandgroups) {
var processor = grammarprocessor(commandgroups, text);
if (processor && processor.command) {
console.log("Command from Grammar Processor", processor);
return voicecommands(processor)
.then(function (result) {
console.log("Result of executed command", result);
if (result.item.actionid === 'show' && result.item.sourceid === 'group') {
return Promise.resolve({ error: "group", item: result.item, groupName: result.name, fn: result.fn });
} else {
return Promise.resolve({ item: result.item, fn: result.fn });
}
}, function () {
return Promise.reject({ error: "unrecognized-command", text: text });
});
} else {
return Promise.reject({ error: "unrecognized-command", text: text });
}
});
2016-07-06 11:39:04 -07:00
} else {
return Promise.reject({ error: "empty" });
}
}
/// <summary> An enum constant representing the window. voice input manager option. </summary>
return {
processTranscript: processTranscript,
getCommandGroups: getCommandGroups
};
});