UnisKB/node_modules/recorder-core/recorder.mp3.min.js

6 lines
141 KiB
JavaScript
Raw Normal View History

2025-06-11 11:15:17 +00:00
/*
录音
https://github.com/xiangyuecn/Recorder
src: recorder-core.js,engine/mp3.js,engine/mp3-engine.js
*/
!function(e){var t="object"==typeof window&&!!window.document,a=t?window:Object;!function(e,y){"use strict";var A=function(){},f=function(e){return"number"==typeof e},B=function(e){return JSON.stringify(e)},W=function(e){return new _(e)},k=W.LM="2025-01-11 09:28",R="https://github.com/xiangyuecn/Recorder",T="Recorder",x="getUserMedia",N="srcSampleRate",V="sampleRate",i="bitRate",E="catch",t=e[T];if(t&&t.LM==k)return t.CLog(t.i18n.$T("K8zP::重复导入{1}",0,T),3);W.IsOpen=function(){var e=W.Stream;if(e){var t=j(e),a=t[0];if(a){var n=a.readyState;return"live"==n||n==a.LIVE}}return!1},W.BufferSize=4096,W.Destroy=function(){for(var e in Q(T+" Destroy"),F(),a)a[e]()};var a={};W.BindDestroy=function(e,t){a[e]=t},W.Support=function(){if(!y)return!1;var e=navigator.mediaDevices||{};return e[x]||(e=navigator)[x]||(e[x]=e.webkitGetUserMedia||e.mozGetUserMedia||e.msGetUserMedia),!!e[x]&&(W.Scope=e,!!W.GetContext())},W.GetContext=function(e){if(!y)return null;var t=window.AudioContext;if(t||(t=window.webkitAudioContext),!t)return null;var a=W.Ctx,n=0;return a||(a=W.Ctx=new t,n=1,W.NewCtxs=W.NewCtxs||[],W.BindDestroy("Ctx",function(){var e=W.Ctx;e&&e.close&&(s(e),W.Ctx=0);var t=W.NewCtxs;W.NewCtxs=[];for(var a=0;a<t.length;a++)s(t[a])})),e&&a.close&&(n||(a._useC||s(a),a=new t),a._useC=1,W.NewCtxs.push(a)),a},W.CloseNewCtx=function(e){if(e&&e.close){s(e);for(var t=W.NewCtxs||[],a=t.length,n=0;n<t.length;n++)if(t[n]==e){t.splice(n,1);break}Q($("mSxV::剩{1}个GetContext未close",0,a+"-1="+t.length),t.length?3:0)}};var s=function(e){if(e&&e.close&&!e._isC&&(e._isC=1,"closed"!=e.state))try{e.close()}catch(e){Q("ctx close err",1,e)}},C=W.ResumeCtx=function(a,n,s,r){var i=0,o=0,_=0,l=0,f="EventListener",c="ResumeCtx ",u=function(e,t){o&&h(),i||(i=1,e&&r(e,l),t&&s(l)),t&&(!a._LsSC&&a["add"+f]&&a["add"+f]("statechange",b),a._LsSC=1,_=1)},h=function(e){if(!e||!o){o=e?1:0;for(var t=["focus","mousedown","mouseup","touchstart","touchend"],a=0;a<t.length;a++)window[(e?"add":"remove")+f](t[a],b,!0)}},b=function(){var e=a.state,t=p(e);if(!i&&!n(t?++l:l))return u();t?(_&&Q(c+"sc "+e,3),h(1),a.resume().then(function(){_&&Q(c+"sc "+a.state),u(0,1)})[E](function(e){Q(c+"error",1,e),p(a.state)||u(e.message||"error")})):"closed"==e?(_&&!a._isC&&Q(c+"sc "+e,1),u("ctx closed")):u(0,1)};b()},p=W.CtxSpEnd=function(e){return"suspended"==e||"interrupted"==e},I=function(e){var t=e.state,a="ctx.state="+t;return p(t)&&(a+=$("nMIy::注意ctx不是running状态rec.open和start至少要有一个在用户操作(触摸、点击等)时进行调用否则将在rec.start时尝试进行ctx.resume可能会产生兼容性问题(仅iOS)请参阅文档中runningContext配置")),a},L="ConnectEnableWebM";W[L]=!0;var P="ConnectEnableWorklet";W[P]=!1;var H=function(e){var _=e.BufferSize||W.BufferSize,l=e.Stream,i=l._c,f=i[V],c={},t=j(l),a=t[0],n=null,s="";if(a&&a.getSettings){var r=(n=a.getSettings())[V];r&&r!=f&&(s=$("eS8i::Stream的采样率{1}不等于{2}将进行采样率转换注意音质不会变好甚至可能变差主要在移动端未禁用回声消除时会产生此现象浏览器有回声消除时可能只会返回16k采样率的音频数据",0,r,f))}l._ts=n,Q(s+"Stream TrackSet: "+B(n),s?3:0);var u,o,h,b=function(e){var t=l._m=i.createMediaStreamSource(l),a=i.destination,n="createMediaStreamDestination";i[n]&&(a=l._d=i[n]()),t.connect(e),e.connect(a)},p="",m=l._call,v=function(e,t){for(var a in m){if(t!=f){c.index=0;var n=(c=W.SampleData([e],t,f,c,{_sum:1})).data,s=c._sum}else{c={};for(var r=e.length,n=new Int16Array(r),s=0,i=0;i<r;i++){var o=Math.max(-1,Math.min(1,e[i]));o=o<0?32768*o:32767*o,n[i]=o,s+=Math.abs(o)}}for(var _ in m)m[_](n,s);return}},d="ScriptProcessor",g="audioWorklet",S=T+" "+g,w="RecProc",M="MediaRecorder",y=M+".WebM.PCM",A=i.createScriptProcessor||i.createJavaScriptNode,k=$("ZGlf::。由于{1}内部1秒375次回调在移动端可能会有性能问题导致回调丢失录音变短PC端无影响暂不建议开启{1}。",0,g),R=function(){o=l.isWorklet=!1,O(l),Q($("7TU0::Connect采用老的{1}",0