1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update voice

This commit is contained in:
Luke Pulverenti 2016-07-20 09:56:24 -04:00
parent 9ff21cf7b8
commit 79240b1a24
8 changed files with 90 additions and 125 deletions

View file

@ -1,10 +1,15 @@
define([], function () {
var currentRecognition = null;
define(['events'], function (events) {
var receiver = {
};
var currentRecognition = null;
/// <summary> Starts listening for voice commands </summary>
/// <returns> . </returns>
function listenForCommand(lang) {
function listen(options) {
return new Promise(function (resolve, reject) {
cancelListener();
@ -13,13 +18,28 @@
window.mozSpeechRecognition ||
window.oSpeechRecognition ||
window.msSpeechRecognition)();
recognition.lang = lang;
recognition.lang = options.lang;
recognition.continuous = options.continuous || false;
var resultCount = 0;
recognition.onresult = function (event) {
console.log(event);
if (event.results.length > 0) {
var resultInput = event.results[0][0].transcript || '';
resolve(resultInput);
var resultInput = event.results[resultCount][0].transcript || '';
resultCount++;
if (options.continuous) {
events.trigger(receiver, 'input', [
{
text: resultInput
}
]);
} else {
resolve(resultInput);
}
}
};
@ -36,7 +56,6 @@
});
}
/// <summary> Cancel listener. </summary>
/// <returns> . </returns>
function cancelListener() {
@ -48,10 +67,9 @@
}
/// <summary> An enum constant representing the window. voice input manager option. </summary>
return {
listenForCommand: listenForCommand,
cancel: cancelListener
};
receiver.listen = listen;
receiver.cancel = cancelListener;
/// <summary> An enum constant representing the window. voice input manager option. </summary>
return receiver;
});