From 92cae1ea2e3d976976badbd1b10a92ddaf776f84 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 27 Aug 2017 21:55:49 +0200 Subject: [PATCH] Added docblocks --- UI/Input/Voice/ReadManager.js | 43 +++++++++++++++++++++++++++++++ UI/Input/Voice/VoiceManager.js | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/UI/Input/Voice/ReadManager.js b/UI/Input/Voice/ReadManager.js index b60b2da..7d844fb 100644 --- a/UI/Input/Voice/ReadManager.js +++ b/UI/Input/Voice/ReadManager.js @@ -33,6 +33,15 @@ 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) { let utter = new SpeechSynthesisUtterance(text); @@ -43,21 +52,55 @@ 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) { this.lang = lang; }; + /** + * Set pitch. + * + * @param {int} pitch Pitch + * + * @return {void} + * + * @since 1.0.0 + */ jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(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) { this.rate = rate; }; + /** + * Get supported voices. + * + * @return {array} + * + * @since 1.0.0 + */ jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function() { return this.voices; diff --git a/UI/Input/Voice/VoiceManager.js b/UI/Input/Voice/VoiceManager.js index 7d44d82..851ce5b 100644 --- a/UI/Input/Voice/VoiceManager.js +++ b/UI/Input/Voice/VoiceManager.js @@ -32,6 +32,13 @@ 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() { 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() { return '#JSGF V1.0; grammar phrase; public = ' + 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) { // todo: eventually restart 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) { this.commands[command] = callback; }; + /** + * Start voice listener. + * + * @return {void} + * + * @since 1.0.0 + */ jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function() { this.recognition.start(); }; + /** + * Stop voice listener. + * + * @return {void} + * + * @since 1.0.0 + */ jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function() { this.recognition.stop();