Added docblocks

This commit is contained in:
Dennis Eichhorn 2017-08-27 21:55:49 +02:00
parent ee6685cfa6
commit 92cae1ea2e
2 changed files with 90 additions and 0 deletions

View File

@ -33,6 +33,15 @@
this.voice = this.voices[0]; this.voice = this.voices[0];
}; };
/**
* Read text.
*
* @param {string} text Text to read
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.ReadManager.prototype.read = function(text) jsOMS.UI.Input.Voice.ReadManager.prototype.read = function(text)
{ {
let utter = new SpeechSynthesisUtterance(text); let utter = new SpeechSynthesisUtterance(text);
@ -43,21 +52,55 @@
window.speechSynthesis.speak(utter); window.speechSynthesis.speak(utter);
}; };
/**
* Set Language.
*
* @param {string} lang Language id (e.g. en-US)
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.ReadManager.prototype.setLanguage = function(lang) jsOMS.UI.Input.Voice.ReadManager.prototype.setLanguage = function(lang)
{ {
this.lang = lang; this.lang = lang;
}; };
/**
* Set pitch.
*
* @param {int} pitch Pitch
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(pitch) jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(pitch)
{ {
this.pitch = pitch; this.pitch = pitch;
}; };
/**
* Set rate.
*
* @param {int} rate Rate
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.ReadManager.prototype.setRate = function(rate) jsOMS.UI.Input.Voice.ReadManager.prototype.setRate = function(rate)
{ {
this.rate = rate; this.rate = rate;
}; };
/**
* Get supported voices.
*
* @return {array}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function() jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function()
{ {
return this.voices; return this.voices;

View File

@ -32,6 +32,13 @@
this.lang = typeof lang === 'undefined' ? 'en-US' : lang; this.lang = typeof lang === 'undefined' ? 'en-US' : lang;
}; };
/**
* Setup or re-initialize voice manager.
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.setup = function() jsOMS.UI.Input.Voice.VoiceManager.prototype.setup = function()
{ {
const self = this; const self = this;
@ -69,27 +76,67 @@
} }
}; };
/**
* Create commands/grammar string from commands
*
* @return {string}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.getCommandsString = function() jsOMS.UI.Input.Voice.VoiceManager.prototype.getCommandsString = function()
{ {
return '#JSGF V1.0; grammar phrase; public <phrase> = ' + Object.keys(this.commands).join(' | ') + ' ;'; return '#JSGF V1.0; grammar phrase; public <phrase> = ' + Object.keys(this.commands).join(' | ') + ' ;';
}; };
/**
* Set language
*
* @param {string} lang Language code (e.g. en-US)
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.setLanguage = function(lang) jsOMS.UI.Input.Voice.VoiceManager.prototype.setLanguage = function(lang)
{ {
// todo: eventually restart // todo: eventually restart
this.recognition.lang = lang; this.recognition.lang = lang;
}; };
/**
* Add command/grammar and callback.
*
* @param {string} command Command id
* @param {Callback} callback Callback for command
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.add = function(command, callback) jsOMS.UI.Input.Voice.VoiceManager.prototype.add = function(command, callback)
{ {
this.commands[command] = callback; this.commands[command] = callback;
}; };
/**
* Start voice listener.
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function() jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function()
{ {
this.recognition.start(); this.recognition.start();
}; };
/**
* Stop voice listener.
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function() jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function()
{ {
this.recognition.stop(); this.recognition.stop();