@bothub-chat/ui
Version:
Bothub UI Components
2 lines (1 loc) • 538 B
JavaScript
import{__awaiter as t}from"tslib";const o=(o,...e)=>t(void 0,[o,...e],void 0,(function*(t,o=30){const e=new(window.AudioContext||window.webkitAudioContext),n=yield t.arrayBuffer(),a=yield e.decodeAudioData(n),i=a.getChannelData(0),r=Math.floor(i.length/o),d=[];for(let t=0;t<o;t++){const o=t*r,e=o+r;let n=0;for(let t=o;t<e&&t<i.length;t++)n+=i[t]*i[t];const a=Math.sqrt(n/r);d.push(a)}const l=Math.max(...d);if(l>0)for(let t=0;t<d.length;t++)d[t]=d[t]/l*100;return e.close(),{waveData:d,duration:a.duration}}));export{o as getWaveData};