mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update voice
This commit is contained in:
parent
6e90fe1460
commit
aece94029c
13 changed files with 300 additions and 249 deletions
65
dashboard-ui/voice/voiceprocessor.js
Normal file
65
dashboard-ui/voice/voiceprocessor.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
define(['voice/voicecommands.js', 'voice/grammarprocessor.js'], function (voicecommands, grammarprocessor) {
|
||||
|
||||
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> Process the transcript described by text. </summary>
|
||||
/// <param name="text"> The text. </param>
|
||||
/// <returns> . </returns>
|
||||
function processTranscript(text) {
|
||||
if (text) {
|
||||
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.reject({ error: "group", item: result.item, groupName: result.name });
|
||||
} else {
|
||||
return Promise.resolve({ item: result.item });
|
||||
}
|
||||
}, function () {
|
||||
return Promise.reject({ error: "unrecognized-command", text: text });
|
||||
});
|
||||
} else {
|
||||
return Promise.reject({ error: "unrecognized-command", text: text });
|
||||
}
|
||||
|
||||
} else {
|
||||
return Promise.reject({ error: "empty" });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> An enum constant representing the window. voice input manager option. </summary>
|
||||
return {
|
||||
processTranscript: processTranscript,
|
||||
getCommandGroups: getCommandGroups
|
||||
};
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue