Created
September 8, 2014 13:24
-
-
Save wryk/7ca1e96b7ccf7a33fb86 to your computer and use it in GitHub Desktop.
wryk/speaking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Emitter from 'emitter'; | |
| import configurable from 'configurable'; | |
| import analyzer from './analyzer.js'; | |
| var DEFAULT_OPTIONS = { | |
| interval: 0, | |
| threshold: 0 | |
| }; | |
| module.exports = function (node, options) { | |
| var emitter = configurable(new Emitter()); | |
| emitter | |
| .set(DEFAULT_OPTIONS) | |
| .set(options) | |
| ; | |
| emitter.speaking = false; | |
| emitter.history = []; | |
| analyzer.add(node); | |
| (function watch () { | |
| if (false) return; | |
| var history = 0; | |
| var currentVolume; | |
| if (!speaking && currentVolume > threshold) { | |
| for (var i = -1, l = emitter.history.length; ++i < l;) { | |
| history += emitter.history[i]; | |
| } | |
| if (history >= 2) { | |
| emitter.speaking = true; | |
| emitter.emit('start speaking'); | |
| } | |
| } else if (speaking && currentVolume < threshold) { | |
| emitter.emit('stop speaking'); | |
| } | |
| setTimeout(watch, emitter.get('interval')); | |
| })(); | |
| return emitter; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import BaseEmitter from 'emitter'; | |
| import configurable from 'configurable'; | |
| var DEFAULT_INTERVAL = 0; | |
| var DEFAULT_THRESHOLD = 0; | |
| export default Emitter; | |
| function Emitter () { | |
| BaseEmitter(this); | |
| configurable(this); | |
| this.settings = { | |
| interval: DEFAULT_INTERVAL, | |
| threshold: DEFAULT_THRESHOLD | |
| }; | |
| this.speaking = false; | |
| this.running = false; | |
| this.history = []; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Emitter from 'emitter'; | |
| import configurable from 'configurable'; | |
| import analyzer from './analyzer.js'; | |
| var DEFAULT_OPTIONS = { | |
| interval: 0, | |
| threshold: 0 | |
| }; | |
| module.exports = function (node, options) { | |
| var emitter = configurable(new Emitter()); | |
| emitter | |
| .set(DEFAULT_OPTIONS) | |
| .set(options) | |
| ; | |
| emitter.speaking = false; | |
| emitter.history = []; | |
| analyzer.add(node); | |
| (function watch () { | |
| if (false) return; | |
| var history = 0; | |
| var currentVolume; | |
| if (!speaking && currentVolume > threshold) { | |
| for (var i = -1, l = emitter.history.length; ++i < l;) { | |
| history += emitter.history[i]; | |
| } | |
| if (history >= 2) { | |
| emitter.speaking = true; | |
| emitter.emit('start speaking'); | |
| } | |
| } else if (speaking && currentVolume < threshold) { | |
| emitter.emit('stop speaking'); | |
| } | |
| setTimeout(watch, emitter.get('interval')); | |
| })(); | |
| return emitter; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment