6 lines
23 KiB
JavaScript
6 lines
23 KiB
JavaScript
/*
|
||
录音
|
||
https://github.com/xiangyuecn/Recorder
|
||
src: recorder-core.js,engine/wav.js
|
||
*/
|
||
!function(e){var t="object"==typeof window&&!!window.document,r=t?window:Object;!function(e,w){"use strict";var y=function(){},l=function(e){return"number"==typeof e},F=function(e){return new o(e)},b=F.LM="2023-12-24 18:09",S="https://github.com/xiangyuecn/Recorder",k="Recorder",x="getUserMedia",U="srcSampleRate",G="sampleRate",i="bitRate",I="catch",t=e[k];if(t&&t.LM==b)return t.CLog(t.i18n.$T("K8zP::重复导入{1}",0,k),3);F.IsOpen=function(){var e=F.Stream;if(e){var t=e.getTracks&&e.getTracks()||e.audioTracks||[],r=t[0];if(r){var n=r.readyState;return"live"==n||n==r.LIVE}}return!1},F.BufferSize=4096,F.Destroy=function(){for(var e in N(k+" Destroy"),O(),r)r[e]()};var r={};F.BindDestroy=function(e,t){r[e]=t},F.Support=function(){if(!w)return!1;var e=navigator.mediaDevices||{};return e[x]||(e=navigator)[x]||(e[x]=e.webkitGetUserMedia||e.mozGetUserMedia||e.msGetUserMedia),!!e[x]&&(F.Scope=e,!!F.GetContext())},F.GetContext=function(e){if(!w)return null;var t=window.AudioContext;if(t||(t=window.webkitAudioContext),!t)return null;var r=F.Ctx;if(r&&"closed"!=r.state||(r=F.Ctx=new t,F.NewCtxs=F.NewCtxs||[],F.BindDestroy("Ctx",function(){var e=F.Ctx;e&&e.close&&(e.close(),F.Ctx=0);var t=F.NewCtxs;F.NewCtxs=[];for(var r=0;r<t.length;r++)t[r].close()})),e&&r.close)try{r=new t,F.NewCtxs.push(r)}catch(e){N("GetContext tryNew Error",1,e)}return r},F.CloseNewCtx=function(e){if(e&&e!=F.Ctx){e.close&&e.close();for(var t=F.NewCtxs||[],r=t.length,n=0;n<t.length;n++)if(t[n]==e){t.splice(n,1);break}N($("mSxV::剩{1}个GetContext未close",0,r+"-1="+t.length),t.length?3:0)}};var M=function(e){var t=e.state,r="ctx.state="+t;return"suspended"==t&&(r+=$("nMIy::(注意:ctx不是running状态,rec.open和start至少要有一个在用户操作(触摸、点击等)时进行调用,否则将在rec.start时尝试进行ctx.resume,可能会产生兼容性问题(仅iOS),请参阅文档中runningContext配置)")),r},T="ConnectEnableWebM";F[T]=!0;var L="ConnectEnableWorklet";F[L]=!1;var A=function(e,c){var f=e.BufferSize||F.BufferSize,l=e.Stream,u=l._RC||l._c||F.GetContext(!0);l._c=u;var v,r,p,i=function(e){var t=l._m=u.createMediaStreamSource(l),r=u.destination,n="createMediaStreamDestination";u[n]&&(r=l._d=u[n]()),t.connect(e),e.connect(r)},h="",g=l._call,d=function(e){for(var t in g){for(var r=e.length,n=new Int16Array(r),a=0,o=0;o<r;o++){var i=Math.max(-1,Math.min(1,e[o]));i=i<0?32768*i:32767*i,n[o]=i,a+=Math.abs(i)}for(var s in g)g[s](n,a);return}},m="ScriptProcessor",C="audioWorklet",s=k+" "+C,_="RecProc",w="MediaRecorder",y=w+".WebM.PCM",b=u.createScriptProcessor||u.createJavaScriptNode,S=$("ZGlf::。由于{1}内部1秒375次回调,在移动端可能会有性能问题导致回调丢失录音变短,PC端无影响,暂不建议开启{1}。",0,C),x=function(){r=l.isWorklet=!1,n(l),N($("7TU0::Connect采用老的{1},",0,m)+B.get($(F[L]?"JwCL::但已设置{1}尝试启用{2}":"VGjB::可设置{1}尝试启用{2}",2),[k+"."+L+"=true",C])+h+S,3);var e=l._p=b.call(u,f,1,1);i(e),e.onaudioprocess=function(e){var t=e.inputBuffer.getChannelData(0);d(t)}},M=function(){v=l.isWebM=!1,R(l),r=l.isWorklet=!b||F[L];var t=window.AudioWorkletNode;if(r&&u[C]&&t){var n=function(){return r&&l._na},a=l._na=function(){""!==p&&(clearTimeout(p),p=setTimeout(function(){p=0,n()&&(N($("MxX1::{1}未返回任何音频,恢复使用{2}",0,C,m),3),b&&x())},500))},o=function(){if(n()){var e=l._n=new t(u,_,{processorOptions:{bufferSize:f}});i(e),e.port.onmessage=function(e){p&&(clearTimeout(p),p=""),n()?d(e.data.val):r||N($("XUap::{1}多余回调",0,C),3)},N($("yOta::Connect采用{1},设置{2}可恢复老式{3}",0,C,k+"."+L+"=false",m)+h+S,3)}};u.resume()[g&&"finally"](function(){if(n())if(u[_])o();else{var e,t,r=(t="class "+_+" extends AudioWorkletProcessor{",t+="constructor "+(e=function(e){return e.toString().replace(/^function|DEL_/g,"").replace(/\$RA/g,s)})(function(e){DEL_super(e);var t=this,r=e.processorOptions.bufferSize;t.bufferSize=r,t.buffer=new Float32Array(2*r),t.pos=0,t.port.onmessage=function(e){e.data.kill&&(t.kill=!0,$C.log("$RA kill call"))},$C.log("$RA .ctor call",e)}),t+="process "+e(function(e,t,r){var n=this,a=n.bufferSize,o=n.buffer,i=n.pos;if((e=(e[0]||[])[0]||[]).length){o.set(e,i);var s=~~((i+=e.length)/a)*a;if(s){this.port.postMessage({val:o.slice(0,s)});var c=o.subarray(s,i);(o=new Float32Array(2*a)).set(c),i=c.length,n.buffer=o}n.pos=i}return!n.kill}),t=(t+='}try{registerProcessor("'+_+'", '+_+')}catch(e){$C.error("'+s+' Reg Error",e)}').replace(/\$C\./g,"console."),"data:text/javascript;base64,"+btoa(unescape(encodeURIComponent(t))));u[C].addModule(r).then(function(e){n()&&(u[_]=1,o(),p&&a())})[I](function(e){N(C+".addModule Error",1,e),n()&&x()})}})}else x()};!function(){var e=window[w],t="ondataavailable",r="audio/webm; codecs=pcm";v=l.isWebM=F[T];var n=e&&t in e.prototype&&e.isTypeSupported(r);if(h=n?"":$("VwPd::(此浏览器不支持{1})",0,y),!c||!v||!n)return M();var a=function(){return v&&l._ra},o=(l._ra=function(){""!==p&&(clearTimeout(p),p=setTimeout(function(){a()&&(N($("vHnb::{1}未返回任何音频,降级使用{2}",0,w,C),3),M())},500))},Object.assign({mimeType:r},F.ConnectWebMOptions)),i=l._r=new e(l,o),s=l._rd={sampleRate:u[G]};i[t]=function(e){var t=new FileReader;t.onloadend=function(){if(a()){var e=D(new Uint8Array(t.result),s);if(!e)return;if(-1==e)return void M();p&&(clearTimeout(p),p=""),d(e)}else v||N($("O9P7::{1}多余回调",0,w),3)},t.readAsArrayBuffer(e.data)},i.start(~~(f/48)),N($("LMEm::Connect采用{1},设置{2}可恢复使用{3}或老式{4}",0,y,k+"."+T+"=false",C,m))}()},n=function(e){e._na=null,e._n&&(e._n.port.postMessage({kill:!0}),e._n.disconnect(),e._n=null)},R=function(e){e._ra=null,e._r&&(e._r.stop(),e._r=null)},O=function(e){var t=(e=e||F)==F,r=e.Stream;r&&(r._m&&(r._m.disconnect(),r._m=null),!r._RC&&r._c&&F.CloseNewCtx(r._c),r._RC=null,r._c=null,r._d&&(a(r._d.stream),r._d=null),r._p&&(r._p.disconnect(),r._p.onaudioprocess=r._p=null),n(r),R(r),t&&a(r)),e.Stream=0},a=F.StopS_=function(e){for(var t=e.getTracks&&e.getTracks()||e.audioTracks||[],r=0;r<t.length;r++){var n=t[r];n.stop&&n.stop()}e.stop&&e.stop()};F.SampleData=function(e,t,r,n,a){var o="SampleData";n||(n={});var i=n.index||0,s=n.offset||0,c=n.filter;if(c&&c.fn&&c.sr!=t&&(c=null,N($("d48C::{1}的filter采样率变了,重设滤波",0,o),3)),!c){var f=3*t/4<r?0:r/2*3/4;c={fn:f?F.IIRFilter(!0,t,f):0}}c.sr=t;var l=c.fn,u=n.frameNext||[];a||(a={});var v=a.frameSize||1;a.frameType&&(v="mp3"==a.frameType?1152:1);var p=e.length;p+1<i&&N($("tlbC::{1}似乎传入了未重置chunk {2}",0,o,i+">"+p),3);for(var h=0,g=i;g<p;g++)h+=e[g].length;h=Math.max(0,h-Math.floor(s));var d=t/r;1<d?h=Math.floor(h/d):(d=1,r=t),h+=u.length;for(var m=new Int16Array(h),C=0,g=0;g<u.length;g++)m[C]=u[g],C++;for(;i<p;i++){for(var _=e[i],g=s,w=_.length,y=l&&l.Embed,b=0,S=0,x=0,M=0,k=0,I=0;k<w;k++,I++)if(I<w&&(y?(x=_[I],M=y.b0*x+y.b1*y.x1+y.b0*y.x2-y.a1*y.y1-y.a2*y.y2,y.x2=y.x1,y.x1=x,y.y2=y.y1,y.y1=M):M=l?l(_[I]):_[I]),b=S,S=M,0!=I){var T=Math.floor(g);if(k==T){var L=Math.ceil(g),A=g-T,R=b,O=L<w?S:R,D=R+(O-R)*A;32767<D?D=32767:D<-32768&&(D=-32768),m[C]=D,C++,g+=d}}else k--;s=Math.max(0,g-w)}u=null;var z=m.length%v;if(0<z){var E=2*(m.length-z);u=new Int16Array(m.buffer.slice(E)),m=new Int16Array(m.buffer.slice(0,E))}return{index:i,offset:s,filter:c,frameNext:u,sampleRate:r,data:m}},F.IIRFilter=function(e,t,r){var n=2*Math.PI*r/t,a=Math.sin(n),o=Math.cos(n),i=a/2,s=1+i,c=-2*o/s,f=(1-i)/s;if(e)var l=(1-o)/2/s,u=(1-o)/s;else var l=(1+o)/2/s,u=-(1+o)/s;var v=0,p=0,h=0,g=0,d=0,m=function(e){return h=l*e+u*v+l*p-c*g-f*d,p=v,v=e,d=g,g=h};return m.Embed={x1:0,x2:0,y1:0,y2:0,b0:l,b1:u,a1:c,a2:f},m},F.PowerLevel=function(e,t){var r=e/t||0;return r<1251?Math.round(r/1250*10):Math.round(Math.min(100,Math.max(0,100*(1+Math.log(r/1e4)/Math.log(10)))))},F.PowerDBFS=function(e){var t=Math.max(.1,e||0);return t=Math.min(t,32767),t=20*Math.log(t/32767)/Math.log(10),Math.max(-100,Math.round(t))},F.CLog=function(e,t){if("object"==typeof console){var r=new Date,n=("0"+r.getMinutes()).substr(-2)+":"+("0"+r.getSeconds()).substr(-2)+"."+("00"+r.getMilliseconds()).substr(-3),a=this&&this.envIn&&this.envCheck&&this.id,o=["["+n+" "+k+(a?":"+a:"")+"]"+e],i=arguments,s=F.CLog,c=2,f=s.log||console.log;for(l(t)?f=1==t?s.error||console.error:3==t?s.warn||console.warn:f:c=1;c<i.length;c++)o.push(i[c]);u?f&&f("[IsLoser]"+o[0],1<o.length?o:""):f.apply(console,o)}};var N=function(){F.CLog.apply(this,arguments)},u=!0;try{u=!console.log.apply}catch(e){}var s=0;function o(e){var t=this;t.id=++s,c();var r={type:"mp3",onProcess:y};for(var n in e)r[n]=e[n];var a=(t.set=r)[i],o=r[G];(a&&!l(a)||o&&!l(o))&&t.CLog($.G("IllegalArgs-1",[$("VtS4::{1}和{2}必须是数值",0,G,i)]),1,e),r[i]=+a||16,r[G]=+o||16e3,t.state=0,t._S=9,t.Sync={O:9,C:9}}F.Sync={O:9,C:9},F.prototype=o.prototype={CLog:N,_streamStore:function(){return this.set.sourceStream?this:F},_streamCtx:function(){var e=this._streamStore().Stream;return e&&e._c},open:function(e,r){var n=this,a=n.set,o=n._streamStore(),i=0;e=e||y;var s=function(e,t){t=!!t,n.CLog($("5tWi::录音open失败:")+e+",isUserNotAllow:"+t,1),i&&F.CloseNewCtx(i),r&&r(e,t)};n._streamTag=x;var c=function(){n.CLog("open ok, id:"+n.id+" stream:"+n._streamTag),e(),n._SO=0},f=o.Sync,l=++f.O,u=f.C;n._O=n._O_=l,n._SO=n._S;if(w){var t=n.envCheck({envName:"H5",canProcess:!0});if(t)s($("A5bm::不能录音:")+t);else if(a.sourceStream){if(n._streamTag="set.sourceStream",!F.GetContext())return void s($("1iU7::不支持此浏览器从流中获取录音"));O(o);var v=n.Stream=a.sourceStream;v._RC=a.runningContext,v._call={};try{A(o)}catch(e){return O(o),void s($("BTW2::从流中打开录音失败:")+e.message)}c()}else{var p=function(e,t){try{window.top.a}catch(e){return void s($("Nclz::无权录音(跨域,请尝试给iframe添加麦克风访问策略,如{1})",0,'allow="camera;microphone"'))}/Permission|Allow/i.test(e)?s($("gyO5::用户拒绝了录音权限"),!0):!1===window.isSecureContext?s($("oWNo::浏览器禁止不安全页面录音,可开启https解决")):/Found/i.test(e)?s(t+$("jBa9::,无可用麦克风")):s(t)};if(F.IsOpen())c();else if(F.Support()){var h=a.runningContext;h||(h=i=F.GetContext(!0));var g=function(t){setTimeout(function(){t._call={};var e=F.Stream;e&&(O(),t._call=e._call),(F.Stream=t)._c=h,t._RC=a.runningContext,function(){if(u!=f.C||!n._O){var e=$("dFm8::open被取消");return l==f.O?n.close():e=$("VtJO::open被中断"),s(e),!0}}()||(F.IsOpen()?(e&&n.CLog($("upb8::发现同时多次调用open"),1),A(o,1),c()):s($("Q1GA::录音功能无效:无音频流")))},100)},d=function(e){var t=e.name||e.message||e.code+":"+e;n.CLog($("xEQR::请求录音权限错误"),1,e),p(t,$("bDOG::无法录音:")+t)},m=a.audioTrackSet||{};m[G]=h[G];var C={audio:m};try{var _=F.Scope[x](C,g,d)}catch(e){n.CLog(x,3,e),C={audio:!0},_=F.Scope[x](C,g,d)}n.CLog(x+"("+JSON.stringify(C)+") "+M(h)+$("RiWe::,未配置noiseSuppression和echoCancellation时浏览器可能会自动打开降噪和回声消除,移动端可能会降低系统播放音量(关闭录音后可恢复),请参阅文档中audioTrackSet配置")+"("+S+") LM:"+b+" UA:"+navigator.userAgent),_&&_.then&&_.then(g)[I](d)}else p("",$("COxc::此浏览器不支持录音"))}}else s($.G("NonBrowser-1",["open"])+$("EMJq::,可尝试使用RecordApp解决方案")+"("+S+"/tree/master/app-support-sample)")},close:function(e){e=e||y;var t=this,r=t._streamStore();t._stop();var n=" stream:"+t._streamTag,a=r.Sync;if(t._O=0,t._O_!=a.O)return t.CLog($("hWVz::close被忽略(因为同时open了多个rec,只有最后一个会真正close)")+n,3),void e();a.C++,O(r),t.CLog("close,"+n),e()},mock:function(e,t){var r=this;return r._stop(),r.isMock=1,r.mockEnvInfo=null,r.buffers=[e],r.recSize=e.length,r._setSrcSR(t),r._streamTag="mock",r},_setSrcSR:function(e){var t=this.set,r=t[G];e<r?t[G]=e:r=0,this[U]=e,this.CLog(U+": "+e+" set."+G+": "+t[G]+(r?" "+$("UHvm::忽略")+": "+r:""),r?3:0)},envCheck:function(e){var t,r=this.set,n="CPU_BE";if(t||F[n]||"function"!=typeof Int8Array||new Int8Array(new Int32Array([1]).buffer)[0]||(c(n),t=$("Essp::不支持{1}架构",0,n)),!t){var a=r.type,o=this[a+"_envCheck"];r.takeoffEncodeChunk&&(o?e.canProcess||(t=$("7uMV::{1}环境不支持实时处理",0,e.envName)):t=$("2XBl::{1}类型不支持设置takeoffEncodeChunk",0,a)+(this[a]?"":$("LG7e::(未加载编码器)"))),!t&&o&&(t=this[a+"_envCheck"](e,r))}return t||""},envStart:function(e,t){var r=this,n=r.set;if(r.isMock=e?1:0,r.mockEnvInfo=e,r.buffers=[],r.recSize=0,e&&(r._streamTag="env$"+e.envName),r.state=1,r.envInLast=0,r.envInFirst=0,r.envInFix=0,r.envInFixTs=[],r._setSrcSR(t),r.engineCtx=0,r[n.type+"_start"]){var a=r.engineCtx=r[n.type+"_start"](n);a&&(a.pcmDatas=[],a.pcmSize=0)}},envResume:function(){this.envInFixTs=[]},envIn:function(e,t){var a=this,o=a.set,i=a.engineCtx;if(1==a.state){var r=a[U],n=e.length,s=F.PowerLevel(t,n),c=a.buffers,f=c.length;c.push(e);var l=c,u=f,v=Date.now(),p=Math.round(n/r*1e3);a.envInLast=v,1==a.buffers.length&&(a.envInFirst=v-p);var h=a.envInFixTs;h.splice(0,0,{t:v,d:p});for(var g=v,d=0,m=0;m<h.length;m++){var C=h[m];if(3e3<v-C.t){h.length=m;break}g=C.t,d+=C.d}var _=h[1],w=v-g,y=w-d;if(w/3<y&&(_&&1e3<w||6<=h.length)){var b=v-_.t-p;if(p/5<b){var S=!o.disableEnvInFix;if(a.CLog("["+v+"]"+B.get($(S?"4Kfd::补偿{1}ms":"bM5i::未补偿{1}ms",1),[b]),3),a.envInFix+=b,S){var x=new Int16Array(b*r/1e3);n+=x.length,c.push(x)}}}var M=a.recSize,k=n,I=M+k;if(a.recSize=I,i){var T=F.SampleData(c,r,o[G],i.chunkInfo);i.chunkInfo=T,M=i.pcmSize,k=T.data.length,I=M+k,i.pcmSize=I,c=i.pcmDatas,f=c.length,c.push(T.data),r=T[G]}var L=Math.round(I/r*1e3),A=c.length,R=l.length,O=function(){for(var e=D?0:-k,t=null==c[0],r=f;r<A;r++){var n=c[r];null==n?t=1:(e+=n.length,i&&n.length&&a[o.type+"_encode"](i,n))}if(t&&i){var r=u;for(l[0]&&(r=0);r<R;r++)l[r]=null}t&&(e=D?k:0,c[0]=null),i?i.pcmSize+=e:a.recSize+=e},D=0,z="rec.set.onProcess";try{D=o.onProcess(c,s,L,r,f,O)}catch(e){console.error(z+$("gFUF::回调出错是不允许的,需保证不会抛异常"),e)}var E=Date.now()-v;if(10<E&&1e3<a.envInFirst-v&&a.CLog(z+$("2ghS::低性能,耗时{1}ms",0,E),3),!0===D){for(var N=0,m=f;m<A;m++)null==c[m]?N=1:c[m]=new Int16Array(0);N?a.CLog($("ufqH::未进入异步前不能清除buffers"),3):i?i.pcmSize-=k:a.recSize-=k}else O()}else a.state||a.CLog("envIn at state=0",3)},start:function(){var t=this,e=1;if(t.set.sourceStream?t.Stream||(e=0):F.IsOpen()||(e=0),e){var r=t._streamCtx();if(t.CLog($("kLDN::start 开始录音,")+M(r)+" stream:"+t._streamTag),t._stop(),t.envStart(null,r[G]),t.state=3,t._SO&&t._SO+1!=t._S)t.CLog($("Bp2y::start被中断"),3);else{t._SO=0;var n=function(){3==t.state&&(t.state=1,t.resume())};if("suspended"==r.state){var a="AudioContext resume: ";t.CLog(a+"wait..."),r.resume().then(function(){t.CLog(a+r.state),n()})[I](function(e){t.CLog(a+r.state+$("upkE::,可能无法录音:")+e.message,1,e),n()})}else n()}}else t.CLog($("6WmN::start失败:未open"),1)},pause:function(){var e=this,t=e._streamStore().Stream;e.state&&(e.state=2,e.CLog("pause"),t&&delete t._call[e.id])},resume:function(){var r=this,e=r._streamStore().Stream;r.state&&(r.state=1,r.CLog("resume"),r.envResume(),e&&(e._call[r.id]=function(e,t){1==r.state&&r.envIn(e,t)},function(e){e._na&&e._na();e._ra&&e._ra()}(e)))},_stop:function(e){var t=this,r=t.set;t.isMock||t._S++,t.state&&(t.pause(),t.state=0),!e&&t[r.type+"_stop"]&&(t[r.type+"_stop"](t.engineCtx),t.engineCtx=0)},stop:function(u,t,e){var v,p=this,h=p.set,r=p.envInLast-p.envInFirst,n=r&&p.buffers.length;p.CLog($("Xq4s::stop 和start时差:")+(r?r+"ms "+$("3CQP::补偿:")+p.envInFix+"ms envIn:"+n+" fps:"+(n/r*1e3).toFixed(1):"-")+" stream:"+p._streamTag+" ("+S+") LM:"+b);var g=function(){p._stop(),e&&p.close()},d=function(e){p.CLog($("u8JG::结束录音失败:")+e,1),t&&t(e),g()},a=function(e,t,r){var n="arraybuffer",a="dataType",o="DefaultDataType",i=p[a]||F[o]||"blob",s=a+"="+i,c=e instanceof ArrayBuffer,f=0,l=c?e.byteLength:e.size;if(i==n?c||(f=1):"blob"==i?"function"!=typeof Blob?f=$.G("NonBrowser-1",[s])+$("1skY::,请设置{1}",0,k+"."+o+'="'+n+'"'):(c&&(e=new Blob([e],{type:t})),e instanceof Blob||(f=1),t=e.type||t):f=$.G("NotSupport-1",[s]),p.CLog($("Wv7l::结束录音 编码花{1}ms 音频时长{2}ms 文件大小{3}b",0,Date.now()-v,r,l)+" "+s+","+t),f)d(1!=f?f:$("Vkbd::{1}编码器返回的不是{2}",0,h.type,i)+", "+s);else{if(h.takeoffEncodeChunk)p.CLog($("QWnr::启用takeoffEncodeChunk后stop返回的blob长度为0不提供音频数据"),3);else if(l<Math.max(50,r/5))return void d($("Sz2H::生成的{1}无效",0,h.type));u&&u(e,r,t),g()}};if(!p.isMock){var o=3==p.state;if(!p.state||o)return void d($("wf9t::未开始录音")+(o?$("Dl2c::,开始录音前无用户交互导致AudioContext未运行"):""))}p._stop(!0);var i=p.recSize;if(i)if(p[h.type]){if(p.isMock){var s=p.envCheck(p.mockEnvInfo||{envName:"mock",canProcess:!1});if(s)return void d($("AxOH::录音错误:")+s)}var c=p.engineCtx;if(p[h.type+"_complete"]&&c){var f=Math.round(c.pcmSize/h[G]*1e3);return v=Date.now(),void p[h.type+"_complete"](c,function(e,t){a(e,t,f)},d)}if(v=Date.now(),p.buffers[0]){var l=F.SampleData(p.buffers,p[U],h[G]);h[G]=l[G];var m=l.data,f=Math.round(m.length/h[G]*1e3);p.CLog($("CxeT::采样:{1} 花:{2}ms",0,i+"->"+m.length,Date.now()-v)),setTimeout(function(){v=Date.now(),p[h.type](m,function(e,t){a(e,t,f)},function(e){d(e)})})}else d($("xkKd::音频buffers被释放"))}else d($("xGuI::未加载{1}编码器,请尝试到{2}的src/engine内找到{1}的编码器并加载",0,h.type,k));else d($("Ltz3::未采集到录音"))}};var D=function(e,t){t.pos||(t.pos=[0],t.tracks={},t.bytes=[]);var r=t.tracks,n=[t.pos[0]],a=function(){t.pos[0]=n[0]},o=t.bytes.length,i=new Uint8Array(o+e.length);if(i.set(t.bytes),i.set(e,o),t.bytes=i,!t._ht){if(W(i,n),P(i,n),!z(W(i,n),[24,83,128,103]))return;for(W(i,n);n[0]<i.length;){var s=W(i,n),c=P(i,n),f=[0],l=0;if(!c)return;if(z(s,[22,84,174,107])){for(;f[0]<c.length;){var u=W(c,f),v=P(c,f),p=[0],h={channels:0,sampleRate:0};if(z(u,[174]))for(;p[0]<v.length;){var g=W(v,p),d=P(v,p),m=[0];if(z(g,[215])){var C=E(d);h.number=C,r[C]=h}else if(z(g,[131])){var C=E(d);1==C?h.type="video":2==C?(h.type="audio",l||(t.track0=h),h.idx=l++):h.type="Type-"+C}else if(z(g,[134])){for(var _="",w=0;w<d.length;w++)_+=String.fromCharCode(d[w]);h.codec=_}else if(z(g,[225]))for(;m[0]<d.length;){var y=W(d,m),b=P(d,m);if(z(y,[181])){var C=0,S=new Uint8Array(b.reverse()).buffer;4==b.length?C=new Float32Array(S)[0]:8==b.length?C=new Float64Array(S)[0]:N("WebM Track !Float",1,b),h[G]=Math.round(C)}else z(y,[98,100])?h.bitDepth=E(b):z(y,[159])&&(h.channels=E(b))}}}t._ht=1,N("WebM Tracks",r),a();break}}}var x=t.track0;if(x){if(16==x.bitDepth&&/FLOAT/i.test(x.codec)&&(x.bitDepth=32,N("WebM 16->32 bit",3)),x[G]!=t[G]||32!=x.bitDepth||x.channels<1||!/(\b|_)PCM\b/i.test(x.codec))return t.bytes=[],t.bad||N("WebM Track Unexpected",3,t),-(t.bad=1);for(var M=[],k=0;n[0]<i.length;){var u=W(i,n),v=P(i,n);if(!v)break;if(z(u,[163])){var I=15&v[0],h=r[I];if(h){if(0===h.idx){for(var T=new Uint8Array(v.length-4),w=4;w<v.length;w++)T[w-4]=v[w];M.push(T),k+=T.length}}else N("WebM !Track"+I,1,r)}a()}if(k){var L=new Uint8Array(i.length-t.pos[0]);L.set(i.subarray(t.pos[0])),t.bytes=L,t.pos[0]=0;for(var T=new Uint8Array(k),w=0,A=0;w<M.length;w++)T.set(M[w],A),A+=M[w].length;var S=new Float32Array(T.buffer);if(1<x.channels){for(var R=[],w=0;w<S.length;)R.push(S[w]),w+=x.channels;S=new Float32Array(R)}return S}}},z=function(e,t){if(!e||e.length!=t.length)return!1;if(1==e.length)return e[0]==t[0];for(var r=0;r<e.length;r++)if(e[r]!=t[r])return!1;return!0},E=function(e){for(var t="",r=0;r<e.length;r++){var n=e[r];t+=(n<16?"0":"")+n.toString(16)}return parseInt(t,16)||0},W=function(e,t,r){var n=t[0];if(!(n>=e.length)){var a=e[n],o=("0000000"+a.toString(2)).substr(-8),i=/^(0*1)(\d*)$/.exec(o);if(i){var s=i[1].length,c=[];if(!(n+s>e.length)){for(var f=0;f<s;f++)c[f]=e[n],n++;return r&&(c[0]=parseInt(i[2]||"0",2)),t[0]=n,c}}}},P=function(e,t){var r=W(e,t,1);if(r){var n=E(r),a=t[0],o=[];if(n<2147483647){if(a+n>e.length)return;for(var i=0;i<n;i++)o[i]=e[a],a++}return t[0]=a,o}},B=F.i18n={lang:"zh-CN",alias:{"zh-CN":"zh","en-US":"en"},locales:{},data:{},put:function(e,t){var r=k+".i18n.put: ",n=e.overwrite;n=null==n||n;var a=e.lang;if(!(a=B.alias[a]||a))throw new Error(r+"set.lang?");var o=B.locales[a];o||(o={},B.locales[a]=o);for(var i,s=/^([\w\-]+):/,c=0;c<t.length;c++){var f=t[c];if(i=s.exec(f)){var l=i[1],f=f.substr(l.length+1);!n&&o[l]||(o[l]=f)}else N(r+"'key:'? "+f,3,e)}},get:function(){return B.v_G.apply(null,arguments)},v_G:function(n,a,e){a=a||[],e=e||B.lang,e=B.alias[e]||e;var t=B.locales[e],o=t&&t[n]||"";return o||"zh"==e?(B.lastLang=e,"=Empty"==o?"":o.replace(/\{(\d+)(\!?)\}/g,function(e,t,r){return e=a[(t=+t||0)-1],(t<1||t>a.length)&&(e="{?}",N("i18n["+n+"] no {"+t+"}: "+o,3)),r?"":e})):"en"==e?B.v_G(n,a,"zh"):B.v_G(n,a,"en")},$T:function(){return B.v_T.apply(null,arguments)},v_T:function(){for(var e,t=arguments,r="",n=[],a=0,o=k+".i18n.$T:",i=/^([\w\-]*):/,s=0;s<t.length;s++){var c=t[s];if(0==s){if(e=i.exec(c),!(r=e&&e[1]))throw new Error(o+"0 'key:'?");c=c.substr(r.length+1)}if(-1===a)n.push(c);else{if(a)throw new Error(o+" bad args");if(0===c)a=-1;else if(l(c)){if(c<1)throw new Error(o+" bad args");a=c}else{var f=1==s?"en":s?"":"zh";if((e=i.exec(c))&&(f=e[1]||f,c=c.substr(e[1].length+1)),!e||!f)throw new Error(o+s+" 'lang:'?");B.put({lang:f,overwrite:!1},[r+":"+c])}}}return r?0<a?r:B.v_G(r,n):""}},$=B.$T;$.G=B.get,$("NonBrowser-1::非浏览器环境,不支持{1}",1),$("IllegalArgs-1::参数错误:{1}",1),$("NeedImport-2::调用{1}需要先导入{2}",2),$("NotSupport-1::不支持:{1}",1),F.TrafficImgUrl="//ia.51.la/go1?id=20469973&pvFlag=1";var c=F.Traffic=function(e){if(w){e=e?"/"+k+"/Report/"+e:"";var t=F.TrafficImgUrl;if(t){var r=F.Traffic,n=/^(https?:..[^\/#]*\/?)[^#]*/i.exec(location.href)||[],a=n[1]||"http://file/",o=(n[0]||a)+e;if(0==t.indexOf("//")&&(t=/^https:/i.test(o)?"https:"+t:"http:"+t),e&&(t=t+"&cu="+encodeURIComponent(a+e)),!r[o]){r[o]=1;var i=new Image;i.src=t,N("Traffic Analysis Image: "+(e||k+".TrafficImgUrl="+F.TrafficImgUrl))}}}};t&&(N($("8HO5::覆盖导入{1}",0,k),1),t.Destroy());e[k]=F}(r,t),"function"==typeof define&&define.amd&&define(function(){return r.Recorder}),"object"==typeof module&&module.exports&&(module.exports=r.Recorder)}(),function(e){var t="object"==typeof window&&!!window.document,r=(t?window:Object).Recorder,n=r.i18n;!function(p,e,h,t){"use strict";p.prototype.enc_wav={stable:!0,fast:!0,getTestMsg:function(){return h("gPSE::支持位数8位、16位(填在比特率里面),采样率取值无限制;此编码器仅在pcm数据前加了一个44字节的wav头,编码出来的16位wav文件去掉开头的44字节即可得到pcm(注:其他wav编码器可能不是44字节)")}};p.prototype.wav=function(e,t,r){var n=this.set;!function(e){var t=e.bitRate,r=8==t?8:16;t!=r&&p.CLog(h("wyw9::WAV Info: 不支持{1}位,已更新成{2}位",0,t,r),3);e.bitRate=r}(n);var a=e.length,o=n.sampleRate,i=n.bitRate,s=a*(i/8),c=p.wav_header(1,1,o,i,s),f=c.length,l=new Uint8Array(f+s);if(l.set(c),8==i)for(var u=0;u<a;u++){var v=128+(e[u]>>8);l[f++]=v}else(l=new Int16Array(l.buffer)).set(e,f/2);t(l.buffer,"audio/wav")},p.wav_header=function(e,t,r,n,a){var o=1==e?0:2,i=new ArrayBuffer(44+o),s=new DataView(i),c=0,f=function(e){for(var t=0;t<e.length;t++,c++)s.setUint8(c,e.charCodeAt(t))},l=function(e){s.setUint16(c,e,!0),c+=2},u=function(e){s.setUint32(c,e,!0),c+=4};return f("RIFF"),u(36+o+a),f("WAVE"),f("fmt "),u(16+o),l(e),l(t),u(r),u(r*(t*n/8)),l(t*n/8),l(n),1!=e&&l(0),f("data"),u(a),new Uint8Array(i)}}(r,0,n.$T)}(); |