formantanalyzer
Version:
Extract formant features such as frequency, power, energy, and bandwidth of formants at syllable or word level from audio sources in a web browser using WebAudio API.
1 lines • 115 kB
JavaScript
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.FormantAnalyzer=n():e.FormantAnalyzer=n()}(this,(function(){return function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var i in e)r.d(t,i,function(n){return e[n]}.bind(null,i));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=1)}([function(e,n,r){"use strict";r.r(n),r.d(n,"solve_poly",(function(){return t})),r.d(n,"mean_std",(function(){return i})),r.d(n,"only_std",(function(){return o})),r.d(n,"only_std_NZ",(function(){return c})),r.d(n,"mean_std_NZ",(function(){return u})),r.d(n,"array_mean_NZ",(function(){return a})),r.d(n,"arraySum",(function(){return s})),r.d(n,"arrayMax",(function(){return l})),r.d(n,"only_mean",(function(){return f})),r.d(n,"covariance",(function(){return m})),r.d(n,"variance",(function(){return p}));var t=function(e,n){let r=0;for(let t=0;t<e.length;t++)r+=e[t]*Math.pow(n,t);return r};const i=(e,n=!1)=>{const r=e.reduce((e,n)=>e+n,0)/e.length;return[r,Math.sqrt(e.reduce((e,n)=>e.concat((n-r)**2),[]).reduce((e,n)=>e+n,0)/(e.length-(n?0:1)))]},o=(e,n=!1)=>{const r=e.reduce((e,n)=>e+n,0)/e.length;return Math.sqrt(e.reduce((e,n)=>e.concat((n-r)**2),[]).reduce((e,n)=>e+n,0)/(e.length-(n?0:1)))},c=e=>{const n=a(e);return Math.sqrt(e.reduce((e,r)=>e.concat((r-n)**2),[]).reduce((e,n)=>e+n,0)/e.length)},u=e=>{const n=a(e);return[n,Math.sqrt(e.reduce((e,r)=>e.concat((r-n)**2),[]).reduce((e,n)=>e+n,0)/e.length)]};function a(e){let n=0,r=0;for(let t in e)e[t]>0&&(n+=e[t],r++);return n/r}function s(e){let n=0;for(let r in e)n+=e[r];return n}function l(e){let n=e.length,r=-1/0;for(;n--;)e[n]>r&&(r=e[n]);return r}const f=e=>e.reduce((e,n)=>e+n,0)/e.length;function m(e,n){const r=e.length;e.length!=r&&console.error("Unequal samples");const t=f(e),i=f(n);let o=0;for(let c=0;c<r;c++)o+=(e[c]-t)*(n[c]-i);return o/=r,o}function p(e){const n=e.length,r=f(e);let t=0;for(let i=0;i<n;i++)t+=Math.pow(e[i]-r,2);return t/=n,t}},function(e,n,r){"use strict";r.r(n),r.d(n,"configure",(function(){return o})),r.d(n,"LaunchAudioNodes",(function(){return c})),r.d(n,"StopAudioNodes",(function(){return u})),r.d(n,"set_predicted_label_for_segment",(function(){return a}));const t=r(2);let i={plot_enable:!1,spec_type:1,output_level:4,plot_len:200,f_min:50,f_max:4e3,N_fft_bins:256,N_mel_bins:128,window_width:25,window_step:25,pause_length:200,min_seg_length:50,auto_noise_gate:!0,voiced_max_dB:100,voiced_min_dB:10,plot_lag:1,pre_norm_gain:1e3,high_f_emph:0,plot_canvas:null,canvas_width:200,canvas_height:100};function o(e){if(null!==e.spec_type&&(i.spec_type=e.spec_type),e.output_level&&(i.output_level=e.output_level),null!==e.f_min&&(i.f_min=e.f_min),e.f_max&&(i.f_max=e.f_max),e.N_fft_bins&&(i.N_fft_bins=e.N_fft_bins),e.N_mel_bins&&(i.N_mel_bins=e.N_mel_bins),e.window_width&&(i.window_width=e.window_width),e.window_step&&(i.window_step=e.window_step),e.pre_norm_gain&&(i.pre_norm_gain=e.pre_norm_gain),null!==e.high_f_emph&&(i.high_f_emph=e.high_f_emph),e.pause_length&&(i.pause_length=e.pause_length),e.min_seg_length&&(i.min_seg_length=e.min_seg_length),null!==e.auto_noise_gate&&(i.auto_noise_gate=e.auto_noise_gate),e.voiced_max_dB&&(i.voiced_max_dB=e.voiced_max_dB),null!==e.voiced_min_dB&&(i.voiced_min_dB=e.voiced_min_dB),e.plot_enable&&e.plot_canvas){i.plot_enable=e.plot_enable,i.plot_canvas=e.plot_canvas,e.plot_len&&(i.plot_len=e.plot_len),e.plot_lag&&(i.plot_lag=e.plot_lag),e.canvas_width&&(i.canvas_width=e.canvas_width),e.canvas_height&&(i.canvas_height=e.canvas_height);let n=1==i.spec_type?i.N_mel_bins:i.N_fft_bins;t.reset_plot(i.plot_enable,i.plot_canvas,i.canvas_width,i.canvas_height,i.spec_type,i.output_level,i.plot_len,n,i.plot_lag)}else i.plot_enable=!1}function c(e,n=null,r=null,o=[],c=!1,u=!0,a=null,s=null){return new Promise((l,f)=>{t.isNodePlaying()?f("Error: Already playing"):t.reset_nodes(i.spec_type,i.f_min,i.f_max,i.N_fft_bins,i.N_mel_bins,i.window_width,i.window_step,i.pre_norm_gain,i.high_f_emph).then((function(){let m=1==i.spec_type?i.N_mel_bins:i.N_fft_bins;t.reset_segmentor(i.output_level,m,i.plot_len,i.window_step,i.pause_length,i.min_seg_length,i.auto_noise_gate,i.voiced_max_dB,i.voiced_min_dB,r,u,o).then((function(){let r=1==i.spec_type?i.N_mel_bins:i.N_fft_bins;t.reset_plot(i.plot_enable,i.plot_canvas,i.canvas_width,i.canvas_height,i.spec_type,i.output_level,i.plot_len,r,i.plot_lag).then((function(){1==e&&n?c?(t.Garbage_Collect(),t.offline_play_the_file(n,a,s).then((function(){l(!0)})).catch(e=>{console.error(e),f(e)})):t.online_play_the_file(n,a,s).then((function(){l(!0)})).catch(e=>{console.error(e),f(e)}):2==e&&n?t.online_play_the_sop(n,a,s).then((function(){l(!0)})).catch(e=>{console.error(e),f(e)}):3==e?t.online_play_the_mic().then((function(){l(!0)})).catch(e=>{console.error(e),f(e)}):f("Invalid audio source")})).catch(e=>{console.error(e),f(e)})})).catch(e=>{console.error(e),f(e)})})).catch(e=>{console.error(e),f(e)})})}function u(e="no reason"){t.disconnect_nodes(e)}function a(e,n,r){t.set_predicted_label_for_segment(e,n,r)}},function(e,n,r){"use strict";r.r(n),r.d(n,"reset_nodes",(function(){return s})),r.d(n,"reset_segmentor",(function(){return l})),r.d(n,"reset_plot",(function(){return f})),r.d(n,"online_play_the_mic",(function(){return m})),r.d(n,"online_play_the_sop",(function(){return p})),r.d(n,"online_play_the_file_TryFFT",(function(){return d})),r.d(n,"online_play_the_file",(function(){return h})),r.d(n,"Garbage_Collect",(function(){return _})),r.d(n,"offline_play_the_file",(function(){return g})),r.d(n,"disconnect_nodes",(function(){return y})),r.d(n,"isNodePlaying",(function(){return v})),r.d(n,"set_predicted_label_for_segment",(function(){return k}));const t=r(3),i=r(8),o="https://unpkg.com/formantanalyzer@1.1.8/analyzernode.min.js";window.AudioContext=window.webkitAudioContext||window.AudioContext||window.mozAudioContext;var c={audioPlaying:0,PlayMode:0,last_node_ms:0,frames_ack:0,frames_analyzed:0,spec_bands:-1},u={spec_type:1,f_min:50,f_max:4e3,N_fft_bins:256,N_mel_bins:128,window_width:25,window_step:25,pre_norm_gain:1e3,high_f_emph:.05},a={plot_enable:!1,spec_type:1,process_level:4,plot_len:500,bins_count:128,bins_y_labels:[],axis_labels_sep:3,last_seg_len:0,plot_lag:3};function s(e,n,r,t,i,o,a,s,l){return new Promise((f,m)=>{i|t?(c.spec_bands=1==e?i:t,c.frames_ack=0,c.frames_analyzed=0,c.PlayMode=0,u.spec_type=e,u.f_min=n,u.f_max=r,u.N_fft_bins=t,u.N_mel_bins=i,u.window_width=o,u.window_step=a,u.pre_norm_gain=s,u.high_f_emph=l,f("ready")):m("Invalid reset_nodes config")})}function l(e,n,r=200,i=15,o=200,c=50,u=!0,a=150,s=50,l=null,f=!0,m=[]){return new Promise((p,d)=>{t.reset_segmentation(e,n,r,i,o,c,u,a,s,l,f,m).then((function(){p("ready")})).catch((function(e){d("reset_segmentor failed: "+e)}))})}function f(e=!1,n=null,r=800,t=400,o=1,c=0,u=100,s=64,l=0){return new Promise((f,m)=>{c?(e&&n?(a.plot_enable=!0,a.spec_type=o,a.process_level=c,a.plot_len=u,a.plot_lag=l,a.last_seg_len=0,a.bins_y_labels=[],a.bins_count=s,a.bins_count>32?a.axis_labels_sep=Math.round(a.bins_count/32):a.axis_labels_sep=0,i.init_canvas(n,r,t,u,s),i.clear_plot()):a.plot_enable=!1,f("ready")):m("Invalid reset_plot config")})}function m(){return new Promise((e,n)=>{var r,i,s;try{r=new AudioContext,i=null;let l={audio:!0,video:!1};navigator.mediaDevices.getUserMedia(l).then(l=>{i=r.createMediaStreamSource(l),c.audioPlaying=1,r.audioWorklet.addModule(o).then((function(){(s=new AudioWorkletNode(r,"spectrum-processor")).port.onmessage=o=>{if(Number.isInteger(o.data)?1==o.data&&(c.frames_ack+=o.data,c.frames_ack>c.frames_analyzed&&s&&s.port.postMessage(1)):o.data.bins_Hz?(a.bins_y_labels=o.data.bins_Hz,(c.spec_bands<=0||c.spec_bands!=a.bins_y_labels.length)&&n("Bins Init mismatch: "+String(c.spec_bands)+", "+String(a.bins_y_labels.length))):Uint32Array.prototype.isPrototypeOf(o.data)&&o.data.length>0&&(c.spec_bands<=0||c.spec_bands!=o.data.length?n("Bins count mismatch: "+String(c.spec_bands)+", "+String(o.data.length)):(t.spectrum_push(o.data,c.frames_analyzed),a.plot_enable&&requestAnimFrame(M),c.frames_analyzed++)),2==c.audioPlaying&&c.frames_analyzed>=c.frames_ack||-1==c.audioPlaying){-1==c.audioPlaying?console.log("Mic stream end by disconnect"):console.log("Mic stream end normal (b)"),c.audioPlaying=0,s&&s.port.postMessage(22);try{i.stop(0)}catch(o){}try{i.disconnect(s)}catch(o){}try{s.disconnect(r.destination)}catch(o){}r&&"closed"!=r.state&&r.close(),i=null,s=null,r=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),e("complete_d")}},s.port.postMessage(u),s.port.postMessage(0),i.onended=function(){console.log("Mic stream ended"),c.audioPlaying=2,s&&s.port.postMessage(22);try{i.stop(0)}catch(e){}try{i.disconnect(s)}catch(e){}if(i=null,c.frames_analyzed>=c.frames_ack&&0!=c.audioPlaying){console.log("Mic stream end normal"),c.audioPlaying=0;try{s.disconnect(r.destination)}catch(e){}r&&"closed"!=r.state&&r.close(),s=null,r=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),e("complete")}};try{i.connect(s),s.connect(r.destination),c.PlayMode=3}catch(e){console.log("File loading failed: "+e);try{i.stop(0)}catch(e){}try{i.disconnect(s)}catch(e){}try{s.disconnect(r.destination)}catch(e){}i=null,s=null,r=null,c.audioPlaying=0,n("Context connection failed: "+e)}})).catch((function(e){c.audioPlaying=0,i=null,r=null,console.log("workletNode loading failed: "+e),n("workletNode loading failed: "+e)}))}).catch(e=>{n(e)})}catch(e){alert("Web Audio API is not supported in this browser"),n("Not supported")}})}function p(e,n=null,r=null){return new Promise((i,s)=>{var l,f,m;try{l=new(window.AudioContext||window.webkitAudioContext),f=null,f=l.createMediaElementSource(e),c.audioPlaying=1,l.audioWorklet.addModule(o).then((function(){(m=new AudioWorkletNode(l,"spectrum-processor")).port.onmessage=e=>{if(Number.isInteger(e.data)?1==e.data&&(c.frames_ack+=e.data,c.frames_ack>c.frames_analyzed&&m&&m.port.postMessage(1)):e.data.bins_Hz?(a.bins_y_labels=e.data.bins_Hz,(c.spec_bands<=0||c.spec_bands!=a.bins_y_labels.length)&&s("Bins Init mismatch: "+String(c.spec_bands)+", "+String(a.bins_y_labels.length))):Uint32Array.prototype.isPrototypeOf(e.data)&&e.data.length>0&&(c.spec_bands<=0||c.spec_bands!=e.data.length?s("Bins count mismatch: "+String(c.spec_bands)+", "+String(e.data.length)):(t.spectrum_push(e.data,c.frames_analyzed),a.plot_enable&&requestAnimFrame(M),c.frames_analyzed++)),2==c.audioPlaying&&c.frames_analyzed>=c.frames_ack||-1==c.audioPlaying){-1==c.audioPlaying?console.log("Demo stream end by disconnect"):console.log("Demo stream end normal (b)"),c.audioPlaying=0,m&&m.port.postMessage(22);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}try{m.disconnect(l.destination)}catch(e){}l&&"closed"!=l.state&&l.close(),f=null,m=null,l=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),i("complete_d")}c.last_node_ms=Date.now()},m.port.postMessage(u),m.port.postMessage(0),f.onended=function(){console.log("Demo stream ended"),c.audioPlaying=2,m&&m.port.postMessage(22);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}if(f=null,c.frames_analyzed>=c.frames_ack&&0!=c.audioPlaying){console.log("Demo stream end normal"),c.audioPlaying=0;try{m.disconnect(l.destination)}catch(e){}l&&"closed"!=l.state&&l.close(),m=null,l=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),i("complete")}},window.setTimeout((function e(){if(0!=c.audioPlaying&&1!=c.audioPlaying&&Date.now()-c.last_node_ms<2e3){setTimeout(e,250);try{m.port.postMessage(22)}catch(e){}}else if(2==c.audioPlaying&&m){try{m.port.postMessage(22)}catch(e){}c.audioPlaying=0,c.last_node_ms=0,console.warn("Worklet is stuck. Terminating."),f=null,m=null,l=null,i(2)}else-1==c.audioPlaying&&(f=null,m=null,l=null,i(3))}),100);try{f.connect(l.destination),f.connect(m),m.connect(l.destination),f.loop=!1,c.PlayMode=1,n?r?e.play(0,n,r):e.play(0,n):e.play(0)}catch(e){console.log("Demo stream failed: "+e);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}try{m.disconnect(l.destination)}catch(e){}f=null,m=null,l=null,c.audioPlaying=0,s("Demo stream loading failed: "+e)}})).catch((function(e){c.audioPlaying=0,f=null,l=null,console.log("workletNode loading failed: "+e),s("workletNode loading failed: "+e)}))}catch(e){alert("Web Audio API is not supported in this browser"),s("Not supported")}})}function d(e,n=null,r=null){return new Promise((i,o)=>{var s,l,f;try{s=new AudioContext,l=null,l=s.createBufferSource(),(f=s.createAnalyser()).fftSize=256,f.smoothingTimeConstant=.8;const m=f.frequencyBinCount;new Uint8Array(m);a.bins_y_labels=f.frequencyBinCount,c.spec_bands=f.frequencyBinCount,c.audioPlaying=1,workletNode=new AudioWorkletNode(s,"spectrum-processor"),workletNode.port.onmessage=e=>{if(Number.isInteger(e.data)?1==e.data&&(c.frames_ack+=e.data,c.frames_ack>c.frames_analyzed&&workletNode&&workletNode.port.postMessage(1)):e.data.bins_Hz?(a.bins_y_labels=e.data.bins_Hz,(c.spec_bands<=0||c.spec_bands!=a.bins_y_labels.length)&&o("Bins Init mismatch: "+String(c.spec_bands)+", "+String(a.bins_y_labels.length))):Uint32Array.prototype.isPrototypeOf(e.data)&&e.data.length>0&&(c.spec_bands<=0||c.spec_bands!=e.data.length?o("Bins count mismatch: "+String(c.spec_bands)+", "+String(e.data.length)):(t.spectrum_push(e.data,c.frames_analyzed),a.plot_enable&&requestAnimFrame(M),c.frames_analyzed++)),2==c.audioPlaying&&c.frames_analyzed>=c.frames_ack||-1==c.audioPlaying){-1==c.audioPlaying?console.log("Online file end by disconnect"):console.log("Online file end normal (b)"),c.audioPlaying=0,workletNode&&workletNode.port.postMessage(22);try{l.stop(0)}catch(e){}try{l.disconnect(workletNode)}catch(e){}try{l.disconnect(s.destination)}catch(e){}try{workletNode.disconnect(s.destination)}catch(e){}s&&"closed"!=s.state&&s.close(),l=null,workletNode=null,s=null,t.segment_truncate(),a.plot_enable&&(requestAnimFrame(M),setTimeout(M,100)),i("complete_d")}},workletNode.port.postMessage(u),workletNode.port.postMessage(0),l.onended=function(){c.audioPlaying=2,workletNode&&workletNode.port.postMessage(22);try{l.stop(0)}catch(e){}try{l.disconnect(workletNode)}catch(e){}try{l.disconnect(s.destination)}catch(e){}if(l=null,c.frames_analyzed>=c.frames_ack&&0!=c.audioPlaying){console.log("Online file end normal"),c.audioPlaying=0;try{workletNode.disconnect(s.destination)}catch(e){}s&&"closed"!=s.state&&s.close(),workletNode=null,s=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),i("complete")}};try{s.decodeAudioData(e,(function(e){l.buffer=e,l.connect(s.destination),l.connect(workletNode),workletNode.connect(s.destination),l.loop=!1,c.PlayMode=1,n||r?((n-=.5)<0&&(n=0),r?l.start(0,n,r):l.start(0,n)):l.start(0)}),(function(e){A(e),o("Audio decode error: "+e)}))}catch(e){console.log("File loading failed: "+e);try{l.stop(0)}catch(e){}try{l.disconnect(workletNode)}catch(e){}try{l.disconnect(s.destination)}catch(e){}try{workletNode.disconnect(s.destination)}catch(e){}l=null,workletNode=null,s=null,c.audioPlaying=0,o("File loading failed: "+e)}}catch(e){alert("Web Audio API is not supported in this browser"),o("Not supported")}})}function h(e,n=null,r=null){return new Promise((i,s)=>{var l,f,m;try{l=new AudioContext,f=null,f=l.createBufferSource(),c.audioPlaying=1,l.audioWorklet.addModule(o).then((function(){(m=new AudioWorkletNode(l,"spectrum-processor")).port.onmessage=e=>{if(Number.isInteger(e.data)?1==e.data&&(c.frames_ack+=e.data,c.frames_ack>c.frames_analyzed&&m&&m.port.postMessage(1)):e.data.bins_Hz?(a.bins_y_labels=e.data.bins_Hz,(c.spec_bands<=0||c.spec_bands!=a.bins_y_labels.length)&&s("Bins Init mismatch: "+String(c.spec_bands)+", "+String(a.bins_y_labels.length))):Uint32Array.prototype.isPrototypeOf(e.data)&&e.data.length>0&&(c.spec_bands<=0||c.spec_bands!=e.data.length?s("Bins count mismatch: "+String(c.spec_bands)+", "+String(e.data.length)):(t.spectrum_push(e.data,c.frames_analyzed),a.plot_enable&&requestAnimFrame(M),c.frames_analyzed++)),2==c.audioPlaying&&c.frames_analyzed>=c.frames_ack||-1==c.audioPlaying){-1==c.audioPlaying?console.log("Online file end by disconnect"):console.log("Online file end normal (b)"),c.audioPlaying=0,m&&m.port.postMessage(22);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}try{m.disconnect(l.destination)}catch(e){}l&&"closed"!=l.state&&l.close(),f=null,m=null,l=null,t.segment_truncate(),a.plot_enable&&(requestAnimFrame(M),setTimeout(M,100)),i("complete_d")}},m.port.postMessage(u),m.port.postMessage(0),f.onended=function(){c.audioPlaying=2,m&&m.port.postMessage(22);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}if(f=null,c.frames_analyzed>=c.frames_ack&&0!=c.audioPlaying){console.log("Online file end normal"),c.audioPlaying=0;try{m.disconnect(l.destination)}catch(e){}l&&"closed"!=l.state&&l.close(),m=null,l=null,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),i("complete")}};try{l.decodeAudioData(e,(function(e){f.buffer=e,f.connect(l.destination),f.connect(m),m.connect(l.destination),f.loop=!1,c.PlayMode=1,n||r?((n-=.5)<0&&(n=0),r?f.start(0,n,r):f.start(0,n)):f.start(0)}),(function(e){A(e),s("Audio decode error: "+e)}))}catch(e){console.log("File loading failed: "+e);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{f.disconnect(l.destination)}catch(e){}try{m.disconnect(l.destination)}catch(e){}f=null,m=null,l=null,c.audioPlaying=0,s("File loading failed: "+e)}})).catch((function(e){c.audioPlaying=0,f=null,l=null,console.log("workletNode loading failed: "+e),s("workletNode loading failed: "+e)}))}catch(e){alert("Web Audio API is not supported in this browser"),s("Not supported")}})}function _(){try{FileAudioContext=null,FileAudioContext=void 0}catch(e){}try{sourceNode=null,sourceNode=void 0}catch(e){}try{workletNode=null,workletNode=void 0}catch(e){}}function g(e,n=null,r=null){return new Promise((i,s)=>{var l,f,m;try{l=new OfflineAudioContext(1,48e6,48e3),f=null,f=l.createBufferSource(),c.audioPlaying=1,l.audioWorklet.addModule(o).then((function(){(m=new AudioWorkletNode(l,"spectrum-processor")).port.onmessage=e=>{if(Number.isInteger(e.data)?1==e.data&&(c.frames_ack++,c.frames_ack>c.frames_analyzed&&m&&m.port.postMessage(1)):e.data.bins_Hz?(a.bins_y_labels=e.data.bins_Hz,(c.spec_bands<=0||c.spec_bands!=a.bins_y_labels.length)&&s("Bins Init mismatch: "+String(c.spec_bands)+", "+String(a.bins_y_labels.length))):Uint32Array.prototype.isPrototypeOf(e.data)&&e.data.length>0&&(c.spec_bands<=0||c.spec_bands!=e.data.length?s("Bins count mismatch: "+String(c.spec_bands)+", "+String(e.data.length)):(t.spectrum_push(e.data,c.frames_analyzed),a.plot_enable&&requestAnimFrame(M),c.frames_analyzed++)),2==c.audioPlaying&&c.frames_analyzed>=c.frames_ack||-1==c.audioPlaying){c.frames_ack=0,m&&m.port.postMessage(22);try{f.stop(0)}catch(e){}try{f.disconnect(m)}catch(e){}try{m.disconnect(l.destination)}catch(e){}f=null,m=null,l=null,-1==c.audioPlaying&&console.log("Offline file end by disconnect"),c.audioPlaying=0,t.segment_truncate(),a.plot_enable&&requestAnimFrame(M),i("complete_u")}c.last_node_ms=Date.now()},m.port.postMessage(u),m.port.postMessage(0);try{l.decodeAudioData(e,(function(e){f.buffer=e,f.connect(m),m.connect(l.destination),f.loop=!1,c.PlayMode=2,n?r?f.start(0,n,r):f.start(0,n):f.start(0),l.startRendering().then((function(e){let n=Date.now();function r(){if(2==c.audioPlaying&&Date.now()-n<1e4){console.log("Rendering finished."),setTimeout(r,100);try{m.port.postMessage(22)}catch(e){}}else if(2==c.audioPlaying&&m){console.error("Worklet is stuck. Terminating."),c.audioPlaying=-1,c.last_node_ms=0;try{m.port.postMessage(22)}catch(e){}i(3)}else if(-1==c.audioPlaying){setTimeout(r,250);try{m.port.postMessage(22)}catch(e){}}else if(1==c.audioPlaying);else if(0==c.audioPlaying||Date.now()-c.last_node_ms>1e4)m=null,c.audioPlaying=0,i(3);else{setTimeout(r,250);try{m.port.postMessage(22)}catch(e){}}}m.port.postMessage(22),window.setTimeout((function(){c.audioPlaying=2,m&&m.port.postMessage(22),window.setTimeout(r,100)}),100),f=null})).catch((function(e){c.audioPlaying=0,console.log("Rendering failed: "+e),s("Rendering failed: "+e)}))}),(function(e){A(e),s("Audio decode error: "+e)}))}catch(e){console.log("File loading failed: "+e);try{f.stop(0)}catch(e){}try{m.disconnect(l.destination)}catch(e){}try{f.disconnect(m)}catch(e){}try{m.disconnect(l.destination)}catch(e){}f=null,m=null,l=null,c.audioPlaying=0,s("File loading failed: "+e)}})).catch((function(e){c.audioPlaying=0,f=null,l=null,console.log("workletNode loading failed: "+e),s("workletNode loading failed: "+e)}))}catch(e){alert("Web Audio API is not supported in this browser. Error: "+e),s("Web Audio API error: "+e)}})}function y(e){0!=c.audioPlaying&&(c.audioPlaying=-1,console.log("Disconnect Nodes because: "+e))}function v(){return c.audioPlaying>0}let b=0,w=!1,x=!1;function k(e,n,r){t.set_segments_label(e,n,r),x=!0,setTimeout(M,100)}async function M(){w=!0;let e=t.get_context_maximum();if(1==a.process_level||2==a.process_level){if(b++,b<a.plot_lag)return w=!1,!0;b=0;let n=t.get_spectrum();n.length>0&&(2==a.process_level?(i.clear_plot(!1),i.plot_spectrum(n,e,a.bins_y_labels),i.plot_axis_majors(a.bins_y_labels,a.axis_labels_sep)):(i.clear_plot(!0),i.plotBands(n[n.length-1],e,a.bins_y_labels,a.axis_labels_sep))),n=null}else if(3==a.process_level||a.process_level>=4){let n=0,r=t.get_segments_count(a.process_level);if(r>0&&(a.last_seg_len!=r||x)){x=!1,a.last_seg_len=r,i.clear_plot();for(let o=r-1;o>=0;o--){let r=t.get_segments_ci(o)[1];if(r>0){let c=t.get_segment(o,a.process_level),u=t.get_seg_timestamps(o);n=n+r+2;let s=a.plot_len-n;a.process_level>=4?(i.plot_formants(c,r,u,s,e),10==a.process_level||11==a.process_level||13==a.process_level?i.plot_syllable_anchors(o,t.get_syllables_ci(o),s):12==a.process_level&&i.plot_syllable_anchors(o,t.get_syllables_ci(o),s,t.get_syllables_curves(o))):3==a.process_level&&i.plot_raw_segment(c,r,u,s,e),c=null;let l=t.get_segments_label(o);if(i.plot_segment_labels(r,s,l),n>a.plot_len)break}else console.warn("Segment size error, si:"+o+", size:"+r)}i.plot_axis_majors(a.bins_y_labels,a.axis_labels_sep)}}else console.log("Error: Invalid process_level");return w=!1,!0}function A(e){console.log(e),c.audioPlaying=0,document.getElementById("msg").textContent="Error",_()}window.requestAnimFrame_2=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e,n){window.setTimeout(e,100)},window.requestAnimFrame=function(e){w||(window.setTimeout(e,10),w=!0)}},function(e,n,r){"use strict";r.r(n),r.d(n,"reset_segmentation",(function(){return P})),r.d(n,"spectrum_push",(function(){return I})),r.d(n,"segment_truncate",(function(){return B})),r.d(n,"get_context_maximum",(function(){return V})),r.d(n,"get_spectrum",(function(){return z})),r.d(n,"get_segment",(function(){return O})),r.d(n,"get_syllables_ci",(function(){return R})),r.d(n,"get_syllables_curves",(function(){return D})),r.d(n,"get_syls_timestamps",(function(){return L})),r.d(n,"get_segments_ci",(function(){return U})),r.d(n,"get_clip_timestamps",(function(){return C})),r.d(n,"get_seg_timestamps",(function(){return E})),r.d(n,"get_segments_count",(function(){return X})),r.d(n,"get_segments_label",(function(){return H})),r.d(n,"set_segments_label",(function(){return Y}));const t=r(4),i=r(7),o=r(0);var c={spec_bands:-1,plot_len:200,max_voiced_bin:80,window_step:.025,current_frame:0,play_end:!1,no_fm_segs:0,c_ci:0,c_started:-1,current_label:[],callbacks_processed:0,seg_limit_1:200,seg_limit_2:250,seg_min_frames:20,seg_breaker:12,process_level:5,auto_noise_gate:!0,voiced_max_dB:100,voiced_min_dB:10,call_at_end:!1},u=[],a=[],s=[],l=[],f=[],m=[],p=[],d=[],h=[],_=!1,g=50,y=2;let v=g,b=y;var w=0,x=0,k=0,M=null;let A=!0;async function P(e,n,r=200,i=15,o=200,P=50,S=!0,j=150,N=50,q=null,F=!0,I=[]){return u=null,a=null,s=null,m=null,f=null,p=null,d=null,A=F,0==A&&(M=q),new Promise((M,A)=>{n?function e(){return new Promise(n=>{T>20?(T=0,n(1),console.error("await_busy_last_process timeout")):c.callbacks_processed<l.length?(T++,setTimeout(()=>{e().then(e=>{n(1)})},500)):c.callbacks_processed>=l.length&&(T=0,n(l.length))})}().then(A=>{c.process_level=e,c.spec_bands=n,c.plot_len=r,c.seg_limit_1=r-10,c.seg_limit_2=r-4,c.max_voiced_bin=parseInt(.7*n),c.window_step=i/1e3,c.seg_breaker=o>2*i?o/i:250/i,c.seg_min_frames=parseInt(P/i),c.current_label=I,c.play_end=!1,c.no_fm_segs=0,c.c_ci=0,c.c_started=-1,u=[],c.current_frame=0,c.callbacks_processed=0,t.clear_fm(),a=[],s=[],f=[],l=[],m=[],p=[],d=[],c.auto_noise_gate=S,c.voiced_max_dB=j,c.voiced_min_dB=N,c.auto_noise_gate?(g=50,y=2):(g=Math.pow(10,c.voiced_max_dB/20),y=Math.pow(10,c.voiced_min_dB/20)),w=0,x=0,k=0,v=g,b=y,h=[],_=!1,M("ready")}):A("Invalid spec_bands")})}var T=0;function S(e=-1){c.c_ci=0,c.c_started=e,c.no_fm_segs=0,t.clear_fm()}async function j(){for(_=!0;h.length>0;){let e=h.splice(0,1)[0],n=c.c_ci,r=0,i=1,o=0,u=0,a=0,s=0,l=0,f=[],m=0,p=2*y,d=0,_=0;for(;i<c.spec_bands;){if(_+=e[i],e[i]>e[i-1]&&(i<2||e[i]>e[i-2])&&(i<3||e[i]>e[i-3])){if(-1==l||0==l){if(-1==l&&e[u]>y&&o<=u&&u<a){e[u]>p&&(p=e[u],d=u);let n=e[u]/10;for(;o<u&&e[o]<n;)o++;for(;a>u&&e[a]<n;)a--;f[r]=[o,a,u],r++,m+=e[u]}o=i-1,u=i}else 1==l&&(u=i);l=1}else if(e[i]<e[i-1]&&(i<2||e[i]<e[i-2])&&(i<3||e[i]<e[i-3]))1!=l&&-1!=l||(a=i,l=-1);else if(-1==l){if(s++,s>2){if(s=0,e[u]>y&&o<=u&&u<a){e[u]>p&&(p=e[u],d=u);let n=e[u]/10;for(;o<u&&e[o]<n;)o++;for(;a>u&&e[a]<n;)a--;f[r]=[o,a,u],r++,m+=e[u]}l=0}}else 1==l&&e[i]>e[i-1]&&(u=i);if(i==c.spec_bands-1&&1==l&&(a=i,u=i,e[u]>y&&o<u&&u<=a)){let n=e[u]/10;for(;o<u&&e[o]<n;)o++;for(;a>u&&e[a]<n;)a--;f[r]=[o,a,u],r++,m+=e[u]}i++}if(c.c_started<0){let e=m>p?p*(r-1)/(m-p):0;r>0&&d>7&&d<c.max_voiced_bin&&r>4&&e>4?(S(0),c.c_started=0):c.no_fm_segs++}c.c_started>=0&&(0==r||d<7||d>=c.max_voiced_bin||r>3&&m/(_-m)<.1?(c.no_fm_segs++,c.c_started<2?c.c_started--:c.no_fm_segs>=c.seg_breaker?N(c.c_ci+1).then((function(){S(-1),0==c.call_at_end&&F()})).catch(e=>{S(-1)}):c.auto_noise_gate&&q(p)):(c.auto_noise_gate&&q(p),t.accumulate_fm(e,f,n,_,y),c.c_started<2?c.c_started++:c.no_fm_segs=0)),c.c_ci++,f=null}c.play_end&&N(c.c_ci).then((function(){S(1),c.play_end&&F()})).catch(e=>{S(1)}),_=!1}function N(e){return new Promise((n,r)=>{let i=e-c.no_fm_segs;if(i>c.seg_min_frames&&c.c_started>=2){let e=c.current_frame-i,o=t.get_ranked_formants();if(13==c.process_level){l.push([e,i]);let r=t.straighten_formants(o,i,y),u=t.sep_syllables(r,y),h=t.make_syl_features(u,g,y);f.push(c.current_label.slice()),a.push(o),s.push(r[0]),m.push(null),p.push(u),d.push(h),n(1),r=null,u=null,h=null}else if(12==c.process_level){l.push([e,i]);let r=t.straighten_formants(o,i,y),u=t.sep_syllables(r,y),h=t.make_coeffs(u);f.push(c.current_label.slice()),a.push(o),s.push(r[0]),m.push(null),p.push(u),d.push(h),n(1),r=null,u=null,h=null}else if(10==c.process_level||11==c.process_level){l.push([e,i]);let r=t.straighten_formants(o,i,y),u=t.sep_syllables(r,y);f.push(c.current_label.slice()),a.push(o),s.push(r[0]),m.push(null),p.push(u),n(1),r=null,u=null}else if(5==c.process_level){l.push([e,i]);let r=t.straighten_formants(o,i,y),u=t.formant_features(r[0],g,y);f.push(c.current_label.slice()),a.push(o),s.push(r[0]),m.push(u),n(1),r=null,u=null}else if(4==c.process_level){l.push([e,i]);let r=t.straighten_formants(o,i,y);f.push(c.current_label.slice()),a.push(o),s.push(r[0]),n(1),r=null}else 3==c.process_level?(l.push([e,i]),f.push(c.current_label.slice()),a.push(o),n(1)):(console.error("Invalid process_level"),r(0))}else i>1?(console.log(l.length+": seg_size:"+i+", ignored, too small < "+c.seg_min_frames),n(0)):n(0)})}function q(e){if(w++,e>g||w>40&&e>2*y){e>=g?(w=0,v=g=e):e>v/100&&(g-=parseInt(g/8),w=35);let n=Math.log10(g);y=n>7?parseInt(Math.pow(10,n-3)/20):n>6?parseInt(Math.pow(10,n-3)/2):n>4?parseInt(Math.pow(10,n-2)/2):n>2?parseInt(Math.pow(10,n/3)):n>1?parseInt(g/10):1,b=y,k>0&&x/k<30*y&&(S(0),k=0,x=0),x+=g,k+=1}else y>10&&y>b/10&&w>20&&(y-=parseInt(b/20))<10&&(y=10)}function F(){if(A||null==M)return!0;if(c.spec_bands>0){if(11==c.process_level)if(p.length>l.length)console.error("Array len mismatch");else if(c.callbacks_processed<p.length){c.callbacks_processed=p.length;const e=C(),n=i.get_utterance_features(l,p);M(0,c.current_label,e,n)}if(12==c.process_level||13==c.process_level)if(d.length>l.length)console.error("Array len mismatch");else for(;c.callbacks_processed<d.length;){c.callbacks_processed++;let e=c.callbacks_processed-1;d[e].length>0&&M(e,c.current_label,L(e),d[e])}else if(10==c.process_level)if(p.length>l.length)console.error("Array len mismatch");else for(;c.callbacks_processed<p.length;){c.callbacks_processed++;let e=c.callbacks_processed-1;p[e][1].length>0&&M(e,c.current_label,L(e),p[e][1])}else if(5==c.process_level)if(m.length>l.length)console.error("Array len mismatch");else for(;c.callbacks_processed<m.length;){c.callbacks_processed++;let e=c.callbacks_processed-1;m[e].length>0&&M(e,c.current_label,E(e),m[e])}else if(4==c.process_level)if(s.length>l.length)console.error("Array len mismatch");else for(;c.callbacks_processed<s.length;){c.callbacks_processed++;let e=c.callbacks_processed-1;s[e].length>0&&M(e,c.current_label,E(e),s[e])}else if(3==c.process_level)for(;c.callbacks_processed<a.length;){c.callbacks_processed++;let e=c.callbacks_processed-1;a[e].length>0&&M(e,c.current_label,E(e),a[e])}else 2==c.process_level?c.current_frame-c.callbacks_processed>c.seg_min_frames&&(M(c.current_frame,c.current_label,[c.current_frame*c.window_step,c.plot_len*c.window_step],u),c.callbacks_processed=c.current_frame):c.current_frame>c.callbacks_processed&&(c.callbacks_processed=c.current_frame,M(c.current_frame,c.current_label,[c.current_frame*c.window_step,c.window_step],u))}else console.warn("s_set.spec_bands is not set yet.");return!0}function I(e,n){if(c.spec_bands==e.length)if(c.current_frame++,c.process_level<=2){u.push(e);let n=o.arrayMax(e);c.process_level<=1?(u.splice(0,u.length-1),n>y&&F()):u.length>c.plot_len&&(u.splice(0,1),n>y&&F()),c.auto_noise_gate&&(n>g?(g=n,w=0,v=n):w>c.seg_limit_1&&g>v/4?g*=.99:w++)}else h.push(e),0==_&&j();else console.error("Error: bins num mismatch "+c.spec_bands+", "+e.length)}function B(){window.setTimeout((function(){c.play_end=!0,0==_&&j()}),10)}function V(){return g/7}function z(){return u}function O(e,n){return n>=4&&c.process_level>=4?s[e]:c.process_level>=3?a[e]:[]}function R(e){return p[e][0]}function D(e){return 12==c.process_level?d[e]:(console.error("Invalid process level for syllable curves "+c.process_level),null)}function L(e){const n=p[e][0].length;let r=[];try{for(let t=0;t<n;t++)r[t]=[],r[t][0]=((l[e][0]+p[e][0][t][0])*c.window_step).toFixed(3),r[t][1]=((p[e][0][t][1]+1)*c.window_step).toFixed(3)}catch(e){console.error(e)}return r}function U(e){return l[e]}function C(){const e=l.length;if(e>0){let n=0;for(let r=0;r<e;r++)n+=l[r][1];return[l[0][0]*c.window_step,(n+1)*c.window_step]}return[0,0]}function E(e){return[l[e][0]*c.window_step,(l[e][1]+1)*c.window_step]}function X(e){return e>=6&&c.process_level>=6||e>=4&&c.process_level>=4?s.length:3==c.process_level?a.length:0}function H(e){return f[e]}function Y(e,n,r){for(;f[e].length<n;)f[e][f[e].length]=-1;f[e][n]=r}},function(e,n,r){"use strict";r.r(n),r.d(n,"formant_features",(function(){return l})),r.d(n,"make_syl_features",(function(){return m})),r.d(n,"make_coeffs",(function(){return p})),r.d(n,"sep_syllables",(function(){return d})),r.d(n,"straighten_formants",(function(){return h})),r.d(n,"rescale_formants",(function(){return _})),r.d(n,"get_ranked_formants",(function(){return g})),r.d(n,"clear_fm",(function(){return y})),r.d(n,"accumulate_fm",(function(){return v})),r.d(n,"straighten_formants_feb28",(function(){return w}));const t=r(0),i=r(5),o=[3,4,6,9],c=o.length;var u=[];let a=0,s=0;function l(e,n,r){try{const i=e.length;let o=new Array(3).fill(0),c=new Array(3).fill(0),u=new Array(3).fill(0),l=new Array(3).fill(0),f=new Array(3).fill(0),m=new Array(3).fill(0),p=new Array(3).fill(0),d=new Array(3).fill(0),h=new Array(3).fill(0),_=new Array(3).fill(0),g=new Array(3).fill(0),y=new Array(3).fill(0),v=new Array(3).fill(0),b=new Array(3).fill(0),w=new Array(3).fill(0);for(let r=0;r<3;r++){let a=!1,s=[],x=[],k=[],M=[],A=[],P=[],T=0,S=0;for(let n=0;n<i;n++){let t=e[n][3*r],i=e[n][3*r+1];if(t>0&&i>0){let f=e[n][3*r+2],m=20*Math.log10(i);if(s.push(t*m),x.push(t),A.push(f*m),k.push(i),M.push(m),a){let o=t-e[n-1][3*r];o>1?u[r]+=o:o<-1&&(l[r]+=-1*o),i>S?(S=i,T=1):1==T&&i<S/2&&(S>10&&P.push(m),S=0,T=-1)}a||(c[r]+=1),a=!0,o[r]+=1}else a=!1,T=0,S=0}if(c[r]>0){let e=t.arraySum(k);h[r]=e/i*100/n,_[r]=e/o[r]*100/n;let c=t.arraySum(M);f[r]=t.arraySum(s)/c,m[r]=t.only_std_NZ(x),g[r]=t.arraySum(A)/c;let u=t.mean_std_NZ(M);if(p[r]=u[0],d[r]=u[1],y[r]=P.length,y[r]>0){let e=t.mean_std_NZ(P);v[r]=e[0],w[r]=e[1],b[r]=100*(v[r]/(c/M.length)-1)}}}let x=[];x.push(i),x.push(Math.sqrt(i)),x.push(s/a),x.push(Math.log10(n)),x.push(r);for(let e=0;e<3;e++)x.push(f[e]),x.push(m[e]),x.push(p[e]),x.push(d[e]),x.push(h[e]),x.push(_[e]),x.push(g[e]),x.push(o[e]),x.push(c[e]),x.push(u[e]),x.push(l[e]),x.push(y[e]),x.push(v[e]),x.push(w[e]),x.push(b[e]),x.push(100*o[e]/i);return x}catch(e){return console.error(e),null}}function f(e,n,r=3,o=!1){let c=[],u=[],a=[],s=[],l=-1;for(let t=0;t<e.length;t++)if(e[t][n]>0){-1==l&&(l=t),s=[],c.push(t-l),o?u.push(10*Math.log10(e[t][n])):u.push(e[t][n]);for(let e=0;e<=r;e++)s.push(1*Math.pow(t,e));a.push(s)}if(c.length>2){let e=i.transpose([u]),n=i.transpose(a),r=i.dot(n,a),o=i.inv(r),s=i.dot(n,e);var f=new Float32Array(i.dot(o,s)),m=function(e){let n=0;for(let r=0;r<c.length;++r){let i=t.solve_poly(e,c[r])-u[r];n+=i*i}return n};f=i.uncmin(m,f).solution;let l=Math.sqrt(m(f))/c.length;return f.push(l),f.push(c.length),f}{let e=new Array(r+1).fill(0);return e.push(0),e.push(c.length),e}}function m(e,n,r){let t=e[1],i=[];try{for(let e=0;e<t.length;e++)i.push(l(t[e],n,r))}catch(e){console.error(e)}return i}function p(e,n,r){let t=[];try{for(let n=0;n<e[1].length;n++){let r=f(e[2][n],1,4,!0),i=f(e[1][n],0,3),o=f(e[1][n],3,3),c=f(e[1][n],6,1);if(e[1][n].length>1){let e=[].concat(r,i,o,c);t.push(e)}}}catch(e){console.error(e)}return t}function d(e,n){let r=e[0],t=e[1];const i=t.length;let o=-1,c=[],u=[],a=[],s=0,l=0;try{for(let e=0;e<i;e++)if(t[e][1]>n?(s=0,l++,o<0&&(o=e)):s++,l>20&&s>0||l>10&&s>1||l>0&&s>4||e>=i-1&&l>4){let n=e-s;n-o>1&&(u.push(r.slice(o,n)),a.push(t.slice(o,n)),c.push([o,n-o]),o=-1,l=0)}}catch(e){console.error(e)}return[c,u,a]}function h(e,n,r){let t=[],i=[];for(let e=0;e<n;e++)t.push(new Float32Array(9).fill(0)),i.push(new Float32Array(3).fill(0));let o=0,c=0;for(let n=0;n<e.length;n++){const u=e[n][15]/e[n][13];if((Math.abs(u-o)>20||c<0)&&(o=u,c++,c>=3))break;let a=3*c,s=3*c+1,l=3*c+2;for(let o=0;o<e[n][14];o++){let u=c;a=3*u,s=3*u+1,l=3*u+2;const f=e[n][10][o];if(f>0){const c=e[n][12][o],m=e[n][7][o],p=e[n][9][o]-e[n][8][o]+1;t[m][a]>r&&t[m][a]<f&&u<2&&(u<3&&u++,a=3*u,s=3*u+1,l=3*u+2),t[m][a]=f,t[m][s]=c,t[m][l]=p,i[m][0]+=f*c,i[m][1]+=c,i[m][2]+=p*c}}}return[t,i]}function _(e){e.length;for(let e=0;e<3;e++);}function g(){let e=[];for(let n=0;n<u.length;n++)if(u[n][14]>=2){const r=u[n][15]/u[n][13];if(r>=7){let t=0;if(0==e.length)e.push(u[n]);else{for(;t<e.length;){if(e[t][15]/e[t][13]>r){e.splice(t,0,u[n]);break}t++}t==e.length&&e.push(u[n])}}}return e}function y(){u=null,u=[],a=0,s=0}function v(e,n,r,t,i){let l=n.length;if(l<1)return;let f=new Array(l).fill(-1),m=new Array(l).fill(0);a+=t;for(let t=0;t<u.length;t++){let i=r-u[t][3];if(i>=0&&i<c){let r=u[t][7].length;for(let c=0;c<l;c++){let a=Math.abs(u[t][5]-n[c][2]);if(a<o[i]){let o=b(i,a,r,u[t][5],n[c][2],u[t][6],e[n[c][2]],u[t][4]);o>1&&o>m[c]&&(m[c]=o,f[c]=t)}}}}for(let t=0;t<u.length;t++){let o=[];for(let e=0;e<l;e++)f[e]==t&&o.push(e);if(o.length>0){let c=n[o[0]][2],l=e[c];if(l>i){let i=n[o[0]][0],f=n[o[0]][1];for(let r=0;r<o.length;r++)n[o[r]][1]>f&&(f=n[o[r]][1]),n[o[r]][0]<i&&(i=n[o[r]][0]),e[n[o[r]][2]]>e[c]&&(c=n[o[r]][2]);let m=0;for(let n=i;n<=f;n++)m+=e[n];m=m;let p=u[t][10].length;p>=3?u[t][4]=(c-u[t][10][p-1]+(u[t][10][p-2]-u[t][10][p-1])+(u[t][10][p-3]-u[t][10][p-2]))/3:2==p?u[t][4]=(c-u[t][10][p-1]+(u[t][10][p-2]-u[t][10][p-1]))/2:1==p&&(u[t][4]=c-u[t][10][p-1]),u[t][0]=i,u[t][1]=f,u[t][2]=r,u[t][3]=r,u[t][5]=c,u[t][6]=l,u[t][7].push(r),u[t][8].push(i),u[t][9].push(f),u[t][10].push(c),u[t][11].push(l),u[t][12].push(m),u[t][13]+=m,u[t][14]+=1,u[t][15]+=m*c,u[t][16]=0,u[t][17]+=f-i+1,a-=m,s+=m}}}for(let t=0;t<l;t++)if(-1==f[t]){let o=n[t][2],c=e[o];if(c>i){let i=n[t][0],a=n[t][1],s=0;for(let n=i;n<=a;n++)s+=e[n];s=s;let l=[];l[0]=i,l[1]=a,l[2]=r,l[3]=r,l[4]=0,l[5]=o,l[6]=c,l[7]=[r],l[8]=[i],l[9]=[a],l[10]=[o],l[11]=[c],l[12]=[s],l[13]=s,l[14]=1,l[15]=s*o,l[16]=0,l[17]=a-i+1,u.push(l)}}}function b(e,n,r,t,i,o,c,u){let a=0;if(o>=c)a=c/o;else{if(!(c>0))return 0;a=o/c}if(0==e)return a>.1?300*a/n:0;{if(a<.001)return 0;a>=1?a=10:a<.1?a=1:a*=10;let n=10-Math.abs(i-t-u);if(n<0)return 0;n<1&&(n=1);let o=r;return o>10&&(o=10),10/e*(n*n+o*a)}}function w(e,n,r){let t=[],i=[],o=[],c=[];for(let e=0;e<n;e++)t.push(new Array(18).fill(0)),i.push(new Array(3).fill(0)),o.push(new Int32Array(6).fill(0)),c.push(new Int32Array(6).fill(0));for(let n=0;n<e.length;n++)for(let u=0;u<e[n][14];u++){const a=e[n][7][u],s=e[n][10][u],l=e[n][12][u];let f=!1;for(let m=0;m<6;m++){const p=3*m,d=3*m+1,h=3*m+2;if(c[a][m]<r||Math.abs(s-o[a][m]/c[a][m])<10){if(0==t[a][d])f=!0;else if(t[a][d]<l){for(let e=5;e>m;e--)t[a][3*e]=t[a][3*(e-1)],t[a][3*e+1]=t[a][3*(e-1)+1],t[a][3*e+2]=t[a][3*(e-1)+2];f=!0}if(f){const r=e[n][9][u]-e[n][8][u]+1;t[a][p]=s,t[a][d]=l,t[a][h]=r,o[a][m]+=s*l,c[a][m]+=l,i[a][0]+=s*l,i[a][1]+=l,i[a][2]+=r*l;break}}}}return[t,i]}},function(module,exports,__webpack_require__){"use strict";(function(global){var numeric=exports;void 0!==global&&(global.numeric=numeric),numeric.version="1.2.6",numeric.bench=function(e,n){var r,t,i;for(void 0===n&&(n=15),t=.5,r=new Date;;){for(i=t*=2;i>3;i-=4)e(),e(),e(),e();for(;i>0;)e(),i--;if(new Date-r>n)break}for(i=t;i>3;i-=4)e(),e(),e(),e();for(;i>0;)e(),i--;return 1e3*(3*t-1)/(new Date-r)},numeric._myIndexOf=function(e){var n,r=this.length;for(n=0;n<r;++n)if(this[n]===e)return n;return-1},numeric.myIndexOf=Array.prototype.indexOf?Array.prototype.indexOf:numeric._myIndexOf,numeric.Function=Function,numeric.precision=4,numeric.largeArray=50,numeric.prettyPrint=function(e){var n=[];return function e(r){var t;if(void 0===r)return n.push(Array(numeric.precision+8).join(" ")),!1;if("string"==typeof r)return n.push('"'+r+'"'),!1;if("boolean"==typeof r)return n.push(r.toString()),!1;if("number"==typeof r){var i=function e(n){if(0===n)return"0";if(isNaN(n))return"NaN";if(n<0)return"-"+e(-n);if(isFinite(n)){var r=Math.floor(Math.log(n)/Math.log(10)),t=n/Math.pow(10,r),i=t.toPrecision(numeric.precision);return 10===parseFloat(i)&&(r++,i=(t=1).toPrecision(numeric.precision)),parseFloat(i).toString()+"e"+r.toString()}return"Infinity"}(r),o=r.toPrecision(numeric.precision),c=parseFloat(r.toString()).toString(),u=[i,o,c,parseFloat(o).toString(),parseFloat(c).toString()];for(t=1;t<u.length;t++)u[t].length<i.length&&(i=u[t]);return n.push(Array(numeric.precision+8-i.length).join(" ")+i),!1}if(null===r)return n.push("null"),!1;if("function"==typeof r){n.push(r.toString());var a=!1;for(t in r)r.hasOwnProperty(t)&&(a?n.push(",\n"):n.push("\n{"),a=!0,n.push(t),n.push(": \n"),e(r[t]));return a&&n.push("}\n"),!0}if(r instanceof Array){if(r.length>numeric.largeArray)return n.push("...Large Array..."),!0;a=!1;for(n.push("["),t=0;t<r.length;t++)t>0&&(n.push(","),a&&n.push("\n ")),a=e(r[t]);return n.push("]"),!0}for(t in n.push("{"),a=!1,r)r.hasOwnProperty(t)&&(a&&n.push(",\n"),a=!0,n.push(t),n.push(": \n"),e(r[t]));return n.push("}"),!0}(e),n.join("")},numeric.parseDate=function(e){return function e(n){if("string"==typeof n)return Date.parse(n.replace(/-/g,"/"));if(!(n instanceof Array))throw new Error("parseDate: parameter must be arrays of strings");var r,t=[];for(r=0;r<n.length;r++)t[r]=e(n[r]);return t}(e)},numeric.parseFloat=function(e){return function e(n){if("string"==typeof n)return parseFloat(n);if(!(n instanceof Array))throw new Error("parseFloat: parameter must be arrays of strings");var r,t=[];for(r=0;r<n.length;r++)t[r]=e(n[r]);return t}(e)},numeric.parseCSV=function(e){var n,r,t,i=e.split("\n"),o=[],c=/(([^'",]*)|('[^']*')|("[^"]*")),/g,u=/^\s*(([+-]?[0-9]+(\.[0-9]*)?(e[+-]?[0-9]+)?)|([+-]?[0-9]*(\.[0-9]+)?(e[+-]?[0-9]+)?))\s*$/,a=0;for(r=0;r<i.length;r++){var s,l=(i[r]+",").match(c);if(l.length>0){for(o[a]=[],n=0;n<l.length;n++)s=(t=l[n]).substr(0,t.length-1),u.test(s)?o[a][n]=parseFloat(s):o[a][n]=s;a++}}return o},numeric.toCSV=function(e){var n,r,t,i,o,c=numeric.dim(e);for(t=c[0],c[1],o=[],n=0;n<t;n++){for(i=[],r=0;r<t;r++)i[r]=e[n][r].toString();o[n]=i.join(", ")}return o.join("\n")+"\n"},numeric.getURL=function(e){var n=new XMLHttpRequest;return n.open("GET",e,!1),n.send(),n},numeric.imageURL=function(e){function n(e,n,r){void 0===n&&(n=0),void 0===r&&(r=e.length);var t,i=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],o=-1;e.length;for(t=n;t<r;t++)o=o>>>8^i[255&(o^e[t])];return-1^o}var r,t,i,o,c,u,a,s,l,f,m=e[0].length,p=e[0][0].length,d=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,p>>24&255,p>>16&255,p>>8&255,255&p,m>>24&255,m>>16&255,m>>8&255,255&m,8,2,0,0,0,-1,-2,-3,-4,-5,-6,-7,-8,73,68,65,84,8,29];for(f=n(d,12,29),d[29]=f>>24&255,d[30]=f>>16&255,d[31]=f>>8&255,d[32]=255&f,r=1,t=0,a=0;a<m;a++){for(a<m-1?d.push(0):d.push(1),c=3*p+1+(0===a)&255,u=3*p+1+(0===a)>>8&255,d.push(c),d.push(u),d.push(255&~c),d.push(255&~u),0===a&&d.push(0),s=0;s<p;s++)for(i=0;i<3;i++)t=(t+(r=(r+(c=(c=e[i][a][s])>255?255:c<0?0:Math.round(c)))%65521))%65521,d.push(c);d.push(0)}return l=(t<<16)+r,d.push(l>>24&255),d.push(l>>16&255),d.push(l>>8&255),d.push(255&l),o=d.length-41,d[33]=o>>24&255,d[34]=o>>16&255,d[35]=o>>8&255,d[36]=255&o,f=n(d,37),d.push(f>>24&255),d.push(f>>16&255),d.push(f>>8&255),d.push(255&f),d.push(0),d.push(0),d.push(0),d.push(0),d.push(73),d.push(69),d.push(78),d.push(68),d.push(174),d.push(66),d.push(96),d.push(130),"data:image/png;base64,"+function(e){var n,r,t,i,o,c,u,a=e.length,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",l="";for(n=0;n<a;n+=3)o=((3&(r=e[n]))<<4)+((t=e[n+1])>>4),c=((15&t)<<2)+((i=e[n+2])>>6),u=63&i,n+1>=a?c=u=64:n+2>=a&&(u=64),l+=s.charAt(r>>2)+s.charAt(o)+s.charAt(c)+s.charAt(u);return l}(d)},numeric._dim=function(e){for(var n=[];"object"==typeof e;)n.push(e.length),e=e[0];return n},numeric.dim=function(e){var n;return"object"==typeof e?"object"==typeof(n=e[0])?"object"==typeof n[0]?numeric._dim(e):[e.length,n.length]:[e.length]:[]},numeric.mapreduce=function(e,n){return Function("x","accum","_s","_k",'if(typeof accum === "undefined") accum = '+n+';\nif(typeof x === "number") { var xi = x; '+e+'; return accum; }\nif(typeof _s === "undefined") _s = numeric.dim(x);\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i,xi;\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) {\n accum = arguments.callee(x[i],accum,_s,_k+1);\n } return accum;\n}\nfor(i=_n-1;i>=1;i-=2) { \n xi = x[i];\n '+e+";\n xi = x[i-1];\n "+e+";\n}\nif(i === 0) {\n xi = x[i];\n "+e+"\n}\nreturn accum;")},numeric.mapreduce2=function(e,n){return Function("x","var n = x.length;\nvar i,xi;\n"+n+";\nfor(i=n-1;i!==-1;--i) { \n xi = x[i];\n "+e+";\n}\nreturn accum;")},numeric.same=function e(n,r){var t,i;if(!(n instanceof Array&&r instanceof Array))return!1;if((i=n.length)!==r.length)return!1;for(t=0;t<i;t++)if(n[t]!==r[t]){if("object"!=typeof n[t])return!1;if(!e(n[t],r[t]))return!1}return!0},numeric.rep=function(e,n,r){void 0===r&&(r=0);var t,i=e[r],o=Array(i);if(r===e.length-1){for(t=i-2;t>=0;t-=2)o[t+1]=n,o[t]=n;return-1===t&&(o[0]=n),o}for(t=i-1;t>=0;t--)o[t]=numeric.rep(e,n,r+1);return o},numeric.dotMMsmall=function(e,n){var r,t,i,o,c,u,a,s,l,f,m;for(o=e.length,c=n.length,u=n[0].length,a=Array(o),r=o-1;r>=0;r--){for(s=Array(u),l=e[r],i=u-1;i>=0;i--){for(f=l[c-1]*n[c-1][i],t=c-2;t>=1;t-=2)m=t-1,f+=l[t]*n[t][i]+l[m]*n[m][i];0===t&&(f+=l[0]*n[0][i]),s[i]=f}a[r]=s}return a},numeric._getCol=function(e,n,r){var t;for(t=e.length-1;t>0;--t)r[t]=e[t][n],r[--t]=e[t][n];0===t&&(r[0]=e[0][n])},numeric.dotMMbig=function(e,n){var r,t,i,o=numeric._getCol,c=n.length,u=Array(c),a=e.length,s=n[0].length,l=new Array(a),f=numeric.dotVV;for(--c,t=--a;-1!==t;--t)l[t]=Array(s);for(t=--s;-1!==t;--t)for(o(n,t,u),i=a;-1!==i;--i)0,r=e[i],l[i][t]=f(r,u);return l},numeric.dotMV=function(e,n){var r,t=e.length,i=(n.length,Array(t)),o=numeric.dotVV;for(r=t-1;r>=0;r--)i[r]=o(e[r],n);return i},numeric.dotVM=function(e,n){var r,t,i,o,c,u,a;for(i=e.length,o=n[0].length,c=Array(o),t=o-1;t>=0;t--){for(u=e[i-1]*n[i-1][t],r=i-2;r>=1;r-=2)a=r-1,u+=e[r]*n[r][t]+e[a]*n[a][t];0===r&&(u+=e[0]*n[0][t]),c[t]=u}return c},numeric.dotVV=function(e,n){var r,t,i=e.length,o=e[i-1]*n[i-1];for(r=i-2;r>=1;r-=2)t=r-1,o+=e[r]*n[r]+e[t]*n[t];return 0===r&&(o+=e[0]*n[0]),o},numeric.dot=function(e,n){var r=numeric.dim;switch(1e3*r(e).length+r(n).length){case 2002:return n.length<10?numeric.dotMMsmall(e,n):numeric.dotMMbig(e,n);case 2001:return numeric.dotMV(e,n);case 1002:return numeric.dotVM(e,n);case 1001:return numeric.dotVV(e,n);case 1e3:return numeric.mulVS(e,n);case 1:return numeric.mulSV(e,n);case 0:return e*n;default:throw new Error("numeric.dot only works on vectors and matrices")}},numeric.diag=function(e){var n,r,t,i,o=e.length,c=Array(o);for(n=o-1;n>=0;n--){for(i=Array(o),r=n+2,t=o-1;t>=r;t-=2)i[t]=0,i[t-1]=0;for(t>n&&(i[t]=0),i[n]=e[n],t=n-1;t>=1;t-=2)i[t]=0,i[t-1]=0;0===t&&(i[0]=0),c[n]=i}return c},numeric.getDiag=function(e){var n,r=Math.min(e.length,e[0].length),t=Array(r);for(n=r-1;n>=1;--n)t[n]=e[n][n],t[--n]=e[n][n];return 0===n&&(t[0]=e[0][0]),t},numeric.identity=function(e){return numeric.diag(numeric.rep([e],1))},numeric.pointwise=function(e,n,r){void 0===r&&(r="");var t,i,o=[],c=/\[i\]$/,u="",a=!1;for(t=0;t<e.length;t++)c.test(e[t])?u=i=e[t].substring(0,e[t].length-3):i=e[t],"ret"===i&&(a=!0),o.push(i);return o[e.length]="_s",o[e.length+1]="_k",o[e.length+2]='if(typeof _s === "undefined") _s = numeric.dim('+u+');\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i'+(a?"":", ret = Array(_n)")+";\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) ret[i] = arguments.callee("+e.join(",")+",_s,_k+1);\