bricks/3parties/recorder.wav.min.js

6 lines
23 KiB
JavaScript
Raw Normal View History

2024-03-01 15:33:39 +08:00
/*
录音
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(