From f9c564cf68ebfee675da00743a1a52c17d701096 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Wed, 29 Jun 2016 21:00:24 -0700 Subject: [PATCH 1/5] API interface for simulating pressing button --- IodineGBA/core/Emulator.js | 7 +++++++ IodineGBA/core/Worker.js | 2 ++ index.html | 1 + user_scripts/Interface.js | 16 ++++++++++++++++ user_scripts/JoyPadGlueCode.js | 1 + 5 files changed, 27 insertions(+) create mode 100644 user_scripts/Interface.js diff --git a/IodineGBA/core/Emulator.js b/IodineGBA/core/Emulator.js index b230174..fd9ec7c 100644 --- a/IodineGBA/core/Emulator.js +++ b/IodineGBA/core/Emulator.js @@ -329,12 +329,19 @@ GameBoyAdvanceEmulator.prototype.initializeCore = function () { return allowInit | 0; } GameBoyAdvanceEmulator.prototype.keyDown = function (keyPressed) { + console.log("keydown emulator"); + console.log(keyPressed); + keyPressed = keyPressed | 0; if ((this.emulatorStatus | 0) < 0x10 && (keyPressed | 0) >= 0 && (keyPressed | 0) <= 9) { this.IOCore.joypad.keyPress(keyPressed | 0); } } GameBoyAdvanceEmulator.prototype.keyUp = function (keyReleased) { + console.log("keyup emulator"); + console.log(keyReleased); + + keyReleased = keyReleased | 0; if ((this.emulatorStatus | 0) < 0x10 && (keyReleased | 0) >= 0 && (keyReleased | 0) <= 9) { this.IOCore.joypad.keyRelease(keyReleased | 0); diff --git a/IodineGBA/core/Worker.js b/IodineGBA/core/Worker.js index 1a96fde..f88ca0b 100644 --- a/IodineGBA/core/Worker.js +++ b/IodineGBA/core/Worker.js @@ -112,9 +112,11 @@ self.onmessage = function (event) { break; case 11: Iodine.keyDown(data.payload | 0); + console.log("keydown"); break; case 12: Iodine.keyUp(data.payload | 0); + console.log("keyUp"); break; case 13: Iodine.incrementSpeed(+data.payload); diff --git a/index.html b/index.html index 586ccc4..1512cfd 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,7 @@ + diff --git a/user_scripts/Interface.js b/user_scripts/Interface.js new file mode 100644 index 0000000..66017d7 --- /dev/null +++ b/user_scripts/Interface.js @@ -0,0 +1,16 @@ +var mapButtontoIndex = {"A":0, "B":1, "Select":2, "Start":3, "Right":4, "Left": 5, "Up":6 ,"Down":7, "R":8, "L":9} + +function pressButton(button, time) { + + if(button in mapButtontoIndex ){ + + index = mapButtontoIndex[button] + IodineGUI.Iodine.keyDown(index); + + setTimeout(function() { + IodineGUI.Iodine.keyUp(index); + }, time); + } + + return; +} \ No newline at end of file diff --git a/user_scripts/JoyPadGlueCode.js b/user_scripts/JoyPadGlueCode.js index 98f1444..5bacfb8 100644 --- a/user_scripts/JoyPadGlueCode.js +++ b/user_scripts/JoyPadGlueCode.js @@ -9,6 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ function keyDown(e) { + var keyCode = e.keyCode | 0; for (var keyMapIndex = 0; (keyMapIndex | 0) < 10; keyMapIndex = ((keyMapIndex | 0) + 1) | 0) { if ((IodineGUI.defaults.keyZonesGBA[keyMapIndex | 0] | 0) == (keyCode | 0)) { From 0ca17cd800647438f6bcb5703e2872c54aebcb9b Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Mon, 4 Jul 2016 02:20:46 -0700 Subject: [PATCH 2/5] add voice interface file --- index.html | 2 + user_scripts/Interface.js | 4 +- user_scripts/VoiceController.js | 32 ++ user_scripts/annyang.min.js | 694 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 730 insertions(+), 2 deletions(-) create mode 100644 user_scripts/VoiceController.js create mode 100644 user_scripts/annyang.min.js diff --git a/index.html b/index.html index 1512cfd..ce33b72 100644 --- a/index.html +++ b/index.html @@ -64,6 +64,8 @@ + + diff --git a/user_scripts/Interface.js b/user_scripts/Interface.js index 66017d7..499947b 100644 --- a/user_scripts/Interface.js +++ b/user_scripts/Interface.js @@ -1,9 +1,9 @@ -var mapButtontoIndex = {"A":0, "B":1, "Select":2, "Start":3, "Right":4, "Left": 5, "Up":6 ,"Down":7, "R":8, "L":9} +var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": 5, "up":6 ,"down":7, "r":8, "l":9} function pressButton(button, time) { if(button in mapButtontoIndex ){ - + index = mapButtontoIndex[button] IodineGUI.Iodine.keyDown(index); diff --git a/user_scripts/VoiceController.js b/user_scripts/VoiceController.js new file mode 100644 index 0000000..1f81166 --- /dev/null +++ b/user_scripts/VoiceController.js @@ -0,0 +1,32 @@ +if(annyang){ + + pressKeyFunctionConstructor = function(key){ + key = key.toLowerCase() + var func = function(){ + pressButton(key,20); + }; + return func; + } + + handleButton = function(key){ + //lower case the key to ignore capitals + key = key.toLowerCase(); + pressButton(key, 20); + } + + var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": 5, "up":6 ,"down":7, "r":8, "l":9}; + + var commands = {}; + + for (var key in mapButtontoIndex){ + commands[key] = pressKeyFunctionConstructor(key); + } + commands["press (the) button *key"] = handleButton; + commands["press (the) key *key"] = handleButton; + + + + // Add our commands to annyang + annyang.addCommands(commands); + annyang.start(); +} \ No newline at end of file diff --git a/user_scripts/annyang.min.js b/user_scripts/annyang.min.js new file mode 100644 index 0000000..59f2050 --- /dev/null +++ b/user_scripts/annyang.min.js @@ -0,0 +1,694 @@ +//! annyang +//! version : 2.4.0 +//! author : Tal Ater @TalAter +//! license : MIT +//! https://www.TalAter.com/annyang/ +(function (root, factory) { + "use strict"; + if (typeof define === 'function' && define.amd) { // AMD + global + define([], function () { + return (root.annyang = factory(root)); + }); + } else if (typeof module === 'object' && module.exports) { // CommonJS + module.exports = factory(root); + } else { // Browser globals + root.annyang = factory(root); + } +}(typeof window !== 'undefined' ? window : this, function (root, undefined) { + "use strict"; + + /** + * # Quick Tutorial, Intro and Demos + * + * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). + * + * For a more in-depth look at annyang, read on. + * + * # API Reference + */ + + var annyang; + + // Get the SpeechRecognition object, while handling browser prefixes + var SpeechRecognition = root.SpeechRecognition || + root.webkitSpeechRecognition || + root.mozSpeechRecognition || + root.msSpeechRecognition || + root.oSpeechRecognition; + + console.log(SpeechRecognition); + + // Check browser support + // This is done as early as possible, to make it as fast as possible for unsupported browsers + if (!SpeechRecognition) { + return null; + } + + var commandsList = []; + var recognition; + var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] }; + var autoRestart; + var lastStartedAt = 0; + var autoRestartCount = 0; + var debugState = false; + var debugStyle = 'font-weight: bold; color: #00f;'; + var pauseListening = false; + var isListening = false; + + // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license. + var optionalParam = /\s*\((.*?)\)\s*/g; + var optionalRegex = /(\(\?:[^)]+\))\?/g; + var namedParam = /(\(\?)?:\w+/g; + var splatParam = /\*\w+/g; + var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#]/g; + var commandToRegExp = function(command) { + command = command.replace(escapeRegExp, '\\$&') + .replace(optionalParam, '(?:$1)?') + .replace(namedParam, function(match, optional) { + return optional ? match : '([^\\s]+)'; + }) + .replace(splatParam, '(.*?)') + .replace(optionalRegex, '\\s*$1?\\s*'); + return new RegExp('^' + command + '$', 'i'); + }; + + // This method receives an array of callbacks to iterate over, and invokes each of them + var invokeCallbacks = function(callbacks) { + var args = Array.prototype.slice.call(arguments, 1); + callbacks.forEach(function(callback) { + callback.callback.apply(callback.context, args); + }); + }; + + var isInitialized = function() { + return recognition !== undefined; + }; + + // method for logging in developer console when debug mode is on + var logMessage = function(text, extraParameters) { + if (text.indexOf('%c') === -1 && !extraParameters) { + console.log(text); + } else { + extraParameters = extraParameters || debugStyle; + console.log(text, extraParameters); + } + }; + + var initIfNeeded = function() { + if (!isInitialized()) { + annyang.init({}, false); + } + }; + + var registerCommand = function(command, cb, phrase) { + commandsList.push({ command: command, callback: cb, originalPhrase: phrase }); + if (debugState) { + logMessage('Command successfully loaded: %c'+phrase, debugStyle); + } + }; + + var parseResults = function(results) { + invokeCallbacks(callbacks.result, results); + var commandText; + // go over each of the 5 results and alternative results received (we've set maxAlternatives to 5 above) + for (var i = 0; i 0) { + debugState = !!newState; + } else { + debugState = true; + } + }, + + /** + * Set the language the user will speak in. If this method is not called, defaults to 'en-US'. + * + * @param {String} language - The language (locale) + * @method setLanguage + * @see [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported) + */ + setLanguage: function(language) { + initIfNeeded(); + recognition.lang = language; + }, + + /** + * Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands. + * + * #### Examples: + * ````javascript + * var commands = {'hello :name': helloFunction, 'howdy': helloFunction}; + * var commands2 = {'hi': helloFunction}; + * + * annyang.addCommands(commands); + * annyang.addCommands(commands2); + * // annyang will now listen to all three commands + * ```` + * + * @param {Object} commands - Commands that annyang should listen to + * @method addCommands + * @see [Commands Object](#commands-object) + */ + addCommands: function(commands) { + var cb; + + initIfNeeded(); + + for (var phrase in commands) { + if (commands.hasOwnProperty(phrase)) { + cb = root[commands[phrase]] || commands[phrase]; + if (typeof cb === 'function') { + // convert command to regex then register the command + registerCommand(commandToRegExp(phrase), cb, phrase); + } else if (typeof cb === 'object' && cb.regexp instanceof RegExp) { + // register the command + registerCommand(new RegExp(cb.regexp.source, 'i'), cb.callback, phrase); + } else { + if (debugState) { + logMessage('Can not register command: %c'+phrase, debugStyle); + } + continue; + } + } + } + }, + + /** + * Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. + * + * #### Examples: + * ````javascript + * var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction}; + * + * // Remove all existing commands + * annyang.removeCommands(); + * + * // Add some commands + * annyang.addCommands(commands); + * + * // Don't respond to hello + * annyang.removeCommands('hello'); + * + * // Don't respond to howdy or hi + * annyang.removeCommands(['howdy', 'hi']); + * ```` + * @param {String|Array|Undefined} [commandsToRemove] - Commands to remove + * @method removeCommands + */ + removeCommands: function(commandsToRemove) { + if (commandsToRemove === undefined) { + commandsList = []; + return; + } + commandsToRemove = Array.isArray(commandsToRemove) ? commandsToRemove : [commandsToRemove]; + commandsList = commandsList.filter(function(command) { + for (var i = 0; i + * var commands = { + * // annyang will capture anything after a splat (*) and pass it to the function. + * // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin'); + * 'show me *tag': showFlickr, + * + * // A named variable is a one word variable, that can fit anywhere in your command. + * // e.g. saying "calculate October stats" will call calculateStats('October'); + * 'calculate :month stats': calculateStats, + * + * // By defining a part of the following command as optional, annyang will respond + * // to both: "say hello to my little friend" as well as "say hello friend" + * 'say hello (to my little) friend': greeting + * }; + * + * var showFlickr = function(tag) { + * var url = 'http://api.flickr.com/services/rest/?tags='+tag; + * $.getJSON(url); + * } + * + * var calculateStats = function(month) { + * $('#stats').text('Statistics for '+month); + * } + * + * var greeting = function() { + * $('#greeting').text('Hello!'); + * } + * + * ```` + * + * ### Using Regular Expressions in commands + * For advanced commands, you can pass a regular expression object, instead of + * a simple string command. + * + * This is done by passing an object containing two properties: `regexp`, and + * `callback` instead of the function. + * + * #### Examples: + * ````javascript + * var calculateFunction = function(month) { console.log(month); } + * var commands = { + * // This example will accept any word as the "month" + * 'calculate :month stats': calculateFunction, + * // This example will only accept months which are at the start of a quarter + * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction} + * } + ```` + * + */ \ No newline at end of file From f80fe4a905c0c2c52966d72a4faf3df1d1f37f8a Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Thu, 7 Jul 2016 02:24:39 -0700 Subject: [PATCH 3/5] use regex to catch command --- index.html | 1 - user_scripts/Interface.js | 2 +- user_scripts/VoiceController.js | 183 +++++++++++++++++++++++++++++++++++----- user_scripts/annyang.min.js | 2 - 4 files changed, 162 insertions(+), 26 deletions(-) diff --git a/index.html b/index.html index ce33b72..45ceb49 100644 --- a/index.html +++ b/index.html @@ -64,7 +64,6 @@ - diff --git a/user_scripts/Interface.js b/user_scripts/Interface.js index 499947b..de49411 100644 --- a/user_scripts/Interface.js +++ b/user_scripts/Interface.js @@ -2,7 +2,7 @@ var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": function pressButton(button, time) { - if(button in mapButtontoIndex ){ + if( button in mapButtontoIndex ){ index = mapButtontoIndex[button] IodineGUI.Iodine.keyDown(index); diff --git a/user_scripts/VoiceController.js b/user_scripts/VoiceController.js index 1f81166..cc8b08c 100644 --- a/user_scripts/VoiceController.js +++ b/user_scripts/VoiceController.js @@ -1,32 +1,171 @@ -if(annyang){ - - pressKeyFunctionConstructor = function(key){ - key = key.toLowerCase() - var func = function(){ - pressButton(key,20); - }; - return func; +// if(annyang){ + +// pressKeyFunctionConstructor = function(key){ +// key = key.toLowerCase() +// var func = function(){ +// pressButton(key,20); +// }; +// return func; +// } + +// handleButton = function(key){ +// //lower case the key to ignore capitals +// key = key.toLowerCase(); +// pressButton(key, 20); +// } + + + +// var commands = {}; + +// for (var key in mapButtontoIndex){ +// commands[key] = pressKeyFunctionConstructor(key); +// } +// commands["press (the) button *key"] = handleButton; +// commands["press (the) key *key"] = handleButton; + + + +// // Add our commands to annyang +// annyang.addCommands(commands); +// annyang.start(); +// } + +var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": 5, "up":6 ,"down":7, "r":8, "l":9}; +var SpeechRecognition = SpeechRecognition || + webkitSpeechRecognition || + mozSpeechRecognition || + msSpeechRecognition || + oSpeechRecognition; + +if (SpeechRecognition){ + recognition = new SpeechRecognition(); + recognition.maxAlternatives = 30; + recognition.continuous = true; + recognition.lang = 'en-US'; + + recognition.onstart = function() { + console.log("start"); + }; + + recognition.onerror = function(event) { + console.log(event); + }; + + recognition.onend = function() { + console.log("end"); + recognition.start(); + }; + + + var controlRegex = new RegExp(/(?:press|push)(?:\sthe)?(?:\sbutton|\skey)?\s(\w+)/, 'i'); + handleButton = function(result) { + var match = controlRegex.exec(result); + if (match != null){ + var key = match[1].toLowerCase(); + if (key in mapButtontoIndex){ + pressButton(key, 20); + return true; + } + } + return false; } - handleButton = function(key){ - //lower case the key to ignore capitals - key = key.toLowerCase(); - pressButton(key, 20); + // var fullScreenRegex = new RegExp(/fullscreen|full-screen/, 'i'); + // handleFullscreen = function(result) { + // console.log("fullscreen handler"); + // if (fullScreenRegex.test(result)){ + // toggleFullScreen(); + // return true; + // } + // return false; + // } + + var settingsRegexOne = new RegExp(/(increase|up|decrease|down)(?:\sthe)?\s(volume|speed)(\sby\s(\w+))?/, 'i'); + var settingsRegexTwo = new RegExp(/(?:set|move|get)(?:\sthe)?\s(volume|speed)(?:\sto)?\s(\w+)/, 'i'); + handleSettings = function(result) { + var matchOne = settingsRegexOne.exec(result); + var matchTwo = settingsRegexTwo.exec(result); + if(matchOne != null){ + var action = matchOne[1].toLowerCase(); + var obj = matchOne[2].toLowerCase(); + var num = matchOne[4]; + if( isNaN(num) ){ + num = 0.1; + } + else{ + num = parseInt(num) / 100; + } + if (action == "increase" || action == "up"){ + num = num; + } + else{ + num = -num; + } + if (obj == "volume"){ + stepVolume(num); + } + else{ + IodineGUI.Iodine.incrementSpeed(num); + } + return true; + } + + if(matchTwo != null){ + var obj = matchTwo[1].toLowerCase(); + var num = matchTwo[2]; + if( isNaN(num) ){ + num = 0.1; + } + else{ + num = parseInt(num) / 100; + } + if (obj == "volume"){ + stepVolume(-1); + stepVolume(num); + } + else{ + IodineGUI.Iodine.setSpeed(num); + } + return true; + } + return false; } - var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": 5, "up":6 ,"down":7, "r":8, "l":9}; + var RegexFunc = [handleButton, handleSettings]; - var commands = {}; + handleResults = function(results) { + console.log(results); - for (var key in mapButtontoIndex){ - commands[key] = pressKeyFunctionConstructor(key); + var handled = false; + for (var k = 0; k < results.length; k++){ + var result = results[k]; + for (var funcIndex = 0; funcIndex < RegexFunc.length; funcIndex++){ + if (RegexFunc[funcIndex](result) ) { + handled = true; + break; + } + } + if (handled){ + break; + } + } } - commands["press (the) button *key"] = handleButton; - commands["press (the) key *key"] = handleButton; + + recognition.onresult = function(event) { + console.log('result'); + var SpeechRecognitionResult = event.results[event.resultIndex]; + var results = []; + for (var k = 0; k Date: Fri, 8 Jul 2016 01:03:40 -0700 Subject: [PATCH 4/5] clean up --- IodineGBA/core/Emulator.js | 7 ------- IodineGBA/core/Worker.js | 2 -- user_scripts/JoyPadGlueCode.js | 1 - user_scripts/VoiceController.js | 32 -------------------------------- 4 files changed, 42 deletions(-) diff --git a/IodineGBA/core/Emulator.js b/IodineGBA/core/Emulator.js index fd9ec7c..b230174 100644 --- a/IodineGBA/core/Emulator.js +++ b/IodineGBA/core/Emulator.js @@ -329,19 +329,12 @@ GameBoyAdvanceEmulator.prototype.initializeCore = function () { return allowInit | 0; } GameBoyAdvanceEmulator.prototype.keyDown = function (keyPressed) { - console.log("keydown emulator"); - console.log(keyPressed); - keyPressed = keyPressed | 0; if ((this.emulatorStatus | 0) < 0x10 && (keyPressed | 0) >= 0 && (keyPressed | 0) <= 9) { this.IOCore.joypad.keyPress(keyPressed | 0); } } GameBoyAdvanceEmulator.prototype.keyUp = function (keyReleased) { - console.log("keyup emulator"); - console.log(keyReleased); - - keyReleased = keyReleased | 0; if ((this.emulatorStatus | 0) < 0x10 && (keyReleased | 0) >= 0 && (keyReleased | 0) <= 9) { this.IOCore.joypad.keyRelease(keyReleased | 0); diff --git a/IodineGBA/core/Worker.js b/IodineGBA/core/Worker.js index f88ca0b..1a96fde 100644 --- a/IodineGBA/core/Worker.js +++ b/IodineGBA/core/Worker.js @@ -112,11 +112,9 @@ self.onmessage = function (event) { break; case 11: Iodine.keyDown(data.payload | 0); - console.log("keydown"); break; case 12: Iodine.keyUp(data.payload | 0); - console.log("keyUp"); break; case 13: Iodine.incrementSpeed(+data.payload); diff --git a/user_scripts/JoyPadGlueCode.js b/user_scripts/JoyPadGlueCode.js index 5bacfb8..98f1444 100644 --- a/user_scripts/JoyPadGlueCode.js +++ b/user_scripts/JoyPadGlueCode.js @@ -9,7 +9,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ function keyDown(e) { - var keyCode = e.keyCode | 0; for (var keyMapIndex = 0; (keyMapIndex | 0) < 10; keyMapIndex = ((keyMapIndex | 0) + 1) | 0) { if ((IodineGUI.defaults.keyZonesGBA[keyMapIndex | 0] | 0) == (keyCode | 0)) { diff --git a/user_scripts/VoiceController.js b/user_scripts/VoiceController.js index cc8b08c..188b5eb 100644 --- a/user_scripts/VoiceController.js +++ b/user_scripts/VoiceController.js @@ -1,35 +1,3 @@ -// if(annyang){ - -// pressKeyFunctionConstructor = function(key){ -// key = key.toLowerCase() -// var func = function(){ -// pressButton(key,20); -// }; -// return func; -// } - -// handleButton = function(key){ -// //lower case the key to ignore capitals -// key = key.toLowerCase(); -// pressButton(key, 20); -// } - - - -// var commands = {}; - -// for (var key in mapButtontoIndex){ -// commands[key] = pressKeyFunctionConstructor(key); -// } -// commands["press (the) button *key"] = handleButton; -// commands["press (the) key *key"] = handleButton; - - - -// // Add our commands to annyang -// annyang.addCommands(commands); -// annyang.start(); -// } var mapButtontoIndex = {"a":0, "b":1, "select":2, "start":3, "right":4, "left": 5, "up":6 ,"down":7, "r":8, "l":9}; var SpeechRecognition = SpeechRecognition || From 2ea384a20a2df4d8a6ede9db7b6e20627210dfc5 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Fri, 8 Jul 2016 01:16:36 -0700 Subject: [PATCH 5/5] take out extra --- user_scripts/annyang.min.js | 692 -------------------------------------------- 1 file changed, 692 deletions(-) delete mode 100644 user_scripts/annyang.min.js diff --git a/user_scripts/annyang.min.js b/user_scripts/annyang.min.js deleted file mode 100644 index f381242..0000000 --- a/user_scripts/annyang.min.js +++ /dev/null @@ -1,692 +0,0 @@ -//! annyang -//! version : 2.4.0 -//! author : Tal Ater @TalAter -//! license : MIT -//! https://www.TalAter.com/annyang/ -(function (root, factory) { - "use strict"; - if (typeof define === 'function' && define.amd) { // AMD + global - define([], function () { - return (root.annyang = factory(root)); - }); - } else if (typeof module === 'object' && module.exports) { // CommonJS - module.exports = factory(root); - } else { // Browser globals - root.annyang = factory(root); - } -}(typeof window !== 'undefined' ? window : this, function (root, undefined) { - "use strict"; - - /** - * # Quick Tutorial, Intro and Demos - * - * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). - * - * For a more in-depth look at annyang, read on. - * - * # API Reference - */ - - var annyang; - - // Get the SpeechRecognition object, while handling browser prefixes - var SpeechRecognition = root.SpeechRecognition || - root.webkitSpeechRecognition || - root.mozSpeechRecognition || - root.msSpeechRecognition || - root.oSpeechRecognition; - - console.log(SpeechRecognition); - - // Check browser support - // This is done as early as possible, to make it as fast as possible for unsupported browsers - if (!SpeechRecognition) { - return null; - } - - var commandsList = []; - var recognition; - var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] }; - var autoRestart; - var lastStartedAt = 0; - var autoRestartCount = 0; - var debugState = false; - var debugStyle = 'font-weight: bold; color: #00f;'; - var pauseListening = false; - var isListening = false; - - // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license. - var optionalParam = /\s*\((.*?)\)\s*/g; - var optionalRegex = /(\(\?:[^)]+\))\?/g; - var namedParam = /(\(\?)?:\w+/g; - var splatParam = /\*\w+/g; - var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#]/g; - var commandToRegExp = function(command) { - command = command.replace(escapeRegExp, '\\$&') - .replace(optionalParam, '(?:$1)?') - .replace(namedParam, function(match, optional) { - return optional ? match : '([^\\s]+)'; - }) - .replace(splatParam, '(.*?)') - .replace(optionalRegex, '\\s*$1?\\s*'); - return new RegExp('^' + command + '$', 'i'); - }; - - // This method receives an array of callbacks to iterate over, and invokes each of them - var invokeCallbacks = function(callbacks) { - var args = Array.prototype.slice.call(arguments, 1); - callbacks.forEach(function(callback) { - callback.callback.apply(callback.context, args); - }); - }; - - var isInitialized = function() { - return recognition !== undefined; - }; - - // method for logging in developer console when debug mode is on - var logMessage = function(text, extraParameters) { - if (text.indexOf('%c') === -1 && !extraParameters) { - console.log(text); - } else { - extraParameters = extraParameters || debugStyle; - console.log(text, extraParameters); - } - }; - - var initIfNeeded = function() { - if (!isInitialized()) { - annyang.init({}, false); - } - }; - - var registerCommand = function(command, cb, phrase) { - commandsList.push({ command: command, callback: cb, originalPhrase: phrase }); - if (debugState) { - logMessage('Command successfully loaded: %c'+phrase, debugStyle); - } - }; - - var parseResults = function(results) { - invokeCallbacks(callbacks.result, results); - var commandText; - // go over each of the 5 results and alternative results received (we've set maxAlternatives to 5 above) - for (var i = 0; i 0) { - debugState = !!newState; - } else { - debugState = true; - } - }, - - /** - * Set the language the user will speak in. If this method is not called, defaults to 'en-US'. - * - * @param {String} language - The language (locale) - * @method setLanguage - * @see [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported) - */ - setLanguage: function(language) { - initIfNeeded(); - recognition.lang = language; - }, - - /** - * Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands. - * - * #### Examples: - * ````javascript - * var commands = {'hello :name': helloFunction, 'howdy': helloFunction}; - * var commands2 = {'hi': helloFunction}; - * - * annyang.addCommands(commands); - * annyang.addCommands(commands2); - * // annyang will now listen to all three commands - * ```` - * - * @param {Object} commands - Commands that annyang should listen to - * @method addCommands - * @see [Commands Object](#commands-object) - */ - addCommands: function(commands) { - var cb; - - initIfNeeded(); - - for (var phrase in commands) { - if (commands.hasOwnProperty(phrase)) { - cb = root[commands[phrase]] || commands[phrase]; - if (typeof cb === 'function') { - // convert command to regex then register the command - registerCommand(commandToRegExp(phrase), cb, phrase); - } else if (typeof cb === 'object' && cb.regexp instanceof RegExp) { - // register the command - registerCommand(new RegExp(cb.regexp.source, 'i'), cb.callback, phrase); - } else { - if (debugState) { - logMessage('Can not register command: %c'+phrase, debugStyle); - } - continue; - } - } - } - }, - - /** - * Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. - * - * #### Examples: - * ````javascript - * var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction}; - * - * // Remove all existing commands - * annyang.removeCommands(); - * - * // Add some commands - * annyang.addCommands(commands); - * - * // Don't respond to hello - * annyang.removeCommands('hello'); - * - * // Don't respond to howdy or hi - * annyang.removeCommands(['howdy', 'hi']); - * ```` - * @param {String|Array|Undefined} [commandsToRemove] - Commands to remove - * @method removeCommands - */ - removeCommands: function(commandsToRemove) { - if (commandsToRemove === undefined) { - commandsList = []; - return; - } - commandsToRemove = Array.isArray(commandsToRemove) ? commandsToRemove : [commandsToRemove]; - commandsList = commandsList.filter(function(command) { - for (var i = 0; i - * var commands = { - * // annyang will capture anything after a splat (*) and pass it to the function. - * // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin'); - * 'show me *tag': showFlickr, - * - * // A named variable is a one word variable, that can fit anywhere in your command. - * // e.g. saying "calculate October stats" will call calculateStats('October'); - * 'calculate :month stats': calculateStats, - * - * // By defining a part of the following command as optional, annyang will respond - * // to both: "say hello to my little friend" as well as "say hello friend" - * 'say hello (to my little) friend': greeting - * }; - * - * var showFlickr = function(tag) { - * var url = 'http://api.flickr.com/services/rest/?tags='+tag; - * $.getJSON(url); - * } - * - * var calculateStats = function(month) { - * $('#stats').text('Statistics for '+month); - * } - * - * var greeting = function() { - * $('#greeting').text('Hello!'); - * } - * - * ```` - * - * ### Using Regular Expressions in commands - * For advanced commands, you can pass a regular expression object, instead of - * a simple string command. - * - * This is done by passing an object containing two properties: `regexp`, and - * `callback` instead of the function. - * - * #### Examples: - * ````javascript - * var calculateFunction = function(month) { console.log(month); } - * var commands = { - * // This example will accept any word as the "month" - * 'calculate :month stats': calculateFunction, - * // This example will only accept months which are at the start of a quarter - * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction} - * } - ```` - * - */ \ No newline at end of file