From cbbc759f616b0b5ac5cfe730d69a4d5be998b85f Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Fri, 8 Jul 2016 22:15:57 -0700 Subject: [PATCH 1/3] local var and check window attribute for speech recognition --- index.html | 1 + user_scripts/VoiceController.js | 151 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 user_scripts/VoiceController.js diff --git a/index.html b/index.html index 586ccc4..98dfed4 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,7 @@ + diff --git a/user_scripts/VoiceController.js b/user_scripts/VoiceController.js new file mode 100644 index 0000000..3851119 --- /dev/null +++ b/user_scripts/VoiceController.js @@ -0,0 +1,151 @@ +"use strict"; + + +(function(){ + var pressButton = function(button, time) { + if( button in IodineGUI.mapButtontoIndex ){ + var index = IodineGUI.mapButtontoIndex[button] + IodineGUI.Iodine.keyDown(index); + + setTimeout(function() { + IodineGUI.Iodine.keyUp(index); + }, time); + } + return; + } + + var SpeechRecognition = null; + var checks = ['SpeechRecognition', 'webkitSpeechRecognition', + 'mozSpeechRecognition', 'msSpeechRecognition', 'oSpeechRecognition']; + + + var check; + for (var k = 0; k < checks.length; k++){ + check = checks[k]; + if(check in window){ + SpeechRecognition = window[check]; + break; + } + } + + + if (SpeechRecognition){ + var 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'); + var 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; + } + + + 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'); + var 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 RegexFunc = [handleButton, handleSettings]; + + var handleResults = function(results) { + console.log(results); + + 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; + } + } + } + + recognition.onresult = function(event) { + var SpeechRecognitionResult = event.results[event.resultIndex]; + var results = []; + for (var k = 0; k Date: Fri, 8 Jul 2016 22:40:23 -0700 Subject: [PATCH 2/3] message at top --- user_scripts/VoiceController.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user_scripts/VoiceController.js b/user_scripts/VoiceController.js index 3851119..0716974 100644 --- a/user_scripts/VoiceController.js +++ b/user_scripts/VoiceController.js @@ -1,4 +1,13 @@ "use strict"; +/* + Copyright (C) 2016 Jeff Zhang + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + 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(){ From 8d2084e06fc8afe17fa6e57df32890534a09ab40 Mon Sep 17 00:00:00 2001 From: Jeff Zhang Date: Sat, 9 Jul 2016 02:02:29 -0700 Subject: [PATCH 3/3] update readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 18e26b7..04ba5c2 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,28 @@ The above copyright notice and this permission notice shall be included in all c 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. +Voice Interface +-------------------------------------------------------------------- +Voice Interface added by Jeff Zhang@JeffZhang02747 +To control GameBoy through voice, You have to allow this page to access microphone first. + +voice command to press a button: + press/push (the) button/key [button_name] + word in the bracket is optional + + example: + push key left + +voice command to control speed/volume: + increase/up/decrease/down (the) volume/speed + increase/up/decrease/down (the) volume/speed by [amount] + set/move/get (the) volume/speed to [amount] + + example: + up the volume + + + Screenshots --------------------------------------------------------------------