mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-29 01:38:41 +00:00
Prepare for voice actions
This commit is contained in:
parent
e96dc4d8b7
commit
407067d6de
|
|
@ -18,10 +18,11 @@
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
jsOMS.UI.Input.InputManager = function ()
|
||||
jsOMS.UI.Input.InputManager = function (app)
|
||||
{
|
||||
this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager();
|
||||
this.keyboardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager();
|
||||
this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager();
|
||||
this.voiceManager = new jsOMS.UI.Input.Voice.VoiceManager(app);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -33,7 +34,7 @@
|
|||
*/
|
||||
jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function ()
|
||||
{
|
||||
return this.keyBoardManager;
|
||||
return this.keyboardManager;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -47,4 +48,16 @@
|
|||
{
|
||||
return this.mouseManager;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get voice manager.
|
||||
*
|
||||
* @return {Object}
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
jsOMS.UI.Input.InputManager.prototype.getVoiceManager = function ()
|
||||
{
|
||||
return this.voiceManager;
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
|
|
|
|||
63
UI/Input/Voice/ReadManager.js
Normal file
63
UI/Input/Voice/ReadManager.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* Form manager class.
|
||||
*
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
|
||||
/** @namespace jsOMS.UI */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Voice');
|
||||
|
||||
// todo: remove once obsolete
|
||||
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
|
||||
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
|
||||
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
jsOMS.UI.Input.Voice.ReadManager = function ()
|
||||
{
|
||||
this.pitch = 1;
|
||||
this.rate = 1;
|
||||
this.voice = 'en-US';
|
||||
|
||||
this.voices = window.speechSynthesis.getVoices();
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.ReadManager.prototype.read = function(text)
|
||||
{
|
||||
let utter = new SpeechSynthesisUtterance(text);
|
||||
utter.voice = this.voice;
|
||||
utter.pitch = this.pitch;
|
||||
utter.rate = this.rate;
|
||||
window.speechSynthesis.speak(utter);
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.ReadManager.prototype.setLanguage = function(lang)
|
||||
{
|
||||
this.lang = lang;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(pitch)
|
||||
{
|
||||
this.pitch = pitch;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.ReadManager.prototype.setRate = function(rate)
|
||||
{
|
||||
this.rate = rate;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function()
|
||||
{
|
||||
return this.voices;
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
0
UI/Input/Voice/SpeechManager.js
Normal file
0
UI/Input/Voice/SpeechManager.js
Normal file
89
UI/Input/Voice/VoiceManager.js
Normal file
89
UI/Input/Voice/VoiceManager.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Form manager class.
|
||||
*
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
|
||||
/** @namespace jsOMS.UI */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Voice');
|
||||
|
||||
// todo: remove once obsolete
|
||||
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
|
||||
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList
|
||||
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
jsOMS.UI.Input.Voice.VoiceManager = function (app, commands, lang)
|
||||
{
|
||||
this.app = app;
|
||||
this.recognition = new SpeechRecognition();
|
||||
this.speechRecognitionList = new SpeechGrammarList();
|
||||
this.commands = commands;
|
||||
this.lang = typeof lang === 'undefined' ? 'en-US' : lang;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.VoiceManager.prototype.setup = function()
|
||||
{
|
||||
let self = this;
|
||||
|
||||
this.recognition.lang = this.lang;
|
||||
this.recognition.interimResults = false;
|
||||
this.recognition.maxAlternatives = 1;
|
||||
|
||||
if(typeof this.commands !== 'undefined') {
|
||||
this.speechRecognitionList.addFromString(this.commands, 1);
|
||||
recognition.grammars = this.speechRecognitionList;
|
||||
}
|
||||
|
||||
this.recognition.onresult = function(event) {
|
||||
|
||||
|
||||
console.log(event.results[0][0].transcript);
|
||||
}
|
||||
|
||||
this.recognition.onspeechend = function() {
|
||||
self.recognition.stop();
|
||||
}
|
||||
|
||||
this.recognition.onnomatch = function(event) {
|
||||
console.log('Couldn\'t recognize speech');
|
||||
}
|
||||
|
||||
this.recognition.onerror = function(event) {
|
||||
console.log('Error during speech recognition: ' + event.error);
|
||||
}
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.VoiceManager.prototype.setLanguage = function(lang)
|
||||
{
|
||||
// todo: eventually restart
|
||||
this.recognition.lang = lang;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.VoiceManager.prototype.setCommands = function(commands)
|
||||
{
|
||||
// todo: eventually restart
|
||||
this.speechRecognitionList.addFromString(commands, 1);
|
||||
recognition.grammars = this.speechRecognitionList;
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function()
|
||||
{
|
||||
this.recognition.start();
|
||||
};
|
||||
|
||||
jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function()
|
||||
{
|
||||
this.recognition.stop();
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
Loading…
Reference in New Issue
Block a user