Comparing version 0.1.3 to 0.2.0
@@ -1,2 +0,2 @@ | ||
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ | ||
localStorage.debug = true; | ||
@@ -59,3 +59,63 @@ | ||
},{"../hark.js":2,"attachmediastream":3,"bows":4,"getusermedia":6}],2:[function(require,module,exports){ | ||
},{"../hark.js":2,"attachmediastream":4,"bows":5,"getusermedia":3}],3:[function(require,module,exports){ | ||
// getUserMedia helper by @HenrikJoreteg | ||
var func = (navigator.getUserMedia || | ||
navigator.webkitGetUserMedia || | ||
navigator.mozGetUserMedia || | ||
navigator.msGetUserMedia); | ||
module.exports = function (constraints, cb) { | ||
var options; | ||
var haveOpts = arguments.length === 2; | ||
var defaultOpts = {video: true, audio: true}; | ||
// make constraints optional | ||
if (!haveOpts) { | ||
cb = constraints; | ||
constraints = defaultOpts; | ||
} | ||
// treat lack of browser support like an error | ||
if (!func) { | ||
// throw proper error per spec | ||
var error = new Error('NavigatorUserMediaError'); | ||
error.reason = "NOT_SUPPORTED"; | ||
return cb(error); | ||
} | ||
func.call(navigator, constraints, function (stream) { | ||
cb(null, stream); | ||
}, function (err) { | ||
err.reason = err.name || "PERMISSION_DENIED"; | ||
cb(err); | ||
}); | ||
}; | ||
},{}],4:[function(require,module,exports){ | ||
module.exports = function (element, stream, play) { | ||
var autoPlay = (play === false) ? false : true; | ||
if (autoPlay) element.autoplay = true; | ||
// handle mozilla case | ||
if (window.mozGetUserMedia) { | ||
element.mozSrcObject = stream; | ||
if (autoPlay) element.play(); | ||
} else { | ||
if (typeof element.srcObject !== 'undefined') { | ||
element.srcObject = stream; | ||
} else if (typeof element.mozSrcObject !== 'undefined') { | ||
element.mozSrcObject = stream; | ||
} else if (typeof element.src !== 'undefined') { | ||
element.src = URL.createObjectURL(stream); | ||
} else { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
},{}],2:[function(require,module,exports){ | ||
var WildEmitter = require('wildemitter'); | ||
@@ -77,6 +137,8 @@ | ||
var audioContextType = window.webkitAudioContext || window.AudioContext; | ||
// use a single audio context due to hardware limits | ||
var audioContext = null; | ||
module.exports = function(stream, options) { | ||
var harker = new WildEmitter(); | ||
var audioContextType = window.webkitAudioContext || window.AudioContext; | ||
@@ -91,6 +153,9 @@ // make it not break in non-supported browsers | ||
threshold = options.threshold, | ||
play = options.play; | ||
play = options.play, | ||
running = true; | ||
//Setup Audio Context | ||
var audioContext = new audioContextType(); | ||
if (!audioContext) { | ||
audioContext = new audioContextType(); | ||
} | ||
var sourceNode, fftBins, analyser; | ||
@@ -127,2 +192,11 @@ | ||
}; | ||
harker.stop = function() { | ||
running = false; | ||
harker.emit('volume_change', -100, threshold); | ||
if (harker.speaking) { | ||
harker.speaking = false; | ||
harker.emit('stopped_speaking'); | ||
} | ||
}; | ||
@@ -133,2 +207,8 @@ // Poll the analyser node to determine if speaking | ||
setTimeout(function() { | ||
//check if stop has been called | ||
if(!running) { | ||
return; | ||
} | ||
var currentVolume = getMaxVolume(analyser, fftBins); | ||
@@ -159,183 +239,3 @@ | ||
},{"wildemitter":7}],3:[function(require,module,exports){ | ||
module.exports = function (stream, el, options) { | ||
var URL = window.URL; | ||
var opts = { | ||
autoplay: true, | ||
mirror: false, | ||
muted: false | ||
}; | ||
var element = el || document.createElement('video'); | ||
var item; | ||
if (options) { | ||
for (item in options) { | ||
opts[item] = options[item]; | ||
} | ||
} | ||
if (opts.autoplay) element.autoplay = 'autoplay'; | ||
if (opts.muted) element.muted = true; | ||
if (opts.mirror) { | ||
['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) { | ||
var styleName = prefix ? prefix + 'Transform' : 'transform'; | ||
element.style[styleName] = 'scaleX(-1)'; | ||
}); | ||
} | ||
// this first one should work most everywhere now | ||
// but we have a few fallbacks just in case. | ||
if (URL && URL.createObjectURL) { | ||
element.src = URL.createObjectURL(stream); | ||
} else if (element.srcObject) { | ||
element.srcObject = stream; | ||
} else if (element.mozSrcObject) { | ||
element.mozSrcObject = stream; | ||
} else { | ||
return false; | ||
} | ||
return element; | ||
}; | ||
},{}],4:[function(require,module,exports){ | ||
(function() { | ||
var inNode = typeof window === 'undefined', | ||
ls = !inNode && window.localStorage, | ||
debug = ls.debug, | ||
logger = require('andlog'), | ||
goldenRatio = 0.618033988749895, | ||
hue = 0, | ||
padLength = 15, | ||
noop = function() {}, | ||
yieldColor, | ||
bows, | ||
debugRegex; | ||
yieldColor = function() { | ||
hue += goldenRatio; | ||
hue = hue % 1; | ||
return hue * 360; | ||
}; | ||
var debugRegex = debug && debug[0]==='/' && new RegExp(debug.substring(1,debug.length-1)); | ||
bows = function(str) { | ||
var msg; | ||
msg = "%c" + (str.slice(0, padLength)); | ||
msg += Array(padLength + 3 - msg.length).join(' ') + '|'; | ||
if (debugRegex && !str.match(debugRegex)) return noop; | ||
if (!window.chrome) return logger.log.bind(logger, msg); | ||
return logger.log.bind(logger, msg, "color: hsl(" + (yieldColor()) + ",99%,40%); font-weight: bold"); | ||
}; | ||
bows.config = function(config) { | ||
if (config.padLength) { | ||
return padLength = config.padLength; | ||
} | ||
}; | ||
if (typeof module !== 'undefined') { | ||
module.exports = bows; | ||
} else { | ||
window.bows = bows; | ||
} | ||
}).call(); | ||
},{"andlog":5}],5:[function(require,module,exports){ | ||
// follow @HenrikJoreteg and @andyet if you like this ;) | ||
(function () { | ||
var inNode = typeof window === 'undefined', | ||
ls = !inNode && window.localStorage, | ||
out = {}; | ||
if (inNode) { | ||
module.exports = console; | ||
return; | ||
} | ||
if (ls && ls.debug && window.console) { | ||
out = window.console; | ||
} else { | ||
var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), | ||
l = methods.length, | ||
fn = function () {}; | ||
while (l--) { | ||
out[methods[l]] = fn; | ||
} | ||
} | ||
if (typeof exports !== 'undefined') { | ||
module.exports = out; | ||
} else { | ||
window.console = out; | ||
} | ||
})(); | ||
},{}],6:[function(require,module,exports){ | ||
// getUserMedia helper by @HenrikJoreteg | ||
var func = (navigator.getUserMedia || | ||
navigator.webkitGetUserMedia || | ||
navigator.mozGetUserMedia || | ||
navigator.msGetUserMedia); | ||
module.exports = function (constraints, cb) { | ||
var options; | ||
var haveOpts = arguments.length === 2; | ||
var defaultOpts = {video: true, audio: true}; | ||
var error; | ||
var denied = 'PERMISSION_DENIED'; | ||
var notSatified = 'CONSTRAINT_NOT_SATISFIED'; | ||
// make constraints optional | ||
if (!haveOpts) { | ||
cb = constraints; | ||
constraints = defaultOpts; | ||
} | ||
// treat lack of browser support like an error | ||
if (!func) { | ||
// throw proper error per spec | ||
error = new Error('NavigatorUserMediaError'); | ||
error.name = 'NOT_SUPPORTED_ERROR'; | ||
return cb(error); | ||
} | ||
func.call(navigator, constraints, function (stream) { | ||
cb(null, stream); | ||
}, function (err) { | ||
var error; | ||
// coerce into an error object since FF gives us a string | ||
// there are only two valid names according to the spec | ||
// we coerce all non-denied to "constraint not satisfied". | ||
if (typeof err === 'string') { | ||
error = new Error('NavigatorUserMediaError'); | ||
if (err === denied) { | ||
error.name = denied; | ||
} else { | ||
error.name = notSatified; | ||
} | ||
} else { | ||
// if we get an error object make sure '.name' property is set | ||
// according to spec: http://dev.w3.org/2011/webrtc/editor/getusermedia.html#navigatorusermediaerror-and-navigatorusermediaerrorcallback | ||
error = err; | ||
if (!error.name) { | ||
// this is likely chrome which | ||
// sets a property called "ERROR_DENIED" on the error object | ||
// if so we make sure to set a name | ||
if (error[denied]) { | ||
err.name = denied; | ||
} else { | ||
err.name = notSatified; | ||
} | ||
} | ||
} | ||
cb(error); | ||
}); | ||
}; | ||
},{}],7:[function(require,module,exports){ | ||
},{"wildemitter":6}],6:[function(require,module,exports){ | ||
/* | ||
@@ -477,3 +377,69 @@ WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based | ||
},{}],5:[function(require,module,exports){ | ||
(function(window) { | ||
var logger = require('andlog'), | ||
goldenRatio = 0.618033988749895, | ||
hue = 0, | ||
padLength = 15, | ||
yieldColor, | ||
bows; | ||
yieldColor = function() { | ||
hue += goldenRatio; | ||
hue = hue % 1; | ||
return hue * 360; | ||
}; | ||
bows = function(str) { | ||
var msg; | ||
msg = "%c" + (str.slice(0, padLength)); | ||
msg += Array(padLength + 3 - msg.length).join(' ') + '|'; | ||
return logger.log.bind(logger, msg, "color: hsl(" + (yieldColor()) + ",99%,40%); font-weight: bold"); | ||
}; | ||
bows.config = function(config) { | ||
if (config.padLength) { | ||
return padLength = config.padLength; | ||
} | ||
}; | ||
if (typeof module !== 'undefined') { | ||
module.exports = bows; | ||
} else { | ||
window.bows = bows; | ||
} | ||
}).call(this); | ||
},{"andlog":7}],7:[function(require,module,exports){ | ||
// follow @HenrikJoreteg and @andyet if you like this ;) | ||
(function () { | ||
var inNode = typeof window === 'undefined', | ||
ls = !inNode && window.localStorage, | ||
out = {}; | ||
if (inNode) { | ||
module.exports = console; | ||
return; | ||
} | ||
if (ls && ls.debug && window.console) { | ||
out = window.console; | ||
} else { | ||
var methods = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), | ||
l = methods.length, | ||
fn = function () {}; | ||
while (l--) { | ||
out[methods[l]] = fn; | ||
} | ||
} | ||
if (typeof exports !== 'undefined') { | ||
module.exports = out; | ||
} else { | ||
window.console = out; | ||
} | ||
})(); | ||
},{}]},{},[1]) | ||
; |
@@ -1,3 +0,4 @@ | ||
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.hark=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
var WildEmitter = _dereq_('wildemitter'); | ||
(function(e){if("function"==typeof bootstrap)bootstrap("hark",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeHark=e}else"undefined"!=typeof window?window.hark=e():global.hark=e()})(function(){var define,ses,bootstrap,module,exports; | ||
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ | ||
var WildEmitter = require('wildemitter'); | ||
@@ -33,3 +34,4 @@ function getMaxVolume (analyser, fftBins) { | ||
threshold = options.threshold, | ||
play = options.play; | ||
play = options.play, | ||
running = true; | ||
@@ -71,2 +73,11 @@ //Setup Audio Context | ||
}; | ||
harker.stop = function() { | ||
running = false; | ||
harker.emit('volume_change', -100, threshold); | ||
if (harker.speaking) { | ||
harker.speaking = false; | ||
harker.emit('stopped_speaking'); | ||
} | ||
}; | ||
@@ -77,2 +88,8 @@ // Poll the analyser node to determine if speaking | ||
setTimeout(function() { | ||
//check if stop has been called | ||
if(!running) { | ||
return; | ||
} | ||
var currentVolume = getMaxVolume(analyser, fftBins); | ||
@@ -103,3 +120,3 @@ | ||
},{"wildemitter":2}],2:[function(_dereq_,module,exports){ | ||
},{"wildemitter":2}],2:[function(require,module,exports){ | ||
/* | ||
@@ -241,4 +258,4 @@ WildEmitter.js is a slim little event emitter by @henrikjoreteg largely based | ||
},{}]},{},[1]) | ||
(1) | ||
}); | ||
},{}]},{},[1])(1) | ||
}); | ||
; |
18
hark.js
@@ -32,3 +32,4 @@ var WildEmitter = require('wildemitter'); | ||
threshold = options.threshold, | ||
play = options.play; | ||
play = options.play, | ||
running = true; | ||
@@ -70,2 +71,11 @@ //Setup Audio Context | ||
}; | ||
harker.stop = function() { | ||
running = false; | ||
harker.emit('volume_change', -100, threshold); | ||
if (harker.speaking) { | ||
harker.speaking = false; | ||
harker.emit('stopped_speaking'); | ||
} | ||
}; | ||
@@ -76,2 +86,8 @@ // Poll the analyser node to determine if speaking | ||
setTimeout(function() { | ||
//check if stop has been called | ||
if(!running) { | ||
return; | ||
} | ||
var currentVolume = getMaxVolume(analyser, fftBins); | ||
@@ -78,0 +94,0 @@ |
{ | ||
"name": "hark", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "Converts an audio stream to speech events in the browser", | ||
@@ -5,0 +5,0 @@ "main": "hark.js", |
@@ -63,2 +63,4 @@ # Hark | ||
* `setThreshold(threshold_in_db)` change the minimum volume at which the audio will emit a `speaking` event | ||
* hark can be stopped by calling this method | ||
* `stop()` will stop the polling and events will not be emitted. | ||
@@ -65,0 +67,0 @@ ## Options |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92
2062957
710
2