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
57
dashboard-ui/voice/voicereceiver.js
Normal file
57
dashboard-ui/voice/voicereceiver.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
define([], function () {
|
||||
var currentRecognition = null;
|
||||
|
||||
|
||||
/// <summary> Starts listening for voice commands </summary>
|
||||
/// <returns> . </returns>
|
||||
function listenForCommand(lang) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
cancelListener();
|
||||
|
||||
var recognition = new (window.SpeechRecognition ||
|
||||
window.webkitSpeechRecognition ||
|
||||
window.mozSpeechRecognition ||
|
||||
window.oSpeechRecognition ||
|
||||
window.msSpeechRecognition)();
|
||||
recognition.lang = lang;
|
||||
|
||||
recognition.onresult = function (event) {
|
||||
console.log(event);
|
||||
if (event.results.length > 0) {
|
||||
var resultInput = event.results[0][0].transcript || '';
|
||||
resolve(resultInput);
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onerror = function () {
|
||||
reject({ error: event.error, message: event.message });
|
||||
};
|
||||
|
||||
recognition.onnomatch = function () {
|
||||
reject({ error: "no-match" });
|
||||
};
|
||||
currentRecognition = recognition;
|
||||
|
||||
currentRecognition.start();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Cancel listener. </summary>
|
||||
/// <returns> . </returns>
|
||||
function cancelListener() {
|
||||
|
||||
if (currentRecognition) {
|
||||
currentRecognition.abort();
|
||||
currentRecognition = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary> An enum constant representing the window. voice input manager option. </summary>
|
||||
return {
|
||||
listenForCommand: listenForCommand,
|
||||
cancel: cancelListener
|
||||
};
|
||||
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue