Spaces:
Running
Running
benjamin-paine
commited on
Commit
•
4bad033
1
Parent(s):
c356928
Upload 3 files
Browse files- hey-buddy-0.1.0.min.js +2 -0
- logo.png +0 -0
- production.html +400 -0
hey-buddy-0.1.0.min.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
/*! For license information please see hey-buddy.min.js.LICENSE.txt */
|
2 |
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["hey-buddy"]=e():t["hey-buddy"]=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{HeyBuddy:()=>It});var r=function(t){return new Promise((function(e){return setTimeout(e,t)}))};function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function o(){o=function(){return e};var t,e={},r=Object.prototype,i=r.hasOwnProperty,a=Object.defineProperty||function(t,e,r){t[e]=r.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",s=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function l(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof b?e:b,i=Object.create(o.prototype),c=new I(n||[]);return a(i,"_invoke",{value:_(t,r,c)}),i}function p(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var d="suspendedStart",y="suspendedYield",v="executing",m="completed",g={};function b(){}function w(){}function x(){}var E={};l(E,u,(function(){return this}));var k=Object.getPrototypeOf,L=k&&k(k(G([])));L&&L!==r&&i.call(L,u)&&(E=L);var O=x.prototype=b.prototype=Object.create(E);function j(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,a,c,u){var s=p(t[o],t,a);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==n(l)&&i.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,c,u)}),(function(t){r("throw",t,c,u)})):e.resolve(l).then((function(t){f.value=t,c(f)}),(function(t){return r("throw",t,c,u)}))}u(s.arg)}var o;a(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function _(e,r,n){var o=d;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=P(c,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===d)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=p(e,r,n);if("normal"===s.type){if(o=n.done?m:y,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=p(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function G(e){if(e||""===e){var r=e[u];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,a=function r(){for(;++o<e.length;)if(i.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(n(e)+" is not iterable")}return w.prototype=x,a(O,"constructor",{value:x,configurable:!0}),a(x,"constructor",{value:w,configurable:!0}),w.displayName=l(x,f,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,l(t,f,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},j(S.prototype),l(S.prototype,s,(function(){return this})),e.AsyncIterator=S,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new S(h(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(O),l(O,f,"Generator"),l(O,u,(function(){return this})),l(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=G,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(N),!e)for(var r in this)"t"===r.charAt(0)&&i.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function n(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=i.call(a,"catchLoc"),s=i.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,g):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:G(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function i(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,u,"next",t)}function u(t){i(a,n,o,c,u,"throw",t)}c(void 0)}))}}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,u(n.key),n)}}function u(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}var s,f,l=!1;void 0!==window.ort?(l=!0,s=window.ort.Tensor,f=window.ort.InferenceSession):import("./onnxruntime-web/ort.mjs").then((function(t){l=!0,s=t.Tensor,f=t.InferenceSession}));var h=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t)}return e=t,n=null,i=[{key:"waitForInitialization",value:(p=a(o().mark((function t(){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(l){t.next=5;break}return t.next=3,r(10);case 3:t.next=0;break;case 5:case"end":return t.stop()}}),t)}))),function(){return p.apply(this,arguments)})},{key:"createTensor",value:(h=a(o().mark((function e(r,n,i){return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.waitForInitialization();case 2:return e.abrupt("return",new s(r,n,i));case 3:case"end":return e.stop()}}),e)}))),function(t,e,r){return h.apply(this,arguments)})},{key:"createInferenceSession",value:(u=a(o().mark((function e(r){var n,i=arguments;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=i.length>1&&void 0!==i[1]?i[1]:{},e.next=3,t.waitForInitialization();case 3:return e.next=5,f.create(r,n);case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}}),e)}))),function(t){return u.apply(this,arguments)})}],n&&c(e.prototype,n),i&&c(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,i,u,h,p}();function p(t){return p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p(t)}function d(){d=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof b?e:b,a=Object.create(i.prototype),c=new I(n||[]);return o(a,"_invoke",{value:_(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",y="suspendedYield",v="executing",m="completed",g={};function b(){}function w(){}function x(){}var E={};s(E,a,(function(){return this}));var k=Object.getPrototypeOf,L=k&&k(k(G([])));L&&L!==r&&n.call(L,a)&&(E=L);var O=x.prototype=b.prototype=Object.create(E);function j(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==p(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function _(e,r,n){var o=h;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=P(c,n);if(u){if(u===g)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?m:y,s.arg===g)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),g;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,g;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,g):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,g)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function G(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(p(e)+" is not iterable")}return w.prototype=x,o(O,"constructor",{value:x,configurable:!0}),o(x,"constructor",{value:w,configurable:!0}),w.displayName=s(x,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,s(t,u,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},j(S.prototype),s(S.prototype,c,(function(){return this})),e.AsyncIterator=S,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new S(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(O),s(O,u,"Generator"),s(O,a,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=G,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(N),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,g):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),g},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),g}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:G(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),g}},e}function y(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function v(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){y(i,n,o,a,c,"next",t)}function c(t){y(i,n,o,a,c,"throw",t)}a(void 0)}))}}function m(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,w(n.key),n)}}function b(t,e,r){return e&&g(t.prototype,e),r&&g(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function w(t){var e=function(t,e){if("object"!=p(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=p(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==p(e)?e:e+""}h.waitForInitialization().then((function(){h.createTensor=function(t,e,r){return new s(t,e,r)},h.createInferenceSession=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return f.create(t,e)}}));var x=function(){return b((function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:2,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.05,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"/worklet.js",o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"hey-buddy",i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:16e3;m(this,t),this.initialized=!1,this.callbacks=[],this.batchSeconds=e,this.batchIntervalSeconds=r,this.batchIntervalCount=0,this.workletUrl=n,this.workletName=o,this.workletTargetSampleRate=i,this.buffer=new Float32Array(this.batchSamples),this.buffer.fill(0),this.initialize()}),[{key:"batchSamples",get:function(){return Math.floor(this.batchSeconds*this.workletTargetSampleRate)}},{key:"batchIntervalSamples",get:function(){return Math.floor(this.batchIntervalSeconds*this.workletTargetSampleRate)}},{key:"push",value:function(t){var e=this,r=t.length;this.buffer.set(this.buffer.subarray(r)),this.buffer.set(t,this.buffer.length-r),this.batchIntervalCount+=r,this.batchIntervalCount>=this.batchIntervalSamples&&(this.callbacks.forEach((function(t){return t(e.buffer)})),this.batchIntervalCount=0)}},{key:"onBatch",value:function(t){this.callbacks.push(t)}},{key:"offBatch",value:function(t){this.callbacks=this.callbacks.filter((function(e){return e!==t}))}},{key:"initialize",value:(t=v(d().mark((function t(){var e=this;return d().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.initialized){t.next=2;break}return t.abrupt("return");case 2:return t.next=4,navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,autoGainControl:!0,noiseSuppression:!0}});case 4:return this.stream=t.sent,this.audioContext=new AudioContext,this.sourceNode=new MediaStreamAudioSourceNode(this.audioContext,{mediaStream:this.stream}),t.next=9,E.create(this.audioContext,this.workletUrl,this.workletName,this.workletTargetSampleRate);case 9:this.workerNode=t.sent,this.sourceNode.connect(this.workerNode.worker),this.workerNode.worker.port.onmessage=function(t){e.push(t.data)},this.initialized=!0;case 13:case"end":return t.stop()}}),t,this)}))),function(){return t.apply(this,arguments)})}]);var t}(),E=function(){function t(e,r){m(this,t),this.context=e,this.worker=r}return b(t,null,[{key:"create",value:(e=v(d().mark((function e(r,n,o,i){var a;return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,r.audioWorklet.addModule(n);case 2:return a=new AudioWorkletNode(r,o,{processorOptions:{targetSampleRate:i}}),e.abrupt("return",new t(r,a));case 5:case"end":return e.stop()}}),e)}))),function(t,r,n,o){return e.apply(this,arguments)})}]);var e}();function k(t){return k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},k(t)}function L(){L=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new I(n||[]);return o(a,"_invoke",{value:_(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(G([])));E&&E!==r&&n.call(E,a)&&(w=E);var O=b.prototype=m.prototype=Object.create(w);function j(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==k(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function _(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=P(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function P(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,P(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function N(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function G(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(k(e)+" is not iterable")}return g.prototype=b,o(O,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(O),t},e.awrap=function(t){return{__await:t}},j(S.prototype),s(S.prototype,c,(function(){return this})),e.AsyncIterator=S,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new S(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},j(O),s(O,u,"Generator"),s(O,a,(function(){return this})),s(O,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=G,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(N),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),N(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;N(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:G(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function O(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function j(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){O(i,n,o,a,c,"next",t)}function c(t){O(i,n,o,a,c,"throw",t)}a(void 0)}))}}function S(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_(n.key),n)}}function _(t){var e=function(t,e){if("object"!=k(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==k(e)?e:e+""}var P=function(){return t=function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:3,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.modelPath=e,this.session=null,this.duration=0,this.ema=.1,this.lastTime=0,this.webnn=n,this.webgpu=o,this.webgl=i,this.wasm=a,this.power=r,this.load()},e=[{key:"powerPreference",get:function(){switch(this.power){case-1:return"low-power";case 1:return"high-performance";default:return"default"}}},{key:"executionProviders",get:function(){var t=[];return Number.isInteger(this.webnn)&&t.push([{name:"webnn",device:"gpu",powerPreference:this.powerPreference},this.webnn]),Number.isInteger(this.webgpu)&&t.push(["webgpu",this.webgpu]),Number.isInteger(this.webgl)&&t.push(["webgl",this.webgl]),Number.isInteger(this.wasm)&&t.push(["wasm",this.wasm]),t.sort((function(t,e){return t[1]-e[1]})),t.map((function(t){return t[0]}))}},{key:"sessionOptions",get:function(){return{executionProviders:["wasm"]}}},{key:"load",value:(c=j(L().mark((function t(){return L().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h.createInferenceSession(this.modelPath,this.sessionOptions);case 2:this.session=t.sent;case 3:case"end":return t.stop()}}),t,this)}))),function(){return c.apply(this,arguments)})},{key:"waitUntilLoaded",value:(a=j(L().mark((function t(){return L().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!==this.session){t.next=5;break}return t.next=3,r(1);case 3:t.next=0;break;case 5:case"end":return t.stop()}}),t,this)}))),function(){return a.apply(this,arguments)})},{key:"execute",value:(i=j(L().mark((function t(e){return L().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:throw new Error("Not Implemented");case 1:case"end":return t.stop()}}),t)}))),function(t){return i.apply(this,arguments)})},{key:"run",value:(o=j(L().mark((function t(e){var r,n,o;return L().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.waitUntilLoaded();case 2:return r=(new Date).getTime(),t.next=5,this.execute(e);case 5:return n=t.sent,o=(new Date).getTime()-r,0===this.duration?this.duration=o:this.duration=(1-this.ema)*this.duration+this.ema*o,this.lastTime=r,t.abrupt("return",n);case 10:case"end":return t.stop()}}),t,this)}))),function(t){return o.apply(this,arguments)})}],e&&S(t.prototype,e),n&&S(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,n,o,i,a,c}();function T(t){return T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},T(t)}function N(){N=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new I(n||[]);return o(a,"_invoke",{value:j(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(G([])));E&&E!==r&&n.call(E,a)&&(w=E);var k=b.prototype=m.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==T(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function G(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(T(e)+" is not iterable")}return g.prototype=b,o(k,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},L(O.prototype),s(O.prototype,c,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(k),s(k,u,"Generator"),s(k,a,(function(){return this})),s(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=G,I.prototype={constructor:I,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:G(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function I(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function G(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){I(i,n,o,a,c,"next",t)}function c(t){I(i,n,o,a,c,"throw",t)}a(void 0)}))}}function F(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,W(n.key),n)}}function W(t){var e=function(t,e){if("object"!=T(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=T(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==T(e)?e:e+""}function A(t,e,r){return e=C(e),function(t,e){if(e&&("object"==T(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,B()?Reflect.construct(e,r||[],C(t).constructor):e.apply(t,r))}function B(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(B=function(){return!!t})()}function C(t){return C=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},C(t)}function D(t,e){return D=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},D(t,e)}var R=function(t){function e(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/pretrained/silero-vad.onnx",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:3,c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,u=arguments.length>6&&void 0!==arguments[6]?arguments[6]:16e3;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(t=A(this,e,[r,n,o,i,a,c])).sampleRate=u||16e3,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&D(t,e)}(e,t),r=e,n=[{key:"test",value:(a=G(N().mark((function t(){var e,r,n=arguments;return N().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>0&&void 0!==n[0]&&n[0],t.next=3,this.run(new Float32Array(16e3).fill(0));case 3:if(r=t.sent,!(!isNaN(r)&&0<=r&&r<=1)){t.next=8;break}e&&console.log("VAD model OK, executed in ".concat(this.duration," ms")),t.next=9;break;case 8:throw new Error("VAD model failed - got ".concat(r));case 9:case"end":return t.stop()}}),t,this)}))),function(){return a.apply(this,arguments)})},{key:"execute",value:(i=G(N().mark((function t(e){var r,n;return N().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==this.h&&void 0!==this.c&&void 0!==this.sr){t.next=10;break}return t.next=3,h.createTensor("int64",[this.sampleRate],[1]);case 3:return this.sr=t.sent,t.next=6,h.createTensor("float32",new Array(128).fill(0),[2,1,64]);case 6:return this.h=t.sent,t.next=9,h.createTensor("float32",new Array(128).fill(0),[2,1,64]);case 9:this.c=t.sent;case 10:return t.next=12,h.createTensor("float32",e,[1,e.length]);case 12:return r=t.sent,t.next=15,this.session.run({input:r,h:this.h,c:this.c,sr:this.sr});case 15:return n=t.sent,this.c=n.cn,this.h=n.hn,t.abrupt("return",n.output.data[0]);case 19:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})}],n&&F(r.prototype,n),o&&F(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(P);function z(t){return z="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},z(t)}function M(){M=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new T(n||[]);return o(a,"_invoke",{value:j(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(N([])));E&&E!==r&&n.call(E,a)&&(w=E);var k=b.prototype=m.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==z(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(z(e)+" is not iterable")}return g.prototype=b,o(k,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},L(O.prototype),s(O.prototype,c,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(k),s(k,u,"Generator"),s(k,a,(function(){return this})),s(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function Y(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function V(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){Y(i,n,o,a,c,"next",t)}function c(t){Y(i,n,o,a,c,"throw",t)}a(void 0)}))}}function U(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,K(n.key),n)}}function K(t){var e=function(t,e){if("object"!=z(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=z(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==z(e)?e:e+""}function H(t,e,r){return e=q(e),function(t,e){if(e&&("object"==z(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,$()?Reflect.construct(e,r||[],q(t).constructor):e.apply(t,r))}function $(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return($=function(){return!!t})()}function q(t){return q=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},q(t)}function J(t,e){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},J(t,e)}var Q=function(t){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/pretrained/mel-spectrogram.onnx",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:3,a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),H(this,e,[t,r,n,o,i,a])}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&J(t,e)}(e,t),r=e,n=[{key:"test",value:(a=V(M().mark((function t(){var e,r,n=arguments;return M().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=n.length>0&&void 0!==n[0]&&n[0],t.next=3,this.run(new Float32Array(12640).fill(1));case 3:if(4!==(r=t.sent).dims.length||76!==r.dims[2]||32!==r.dims[3]){t.next=8;break}e&&console.log("Mel spectrogram model OK, executed in ".concat(this.duration," ms")),t.next=9;break;case 8:throw new Error("Mel spectrogram model failed");case 9:case"end":return t.stop()}}),t,this)}))),function(){return a.apply(this,arguments)})},{key:"execute",value:(i=V(M().mark((function t(e){var r,n;return M().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,h.createTensor("float32",e,[1,e.length]);case 2:return r=t.sent,t.next=5,this.session.run({input:r});case 5:return n=t.sent,t.next=8,h.createTensor("float32",n.output.data.map((function(t){return t/10+2})),n.output.dims);case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})}],n&&U(r.prototype,n),o&&U(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(P);function X(t){return X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X(t)}function Z(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(t){s=!0,o=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(t,e)||function(t,e){if(t){if("string"==typeof t)return tt(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?tt(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function tt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function et(){et=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new T(n||[]);return o(a,"_invoke",{value:j(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(N([])));E&&E!==r&&n.call(E,a)&&(w=E);var k=b.prototype=m.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==X(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(X(e)+" is not iterable")}return g.prototype=b,o(k,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},L(O.prototype),s(O.prototype,c,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(k),s(k,u,"Generator"),s(k,a,(function(){return this})),s(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function rt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function nt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){rt(i,n,o,a,c,"next",t)}function c(t){rt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function ot(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,it(n.key),n)}}function it(t){var e=function(t,e){if("object"!=X(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=X(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==X(e)?e:e+""}function at(t,e,r){return e=ut(e),function(t,e){if(e&&("object"==X(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ct()?Reflect.construct(e,r||[],ut(t).constructor):e.apply(t,r))}function ct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(ct=function(){return!!t})()}function ut(t){return ut=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},ut(t)}function st(t,e){return st=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},st(t,e)}var ft=function(t){function e(t){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:3,c=arguments.length>5&&void 0!==arguments[5]?arguments[5]:4,u=arguments.length>6&&void 0!==arguments[6]?arguments[6]:96,s=arguments.length>7&&void 0!==arguments[7]?arguments[7]:76,f=arguments.length>8&&void 0!==arguments[8]?arguments[8]:8;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=at(this,e,[t,n,o,i,a,c])).embeddingDim=u,r.windowSize=s,r.windowStride=f,r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&st(t,e)}(e,t),r=e,n=[{key:"test",value:(a=nt(et().mark((function t(){var e,r,n,o=arguments;return et().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.length>0&&void 0!==o[0]&&o[0],t.next=3,h.createTensor("float32",new Float32Array(new Array(3200).fill(0)),[100,32]);case 3:return r=t.sent,t.next=6,this.run(r);case 6:if(2!==(n=t.sent).dims.length||4!==n.dims[0]||96!==n.dims[1]){t.next=11;break}e&&console.log("Speech embedding model OK, executed in ".concat(this.duration," ms")),t.next=13;break;case 11:throw console.error("Unexpected speech embedding result",n),new Error("Speech embedding model failed");case 13:case"end":return t.stop()}}),t,this)}))),function(){return a.apply(this,arguments)})},{key:"execute",value:(i=nt(et().mark((function t(e){var r,n,o,i,a,c,u,s,f,l,p,d,y,v;return et().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=Z(e.dims,2),n=r[0],o=r[1],!(n<this.windowSize)){t.next=3;break}throw new Error("Audio is too short to process - require ".concat(this.windowSize," samples, got ").concat(n));case 3:return i=n-(n-this.windowSize)%this.windowStride,a=(i-this.windowSize)/this.windowStride+1,t.next=7,h.createTensor("float32",new Array(a*this.embeddingDim).fill(0),[a,this.embeddingDim]);case 7:c=t.sent,u=[],s=0;case 10:if(!(s<i-this.windowSize+this.windowStride)){t.next=19;break}return f=s+this.windowSize,t.next=14,h.createTensor("float32",e.data.slice(s*o,f*o),[this.windowSize,o,1]);case 14:l=t.sent,u.push([s,f,l]);case 16:s+=this.windowStride,t.next=10;break;case 19:return t.next=21,h.createTensor("float32",new Float32Array(a*this.windowSize*o),[a,this.windowSize,o,1]);case 21:for(p=t.sent,d=0;d<a;d++)p.data.set(u[d][2].data,d*this.windowSize*o);return t.next=25,this.session.run({input_1:p});case 25:for(y=t.sent,v=0;v<a;v++)c.data.set(y.conv2d_19.data.slice(v*this.embeddingDim,(v+1)*this.embeddingDim),v*this.embeddingDim);return t.abrupt("return",c);case 28:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})}],n&&ot(r.prototype,n),o&&ot(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(P);function lt(t){return lt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},lt(t)}function ht(){ht=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new T(n||[]);return o(a,"_invoke",{value:j(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(N([])));E&&E!==r&&n.call(E,a)&&(w=E);var k=b.prototype=m.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==lt(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(lt(e)+" is not iterable")}return g.prototype=b,o(k,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},L(O.prototype),s(O.prototype,c,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(k),s(k,u,"Generator"),s(k,a,(function(){return this})),s(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function pt(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function dt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){pt(i,n,o,a,c,"next",t)}function c(t){pt(i,n,o,a,c,"throw",t)}a(void 0)}))}}function yt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,vt(n.key),n)}}function vt(t){var e=function(t,e){if("object"!=lt(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=lt(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==lt(e)?e:e+""}function mt(t,e,r){return e=bt(e),function(t,e){if(e&&("object"==lt(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,gt()?Reflect.construct(e,r||[],bt(t).constructor):e.apply(t,r))}function gt(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(gt=function(){return!!t})()}function bt(t){return bt=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},bt(t)}function wt(t,e){return wt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},wt(t,e)}var xt=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),mt(this,e,arguments)}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&wt(t,e)}(e,t),r=e,n=[{key:"test",value:(a=dt(ht().mark((function t(){var e,r,n,o=arguments;return ht().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=o.length>0&&void 0!==o[0]&&o[0],t.next=3,h.createTensor("float32",new Float32Array(1536).fill(0),[1,16,96]);case 3:return r=t.sent,t.next=6,this.run(r);case 6:if(!(0<=(n=t.sent)&&n<=1)){t.next=11;break}e&&console.log("Wake Word model OK, executed in ".concat(this.duration," ms")),t.next=12;break;case 11:throw new Error("Wake Word model test failed - expected 0 <= x <= 1, got ".concat(n));case 12:case"end":return t.stop()}}),t,this)}))),function(){return a.apply(this,arguments)})},{key:"execute",value:(i=dt(ht().mark((function t(e){var r,n;return ht().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r={},3!==e.dims.length){t.next=5;break}r.input=e,t.next=8;break;case 5:return t.next=7,h.createTensor("float32",e.data,[1,e.dims[0],e.dims[1]]);case 7:r.input=t.sent;case 8:return t.next=10,this.session.run(r);case 10:return n=t.sent,t.abrupt("return",1*n.output.data[0]);case 12:case"end":return t.stop()}}),t,this)}))),function(t){return i.apply(this,arguments)})}],n&&yt(r.prototype,n),o&&yt(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r;var r,n,o,i,a}(P);function Et(t){return Et="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},Et(t)}function kt(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,a,c=[],u=!0,s=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=i.call(r)).done)&&(c.push(n.value),c.length!==e);u=!0);}catch(t){s=!0,o=t}finally{try{if(!u&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return c}}(t,e)||_t(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Lt(){Lt=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,o=Object.defineProperty||function(t,e,r){t[e]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function f(t,e,r,n){var i=e&&e.prototype instanceof m?e:m,a=Object.create(i.prototype),c=new T(n||[]);return o(a,"_invoke",{value:j(t,r,c)}),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=f;var h="suspendedStart",p="suspendedYield",d="executing",y="completed",v={};function m(){}function g(){}function b(){}var w={};s(w,a,(function(){return this}));var x=Object.getPrototypeOf,E=x&&x(x(N([])));E&&E!==r&&n.call(E,a)&&(w=E);var k=b.prototype=m.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function O(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==Et(f)&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e((function(e,o){r(t,n,e,o)}))}return i=i?i.then(o,o):o()}})}function j(e,r,n){var o=h;return function(i,a){if(o===d)throw Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=S(c,n);if(u){if(u===v)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===h)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=d;var s=l(e,r,n);if("normal"===s.type){if(o=n.done?y:p,s.arg===v)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function S(e,r){var n=r.method,o=e.iterator[n];if(o===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,S(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),v;var i=l(o,e.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,v;var a=i.arg;return a?a.done?(r[e.resultName]=a.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,v):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function N(e){if(e||""===e){var r=e[a];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,i=function r(){for(;++o<e.length;)if(n.call(e,o))return r.value=e[o],r.done=!1,r;return r.value=t,r.done=!0,r};return i.next=i}}throw new TypeError(Et(e)+" is not iterable")}return g.prototype=b,o(k,"constructor",{value:b,configurable:!0}),o(b,"constructor",{value:g,configurable:!0}),g.displayName=s(b,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,s(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},L(O.prototype),s(O.prototype,c,(function(){return this})),e.AsyncIterator=O,e.async=function(t,r,n,o,i){void 0===i&&(i=Promise);var a=new O(f(t,r,n,o),i);return e.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(k),s(k,u,"Generator"),s(k,a,(function(){return this})),s(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=N,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function o(n,o){return c.type="throw",c.arg=e,r.next=n,o&&(r.method="next",r.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),P(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;P(r)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:N(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),v}},e}function Ot(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function jt(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){Ot(i,n,o,a,c,"next",t)}function c(t){Ot(i,n,o,a,c,"throw",t)}a(void 0)}))}}function St(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=_t(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,c=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==r.return||r.return()}finally{if(c)throw i}}}}function _t(t,e){if(t){if("string"==typeof t)return Pt(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Pt(t,e):void 0}}function Pt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function Tt(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,Nt(n.key),n)}}function Nt(t){var e=function(t,e){if("object"!=Et(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=Et(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==Et(e)?e:e+""}var It=function(){return t=function t(e){var r=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),e=e||{},this.debug=e.debug||!1,this.positiveVadThreshold=e.positiveVadThreshold||.65,this.negativeVadThreshold=e.negativeVadThreshold||.4,this.negativeVadCount=e.negativeVadCount||8,this.wakeWordThreads=e.wakeWordThreads||4,this.wakeWordThreshold=e.wakeWordThreshold||.5,this.wakeWordInterval=e.wakeWordInterval||2;var n=e.modelPath||"/models/hey-buddy.onnx",o=Array.isArray(n)?n:[n],i=e.vadModelPath||"/pretrained/silero-vad.onnx",a=e.embeddingModelPath||"/pretrained/speech-embedding.ort",c=e.spectrogramModelPath||"/pretrained/mel-spectrogram.onnx",u=e.batchSeconds||1.08,s=e.batchIntervalSeconds||.12,f=e.workletUrl||"/worklet.js",l=e.workletName||"hey-buddy",h=e.targetSampleRate||16e3,p=e.spectrogramMelBins||32,d=e.embeddingDim||96,y=e.embeddingWindowSize||76,v=e.embeddingWindowStride||8,m=e.wakeWordEmbeddingFrames||16;this.batcher=new x(u,s,f,l,h),this.batcher.onBatch((function(t){return r.process(t)})),this.vad=new R(i),this.vad.test(this.debug),this.spectrogram=new Q(c),this.spectrogram.test(this.debug),this.spectrogramMelBins=p,this.spectrogramBuffer=null,this.embedding=new ft(a,d,y,v),this.embedding.test(this.debug),this.embeddingDim=d,this.embeddingWindowSize=y,this.embeddingWindowStride=v,this.embeddingBuffer=null,this.wakeWords={},this.wakeWordTimes={},this.wakeWordEmbeddingFrames=m;var g,b=St(o);try{for(b.s();!(g=b.n()).done;){var w=g.value,E=w.split("/").pop().split(".")[0];this.wakeWords[E]=new xt(w),this.wakeWords[E].test(this.debug)}}catch(t){b.e(t)}finally{b.f()}this.listening=!1,this.negatives=0,this.recording=!1,this.audioBuffer=null,this.frameIntervalEma=0,this.frameIntervalEmaWeight=.1,this.frameTimeEma=0,this.frameTimeEmaWeight=.1,this.speechStartCallbacks=[],this.speechEndCallbacks=[],this.recordingCallbacks=[],this.processedCallbacks=[],this.detectedCallbacks=[]},e=[{key:"chunkedWakeWords",get:function(){var t=this;return Object.keys(this.wakeWords).reduce((function(e,r,n){var o=Math.floor(n/t.wakeWordThreads);return e[o]||(e[o]=[]),e[o].push(r),e}),[])}},{key:"onDetected",value:function(t,e){this.detectedCallbacks.push({names:t,callback:e})}},{key:"onProcessed",value:function(t){this.processedCallbacks.push(t)}},{key:"onSpeechStart",value:function(t){this.speechStartCallbacks.push(t)}},{key:"onSpeechEnd",value:function(t){this.speechEndCallbacks.push(t)}},{key:"onRecording",value:function(t){this.recordingCallbacks.push(t)}},{key:"speechStart",value:function(){this.debug&&console.log("Speech start");var t,e=St(this.speechStartCallbacks);try{for(e.s();!(t=e.n()).done;)(0,t.value)()}catch(t){e.e(t)}finally{e.f()}}},{key:"speechEnd",value:function(){this.debug&&console.log("Speech end");var t,e=St(this.speechEndCallbacks);try{for(e.s();!(t=e.n()).done;)(0,t.value)()}catch(t){e.e(t)}finally{e.f()}this.recording&&(this.dispatchRecording(),this.recording=!1)}},{key:"dispatchRecording",value:function(){if(null!==this.audioBuffer){if(this.debug){var t=this.audioBuffer.length,e=t/this.batcher.workletTargetSampleRate;console.log("Dispatching recording for",name,"with",t,"frames (",e,"s)")}var r,n=St(this.recordingCallbacks);try{for(n.s();!(r=n.n()).done;)(0,r.value)(this.audioBuffer)}catch(t){n.e(t)}finally{n.f()}this.audioBuffer=null}else console.error("No recording to dispatch")}},{key:"wakeWordDetected",value:function(t){var e=Date.now();if(!(this.wakeWordTimes[t]&&e-this.wakeWordTimes[t]<1e3*this.wakeWordInterval)){this.debug&&console.log("Wake word detected:",t),this.recording=!0,this.wakeWordTimes[t]=e;var r,n=St(this.detectedCallbacks);try{for(n.s();!(r=n.n()).done;){var o=r.value,i=o.names,a=o.callback;(Array.isArray(i)&&i.includes(t)||i===t)&&a()}}catch(t){n.e(t)}finally{n.f()}}}},{key:"processed",value:function(t){var e,r=St(this.processedCallbacks);try{for(r.s();!(e=r.n()).done;)(0,e.value)(t)}catch(t){r.e(t)}finally{r.f()}}},{key:"checkWakeWordSubset",value:(i=jt(Lt().mark((function t(e){var r=this;return Lt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,Promise.all(e.map((function(t){return r.wakeWords[t].run(r.embeddingBuffer)})));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}}),t)}))),function(t){return i.apply(this,arguments)})},{key:"checkWakeWords",value:(o=jt(Lt().mark((function t(){var e,r,n,o,i,a,c,u,s;return Lt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e={},r=St(this.chunkedWakeWords),t.prev=2,r.s();case 4:if((n=r.n()).done){t.next=12;break}return o=n.value,t.next=8,this.checkWakeWordSubset(o);case 8:for(i=t.sent,a=0;a<o.length;a++)c=o[a],u=i[a],e[c]=u;case 10:t.next=4;break;case 12:t.next=17;break;case 14:t.prev=14,t.t0=t.catch(2),r.e(t.t0);case 17:return t.prev=17,r.f(),t.finish(17);case 20:for(s in e)e[s]>this.wakeWordThreshold&&this.wakeWordDetected(s);return t.abrupt("return",e);case 22:case"end":return t.stop()}}),t,this,[[2,14,17,20]])}))),function(){return o.apply(this,arguments)})},{key:"process",value:(n=jt(Lt().mark((function t(e){var r,n,o,i,a,c,u,s,f,l,p,d=this;return Lt().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return this.frameStart=(new Date).getTime(),void 0!==this.frameEnd&&null!==this.frameEnd?this.frameInterval=this.frameStart-this.frameEnd:this.frameInterval=0,0===this.frameIntervalEma?this.frameIntervalEma=this.frameInterval:this.frameIntervalEma=this.frameIntervalEma*(1-this.frameIntervalEmaWeight)+this.frameInterval*this.frameIntervalEmaWeight,r=e.subarray(e.length-this.batcher.batchIntervalSamples),t.next=6,this.vad.run(r);case 6:return n=t.sent,o=n>this.positiveVadThreshold,i=n<this.negativeVadThreshold,t.next=11,this.spectrogram.run(e);case 11:return a=t.sent,t.next=14,h.createTensor("float32",a.data,a.dims.slice(2));case 14:return this.spectrogramBuffer=t.sent,t.next=17,this.embedding.run(this.spectrogramBuffer);case 17:if(c=t.sent,null!==this.embeddingBuffer){t.next=24;break}return t.next=21,h.createTensor("float32",c.data,[c.dims[c.dims.length-2],this.embeddingDim]);case 21:this.embeddingBuffer=t.sent,t.next=45;break;case 24:if(!((u=this.embeddingBuffer.dims[0]+c.dims[0]-this.wakeWordEmbeddingFrames)>0)){t.next=39;break}if(!(this.embeddingBuffer.dims[0]<this.wakeWordEmbeddingFrames)){t.next=35;break}return(s=new Float32Array(this.wakeWordEmbeddingFrames*this.embeddingDim)).set(this.embeddingBuffer.data.subarray(u*this.embeddingDim)),s.set(c.data,this.wakeWordEmbeddingFrames-c.dims[0]),t.next=32,h.createTensor("float32",s,[this.wakeWordEmbeddingFrames,this.embeddingDim]);case 32:this.embeddingBuffer=t.sent,t.next=37;break;case 35:this.embeddingBuffer.data.set(this.embeddingBuffer.data.subarray(u*this.embeddingDim)),this.embeddingBuffer.data.set(c.data,this.embeddingBuffer.length-this.embeddingDim);case 37:t.next=45;break;case 39:return(f=new Float32Array(this.embeddingBuffer.data.length+c.data.length)).set(this.embeddingBuffer.data),f.set(c.data,this.embeddingBuffer.data.length),t.next=44,h.createTensor("float32",f,[this.embeddingBuffer.dims[0]+c.dims[0],this.embeddingDim]);case 44:this.embeddingBuffer=t.sent;case 45:if(o?(this.negatives=0,this.listening||this.speechStart(),this.listening=!0):(i&&(this.negatives+=1),this.negatives>this.negativeVadCount&&(this.listening&&this.speechEnd(),this.listening=!1)),!this.listening||this.embeddingBuffer.dims[0]!==this.wakeWordEmbeddingFrames){t.next=53;break}return t.next=49,this.checkWakeWords();case 49:l=t.sent,this.processed({listening:!0,recording:this.recording,speech:{probability:n,active:o},wakeWords:Object.entries(l).reduce((function(t,e){var r=kt(e,2),n=r[0],o=r[1];return t[n]={probability:o,active:o>d.wakeWordThreshold},t}),{})}),t.next=54;break;case 53:this.processed({listening:!1,recording:this.recording,speech:{probability:n,active:o},wakeWords:Object.entries(this.wakeWords).reduce((function(t,e){var r=kt(e,2),n=r[0];return r[1],t[n]={probability:0,active:!1},t}),{})});case 54:this.recording&&(null===this.audioBuffer?(this.audioBuffer=new Float32Array(e.length),this.audioBuffer.set(e)):((p=new Float32Array(this.audioBuffer.length+r.length)).set(this.audioBuffer),p.set(r,this.audioBuffer.length),this.audioBuffer=p)),this.frameEnd=(new Date).getTime(),this.frameTime=this.frameEnd-this.frameStart,0===this.frameTimeEma?this.frameTimeEma=this.frameTime:this.frameTimeEma=this.frameTimeEma*(1-this.frameTimeEmaWeight)+this.frameTime*this.frameTimeEmaWeight;case 58:case"end":return t.stop()}}),t,this)}))),function(t){return n.apply(this,arguments)})}],e&&Tt(t.prototype,e),r&&Tt(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,r,n,o,i}();return window.HeyBuddy=It,e})()));
|
logo.png
ADDED
production.html
ADDED
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Hey, Buddy!</title>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/onnxruntime-web@1.19.0/dist/ort.min.js"></script>
|
8 |
+
<script src="dist/hey-buddy.min.js"></script>
|
9 |
+
<style>
|
10 |
+
body {
|
11 |
+
display: flex;
|
12 |
+
flex-flow: column nowrap;
|
13 |
+
justify-content: center;
|
14 |
+
align-items: center;
|
15 |
+
height: 100vh;
|
16 |
+
width: 100vw;
|
17 |
+
padding: 0;
|
18 |
+
margin: 0;
|
19 |
+
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
20 |
+
background-color: rgb(11,15,25);
|
21 |
+
color: white
|
22 |
+
}
|
23 |
+
|
24 |
+
h1 {
|
25 |
+
font-size: 16px;
|
26 |
+
margin-top: 0;
|
27 |
+
}
|
28 |
+
|
29 |
+
p {
|
30 |
+
font-size: 15px;
|
31 |
+
margin-bottom: 10px;
|
32 |
+
margin-top: 5px;
|
33 |
+
}
|
34 |
+
|
35 |
+
strong, em {
|
36 |
+
color: #16c8ce;
|
37 |
+
}
|
38 |
+
|
39 |
+
.card {
|
40 |
+
max-width: 640px;
|
41 |
+
margin: 0 auto;
|
42 |
+
padding: 16px;
|
43 |
+
border: 1px solid rgb(107, 114, 128);
|
44 |
+
border-radius: 16px;
|
45 |
+
background-color: rgb(16, 22, 35);
|
46 |
+
}
|
47 |
+
|
48 |
+
.card p:last-child {
|
49 |
+
margin-bottom: 0;
|
50 |
+
}
|
51 |
+
|
52 |
+
.card img {
|
53 |
+
width: 100%;
|
54 |
+
max-width: 420px;
|
55 |
+
margin: 0 auto;
|
56 |
+
}
|
57 |
+
|
58 |
+
#logo, #links {
|
59 |
+
display: flex;
|
60 |
+
flex-flow: row wrap;
|
61 |
+
justify-content: center;
|
62 |
+
}
|
63 |
+
|
64 |
+
#links {
|
65 |
+
gap: 1em;
|
66 |
+
margin: 1em;
|
67 |
+
}
|
68 |
+
|
69 |
+
#links img {
|
70 |
+
height: 20px;
|
71 |
+
}
|
72 |
+
|
73 |
+
#graphs {
|
74 |
+
display: flex;
|
75 |
+
flex-flow: column nowrap;
|
76 |
+
justify-content: center;
|
77 |
+
align-items: center;
|
78 |
+
gap: 1em;
|
79 |
+
}
|
80 |
+
|
81 |
+
label {
|
82 |
+
display: block;
|
83 |
+
}
|
84 |
+
|
85 |
+
#graphs div {
|
86 |
+
position: relative;
|
87 |
+
}
|
88 |
+
|
89 |
+
#graphs label {
|
90 |
+
position: absolute;
|
91 |
+
right: 0;
|
92 |
+
top: 0;
|
93 |
+
max-width: 120px;
|
94 |
+
text-transform: uppercase;
|
95 |
+
font-family: monospace;
|
96 |
+
text-align: right;
|
97 |
+
padding: 0 4px;
|
98 |
+
line-height: 20px;
|
99 |
+
background-image: linear-gradient(to top, rgba(255,255,255,0.1), rgba(255,255,255,0.0));
|
100 |
+
border: 1px solid rgba(255,255,255,0.1);
|
101 |
+
border-top: none;
|
102 |
+
border-right: none;
|
103 |
+
}
|
104 |
+
|
105 |
+
#graphs .legend {
|
106 |
+
display: flex;
|
107 |
+
flex-flow: row wrap;
|
108 |
+
justify-content: flex-end;
|
109 |
+
gap: 1px 5px;
|
110 |
+
text-transform: uppercase;
|
111 |
+
font-family: monospace;
|
112 |
+
font-size: 10px;
|
113 |
+
line-height: 11px;
|
114 |
+
}
|
115 |
+
|
116 |
+
canvas.graph {
|
117 |
+
border: 1px solid rgba(255,255,255,0.1);
|
118 |
+
border-bottom: none;
|
119 |
+
background-image:
|
120 |
+
repeating-linear-gradient(to top, rgba(255,255,255,0.05), rgba(255,255,255,0.05) 1px, transparent 1px, transparent 10px),
|
121 |
+
linear-gradient(to top, rgba(255,255,255,0.1), rgba(255,255,255,0.0));
|
122 |
+
}
|
123 |
+
|
124 |
+
#recording {
|
125 |
+
margin-top: 1em;
|
126 |
+
position: relative;
|
127 |
+
display: block;
|
128 |
+
height: 100px;
|
129 |
+
line-height: 100px;
|
130 |
+
text-align: center;
|
131 |
+
font-size: 11px;
|
132 |
+
background-image: linear-gradient(to top, rgba(255,255,255,0.1), rgba(255,255,255,0.0));
|
133 |
+
border: 1px solid rgba(255,255,255,0.1);
|
134 |
+
border-bottom-left-radius: 10px;
|
135 |
+
border-bottom-right-radius: 10px;
|
136 |
+
}
|
137 |
+
|
138 |
+
#recording #audio {
|
139 |
+
display: flex;
|
140 |
+
flex-flow: row nowrap;
|
141 |
+
align-items: center;
|
142 |
+
justify-content: center;
|
143 |
+
height: 100%;
|
144 |
+
}
|
145 |
+
|
146 |
+
#recording label {
|
147 |
+
position: absolute;
|
148 |
+
right: 0;
|
149 |
+
top: 0;
|
150 |
+
max-width: 120px;
|
151 |
+
text-transform: uppercase;
|
152 |
+
font-family: monospace;
|
153 |
+
font-size: 12px;
|
154 |
+
text-align: right;
|
155 |
+
padding: 0 4px;
|
156 |
+
line-height: 20px;
|
157 |
+
background-image: linear-gradient(to top, rgba(255,255,255,0.1), rgba(255,255,255,0.0));
|
158 |
+
border: 1px solid rgba(255,255,255,0.1);
|
159 |
+
border-top: none;
|
160 |
+
border-right: none;
|
161 |
+
}
|
162 |
+
</style>
|
163 |
+
</head>
|
164 |
+
<body>
|
165 |
+
<div class="card">
|
166 |
+
<section id="logo">
|
167 |
+
<img src="logo.png" alt="Hey Buddy!" />
|
168 |
+
</section>
|
169 |
+
<section id="headline">
|
170 |
+
<p><strong><em>Hey Buddy!</em></strong> is a library for training wake word models (a.k.a audio keyword spotters) and deploying them to the browser for real-time use on CPU or GPU.</p>
|
171 |
+
<p>Using a wake-word as a gating mechanism for voice-enabled web applications carries numerous benefits, including reduced power consumption, improved privacy, and enhanced performance in noisy environments over speech-to-text systems.</p>
|
172 |
+
<p>This space serves as a demonstration of the JavaScript library for front-end applications. Say something like, <em>“Hey buddy, how are you?”</em> to see the wake word and voice activity detection in action. Your voice command will be isolated as an audio clip, which is then ready to be sent to your application's backend for further processing.</p>
|
173 |
+
</section>
|
174 |
+
<section id="links">
|
175 |
+
<a href="https://github.com/painebenjamin/hey-buddy" target="_blank">
|
176 |
+
<img src="https://img.shields.io/static/v1?label=painebenjamin&message=hey-buddy&logo=github&color=0b1830" alt="painebenjamin - hey-buddy" />
|
177 |
+
</a>
|
178 |
+
<a href="https://huggingface.co/benjamin-paine/hey-buddy" target="_blank">
|
179 |
+
<img src="https://img.shields.io/static/v1?label=benjamin-paine&message=hey-buddy&logo=huggingface&color=0b1830" alt="painebenjamin - hey-buddy" />
|
180 |
+
</a>
|
181 |
+
</section>
|
182 |
+
<section id="graphs"></section>
|
183 |
+
<section id="recording">
|
184 |
+
<label>Recording</label>
|
185 |
+
<div id="audio">No recording yet</div>
|
186 |
+
</section>
|
187 |
+
</div>
|
188 |
+
</body>
|
189 |
+
<script>
|
190 |
+
/** Configuration */
|
191 |
+
const colors = {
|
192 |
+
"buddy": [0,119,187],
|
193 |
+
"hey buddy": [51,187,238],
|
194 |
+
"hi buddy": [0,153,136],
|
195 |
+
"sup buddy": [238,119,51],
|
196 |
+
"yo buddy": [204,51,17],
|
197 |
+
"okay buddy": [238,51,119],
|
198 |
+
"speech": [22,200,206],
|
199 |
+
"frame budget": [25,255,25]
|
200 |
+
};
|
201 |
+
const wakeWords = ["buddy", "hey buddy", "hi buddy", "sup buddy", "yo buddy", "okay buddy"];
|
202 |
+
const canvasSize = { width: 640, height: 100 };
|
203 |
+
const graphLineWidth = 1;
|
204 |
+
const options = {
|
205 |
+
debug: true,
|
206 |
+
modelPath: wakeWords.map((word) => `/models/${word.replace(' ', '-')}.onnx`)
|
207 |
+
};
|
208 |
+
|
209 |
+
/** Helper method for conversion */
|
210 |
+
const float32ToWavBlob = (audioData, sampleRate, numChannels = 1) => {
|
211 |
+
// Helper to write a string to the DataView
|
212 |
+
const writeString = (view, offset, string) => {
|
213 |
+
for (let i = 0; i < string.length; i++) {
|
214 |
+
view.setUint8(offset + i, string.charCodeAt(i));
|
215 |
+
}
|
216 |
+
};
|
217 |
+
|
218 |
+
// Helper to convert Float32Array to Int16Array (16-bit PCM)
|
219 |
+
const floatTo16BitPCM = (output, offset, input) => {
|
220 |
+
for (let i = 0; i < input.length; i++, offset += 2) {
|
221 |
+
let s = Math.max(-1, Math.min(1, input[i])); // Clamping to [-1, 1]
|
222 |
+
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true); // Convert to 16-bit PCM
|
223 |
+
}
|
224 |
+
};
|
225 |
+
|
226 |
+
const byteRate = sampleRate * numChannels * 2; // 16-bit PCM = 2 bytes per sample
|
227 |
+
|
228 |
+
// Calculate sizes
|
229 |
+
const blockAlign = numChannels * 2; // 2 bytes per sample for 16-bit audio
|
230 |
+
const wavHeaderSize = 44;
|
231 |
+
const dataLength = audioData.length * numChannels * 2; // 16-bit PCM data length
|
232 |
+
const buffer = new ArrayBuffer(wavHeaderSize + dataLength);
|
233 |
+
const view = new DataView(buffer);
|
234 |
+
|
235 |
+
// Write WAV file headers
|
236 |
+
writeString(view, 0, 'RIFF'); // ChunkID
|
237 |
+
view.setUint32(4, 36 + dataLength, true); // ChunkSize
|
238 |
+
writeString(view, 8, 'WAVE'); // Format
|
239 |
+
writeString(view, 12, 'fmt '); // Subchunk1ID
|
240 |
+
view.setUint32(16, 16, true); // Subchunk1Size (PCM = 16)
|
241 |
+
view.setUint16(20, 1, true); // AudioFormat (PCM = 1)
|
242 |
+
view.setUint16(22, numChannels, true); // NumChannels
|
243 |
+
view.setUint32(24, sampleRate, true); // SampleRate
|
244 |
+
view.setUint32(28, byteRate, true); // ByteRate
|
245 |
+
view.setUint16(32, blockAlign, true); // BlockAlign
|
246 |
+
view.setUint16(34, 16, true); // BitsPerSample (16-bit PCM)
|
247 |
+
writeString(view, 36, 'data'); // Subchunk2ID
|
248 |
+
view.setUint32(40, dataLength, true); // Subchunk2Size
|
249 |
+
|
250 |
+
// Convert the Float32Array audio samples to 16-bit PCM and write them to the DataView
|
251 |
+
floatTo16BitPCM(view, wavHeaderSize, audioData);
|
252 |
+
|
253 |
+
// Create and return the Blob
|
254 |
+
return new Blob([view], { type: 'audio/wav' });
|
255 |
+
}
|
256 |
+
|
257 |
+
/** Helper method for turning the audio samples into an audio element */
|
258 |
+
const saveRecording = (audioContainer, audioSamples, sampleRate = 16000) => {
|
259 |
+
const blob = float32ToWavBlob(audioSamples, sampleRate);
|
260 |
+
const url = URL.createObjectURL(blob);
|
261 |
+
audioContainer.innerHTML = `<audio controls src="${url}"></audio>`;
|
262 |
+
}
|
263 |
+
|
264 |
+
/** DOM elements */
|
265 |
+
const graphsContainer = document.getElementById("graphs");
|
266 |
+
const audioContainer = document.getElementById("audio");
|
267 |
+
|
268 |
+
/** Memory for drawing */
|
269 |
+
const graphs = {};
|
270 |
+
const history = {};
|
271 |
+
const current = {};
|
272 |
+
const active = {};
|
273 |
+
|
274 |
+
/** Instantiate */
|
275 |
+
const heyBuddy = new HeyBuddy(options);
|
276 |
+
|
277 |
+
/** Add callbacks */
|
278 |
+
|
279 |
+
// When processed, update state for next draw
|
280 |
+
heyBuddy.onProcessed((result) => {
|
281 |
+
current["frame budget"] = heyBuddy.frameTimeEma;
|
282 |
+
current["speech"] = result.speech.probability || 0.0;
|
283 |
+
active["speech"] = result.speech.active;
|
284 |
+
for (let wakeWord in result.wakeWords) {
|
285 |
+
current[wakeWord.replace('-', ' ')] = result.wakeWords[wakeWord].probability || 0.0;
|
286 |
+
active[wakeWord.replace('-', ' ')] = result.wakeWords[wakeWord].active;
|
287 |
+
}
|
288 |
+
if (result.recording) {
|
289 |
+
audioContainer.innerHTML = "Recording…";
|
290 |
+
}
|
291 |
+
});
|
292 |
+
|
293 |
+
// When recording is complete, replace the audio element
|
294 |
+
heyBuddy.onRecording((audioSamples) => {
|
295 |
+
saveRecording(audioContainer, audioSamples);
|
296 |
+
});
|
297 |
+
|
298 |
+
/** Add graphs */
|
299 |
+
for (let graphName of ["wake words", "speech", "frame budget"]) {
|
300 |
+
// Create containers for the graph and its label
|
301 |
+
const graphContainer = document.createElement("div");
|
302 |
+
const graphLabel = document.createElement("label");
|
303 |
+
graphLabel.textContent = graphName;
|
304 |
+
|
305 |
+
// Create a canvas for the graph
|
306 |
+
const graphCanvas = document.createElement("canvas");
|
307 |
+
graphCanvas.className = "graph";
|
308 |
+
graphCanvas.width = canvasSize.width;
|
309 |
+
graphCanvas.height = canvasSize.height;
|
310 |
+
graphs[graphName] = graphCanvas;
|
311 |
+
|
312 |
+
// Add the canvas to the container and the container to the document
|
313 |
+
graphContainer.appendChild(graphCanvas);
|
314 |
+
graphContainer.appendChild(graphLabel);
|
315 |
+
graphsContainer.appendChild(graphContainer);
|
316 |
+
|
317 |
+
// If this is the wake-word graph, also add legend
|
318 |
+
if (graphName === "wake words") {
|
319 |
+
const graphLegend = document.createElement("div");
|
320 |
+
graphLegend.className = "legend";
|
321 |
+
for (let wakeWord of wakeWords) {
|
322 |
+
const legendItem = document.createElement("div");
|
323 |
+
const [r,g,b] = colors[wakeWord];
|
324 |
+
legendItem.style.color = `rgb(${r},${g},${b})`;
|
325 |
+
legendItem.textContent = wakeWord;
|
326 |
+
graphLegend.appendChild(legendItem);
|
327 |
+
}
|
328 |
+
graphLabel.appendChild(graphLegend);
|
329 |
+
}
|
330 |
+
}
|
331 |
+
|
332 |
+
/** Define draw loop */
|
333 |
+
const draw = () => {
|
334 |
+
// Draw speech and model graphs
|
335 |
+
for (let graphName in graphs) {
|
336 |
+
const isWakeWords = graphName === "wake words";
|
337 |
+
const isFrameBudget = graphName === "frame budget";
|
338 |
+
const subGraphs = isWakeWords ? wakeWords : [graphName];
|
339 |
+
|
340 |
+
let isFirst = true;
|
341 |
+
for (let name of subGraphs) {
|
342 |
+
// Update history
|
343 |
+
history[name] = history[name] || [];
|
344 |
+
if (isFrameBudget) {
|
345 |
+
history[name].push((current[name] || 0.0) / 120.0); // 120ms budget
|
346 |
+
} else {
|
347 |
+
history[name].push(current[name] || 0.0);
|
348 |
+
}
|
349 |
+
|
350 |
+
// Trim history
|
351 |
+
if (history[name].length > canvasSize.width) {
|
352 |
+
history[name] = history[name].slice(history[name].length - canvasSize.width);
|
353 |
+
}
|
354 |
+
|
355 |
+
// Draw graph
|
356 |
+
const canvas = graphs[graphName];
|
357 |
+
const ctx = canvas.getContext("2d");
|
358 |
+
const [r,g,b] = colors[name];
|
359 |
+
const opacity = isFrameBudget || active[name] ? 1.0 : 0.5;
|
360 |
+
|
361 |
+
if (isFirst) {
|
362 |
+
// Clear canvas on first draw
|
363 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
364 |
+
isFirst = false;
|
365 |
+
}
|
366 |
+
|
367 |
+
ctx.strokeStyle = `rgba(${r},${g},${b},${opacity})`;
|
368 |
+
ctx.fillStyle = `rgba(${r},${g},${b},${opacity/2})`;
|
369 |
+
ctx.lineWidth = graphLineWidth;
|
370 |
+
|
371 |
+
// Draw from left to right (the frame shifts right to left)
|
372 |
+
ctx.beginPath();
|
373 |
+
let lastX;
|
374 |
+
for (let i = 0; i < history[name].length; i++) {
|
375 |
+
const x = i;
|
376 |
+
const y = canvas.height - history[name][i] * canvas.height;
|
377 |
+
if (i === 0) {
|
378 |
+
ctx.moveTo(1, y);
|
379 |
+
} else {
|
380 |
+
ctx.lineTo(x, y);
|
381 |
+
}
|
382 |
+
lastX = x;
|
383 |
+
}
|
384 |
+
// extend downwards to make a polygon
|
385 |
+
ctx.lineTo(lastX, canvas.height);
|
386 |
+
ctx.lineTo(0, canvas.height);
|
387 |
+
ctx.closePath();
|
388 |
+
ctx.fill();
|
389 |
+
ctx.stroke();
|
390 |
+
}
|
391 |
+
}
|
392 |
+
|
393 |
+
// Request next frame
|
394 |
+
requestAnimationFrame(draw);
|
395 |
+
};
|
396 |
+
|
397 |
+
/** Start the loop */
|
398 |
+
requestAnimationFrame(draw);
|
399 |
+
</script>
|
400 |
+
</html>
|