@aim-packages/subtitle 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +40 -0
- package/dist/index.es.js +347 -309
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var St=Object.defineProperty;var jt=(e,t,r)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var
|
|
1
|
+
"use strict";var St=Object.defineProperty;var jt=(e,t,r)=>t in e?St(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var v=(e,t,r)=>jt(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function U(e,t=2){return e.toString().padStart(t,"0")}function y(e){const t=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%3600%60,a=Math.floor(n%1*1e3),c=U(t),s=U(r),u=U(Math.floor(n)),i=U(a,3);return`${c}:${s}:${u}.${i}`}function A(e){if(!e)return 0;const t=e.split(":");try{let r=t[2].split(",");return r.length===1&&(r=t[2].split(".")),parseFloat(t[0])*3600+parseFloat(t[1])*60+parseFloat(r[0])+parseFloat("0."+r[1])}catch{return 0}}function Ve(e){return/[\u4E00-\u9FFF\u3040-\u309F\u30A0-\u30FF\uAC00-\uD7AF]/.test(e)}const $t=Object.freeze(Object.defineProperty({__proto__:null,containsCJKCharacters:Ve,convertToSeconds:A,formatTime:y,padNumber:U},Symbol.toStringTag,{value:"Module"}));/**
|
|
2
2
|
* @name ass2vtt
|
|
3
3
|
* @desc Converts ASS subtitle data into VTT format.
|
|
4
4
|
* @author YuQian2015 (https://github.com/YuQian2015)
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
`).split(/(?:\r\n|\r|\n)/gm),c=wt(a)+1;let s=0,u,i,o;for(let f=0;f<c;f++){for(o={},i=[],f=Ot(a,f),o.id=parseInt(a[f++],10),u=a[f++].split(/[\t ]*-->[\t ]*/),o[t.propName.start||"start"]=t.timeInText?u[0]:A(u[0]),s=u[1].indexOf(" "),s!==-1&&(u[1]=u[1].substr(0,s)),o[t.propName.end||"end"]=t.timeInText?u[1]:A(u[1]);f<c&&a[f];)i.push(a[f++]);const l=t.propName.text||"text";o[l]=i.join(t.keepMultiLine?`
|
|
23
23
|
`:" ").replace(/\{(\\[\w]+\(?([\w\d]+,?)+\)?)+\}/gi,""),o[l]=o[l].replace(/</g,"<").replace(/>/g,">"),o[l]=o[l].replace(/<(\/?(font|b|u|i|s))((\s+(\w|\w[\w\-]*\w)(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)(\/?)>/gi,"<$1$3$7>"),t.ignoreLineBreaks?o[l]=o[l].replace(/\\N/gi,""):o[l]=o[l].replace(/\\N/gi,"<br />"),r.push(o)}return r}function Pt(e,t){const r=/<\/?[^>]+(>|$)/g;return new Promise((n,a)=>{let c={};const s=[];let u=!1;const i=e.split(`
|
|
24
24
|
`);i.forEach((f,l)=>{f.replace(r,"")===" "||f.replace(r,"")===""||(f.indexOf("-->")!==-1?(u=!0,typeof c.start=="number"&&c.start>=0&&s.push(se(c)),c={start:ae(f.split("-->")[0].trimRight().split(" ").pop()),end:ae(f.split("-->")[1].trimLeft().split(" ").shift()),part:""}):u&&(s.length!==0?(s[s.length-1].part.replace(r,""),f.replace(r,""),c.part.length===0?c.part=f:c.part=`${c.part}
|
|
25
|
-
${f}`,l===i.length-1&&s.push(se(c))):(c.part=f,s.push(se(c)),c.part="")))}),c=[];const o=/(<([0-9:.>]+)>)/ig;s.forEach(f=>{const m=f.part.split().map(function(g){return g.replace(o,function(p){return p.split("").reduce(function(_,k){return`==${p.replace("<","").replace(">","")}`},0)})})[0].replace(r,"").split(" "),b=[];m.forEach(function(g){if(g.indexOf("==")>-1){const p=g.split("=="),_=p[0];if(p[1],_==""||_=="##")return;b.push({word:$e(g.split("==")[0]),time:ae(g.split("==")[1])})}else b.push({word:$e(g),time:void 0})}),f.words=b,f.part=f.part.replace(r,"")}),n(s)})}function ae(e){const t=e.split(":"),r=t[t.length-3]?+t[t.length-3]:0,n=t[t.length-2]?+t[t.length-2]:0,a=+t[t.length-1];return r*3600+n*60+a}function $e(e){return e.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function se(e){if(e==null||typeof e!="object")return e;const t=e.constructor();for(const r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}const ie={padding:[.4,0],maxGap:10,minGap:2,minStart:6};function Et(e){let t,r,n,a,c,s,u,i,o;const f=!!(e&&e.vad&&e.vad.length>0),l="[--end--]",v="[--Single--]",T="[--Full--]",m=/\[(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\]/;let b=!1,g=!1,p="";return _(),{feed:B,reset:_,end:k};function _(){t=!0,r="",n=!1,a="",c=!1,s=void 0,u=0,i=!1,o=0}function k(){if(i){console.log("whisper parser is already end");return}B(l)}function J(j){b||(p+=j),!b&&!g&&We(p)&&(g=!0),!b&&p.length>50&&(b=!0)}function B(j){var me,_e,Se;J(j);const O=[];r+=j,t&&((me=e==null?void 0:e.onStart)==null||me.call(e,{type:"event",event:"start",data:[]})),t&&Ct(r)&&(r=r.slice(qe.length)),t=!1;const Y=r.length;for(;u<Y;){const X=r[u];if(++u,c&&s&&X!=="["&&(s.text+=X),X==="["&&(n&&a.length&&s&&(s.text+=a),a="",n=!0,c=!1),n){if(a+=X,a===T&&(a=""),a===v&&(a="",f&&o++),a===l){s&&O.push(s),i=!0;break}if(m.test(a)){const I=m.exec(a),D=I==null?void 0:I[1],ne=I==null?void 0:I[2];if(s&&O.push(s),D&&ne){if(f&&(e!=null&&e.vad)&&e.vad.length>0){let Z=0;Z=e.vad[o].start-ie.padding[0]<0?0:e.vad[o].start-ie.padding[0];const _t=D==="00:00:00.000";let je=w(A(D)+Z);o>0&&_t&&(je=w(A(D)+Z+ie.padding[0])),s={st:je,et:w(A(ne)+Z),text:"",children:[]}}else s={st:D,et:ne,text:"",children:[]};c=!0,n=!1,a=""}}}}O.length&&((_e=e==null?void 0:e.onParse)==null||_e.call(e,{type:"event",event:"message",data:O})),i&&((Se=e==null?void 0:e.onEnd)==null||Se.call(e,{type:"event",event:"end",data:r}),_())}}const qe=[239,187,191];function Ct(e){return qe.every((t,r)=>e.charCodeAt(r)===t)}function Ft(e){let t,r,n,a,c,s,u,i;const o=/\[(\d+)\]/,f="[--end--]";return l(),{feed:T,reset:l,end:v};function l(){t=!0,r="",n=0,i=!1,s="",a=void 0,c=!1,u=!1}function v(){T(f)}function T(m){var p,_,k,J,B;const b=[];r+=m,t&&((p=e==null?void 0:e.onStart)==null||p.call(e,{type:"event",event:"start",data:[]})),t&&It(r)&&(r=r.slice(Je.length)),t=!1;const g=r.length;for(;n<g;){const j=r[n];if(++n,u&&a&&j!=="["&&(a.text+=j,(_=e==null?void 0:e.onProgress)==null||_.call(e,{type:"event",event:"message",data:[a]})),j==="["&&(c&&s.length&&a&&(a.text+=s,(k=e==null?void 0:e.onProgress)==null||k.call(e,{type:"event",event:"message",data:[a]})),s="",c=!0,u=!1),c){if(s+=j,s===f){a&&b.push(a),i=!0;break}if(o.test(s)){const O=o.exec(s),Y=O==null?void 0:O[1];a&&b.push(a),Y&&(a={index:Number(Y),text:""},u=!0,c=!1,s="")}}}b.length&&((J=e==null?void 0:e.onParse)==null||J.call(e,{type:"event",event:"message",data:b})),i&&((B=e==null?void 0:e.onEnd)==null||B.call(e,{type:"event",event:"end",data:r}),l())}}const Je=[239,187,191];function It(e){return Je.every((t,r)=>e.charCodeAt(r)===t)}async function Lt(e){return At(e,{keepMultiLine:!0,propName:{}}).filter(n=>n.text).map(n=>({st:w(n.start),et:w(n.end),text:n.text}))}async function Ye(e){return(await Pt(e)).filter(n=>n.part).map(n=>({st:w(n.start),et:w(n.end),text:n.part}))}async function Mt(e){return Ye(xt(e))}const zt=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:Mt,createTranslateStreamParser:Ft,createWhisperStreamParser:Et,srtToAimSegments:Lt,vttToAimSegments:Ye},Symbol.toStringTag,{value:"Module"}));class Nt{constructor(t){y(this,"chains",{});y(this,"delimit","__replace__");y(this,"onFilter");y(this,"checked",!1);y(this,"checkedText","");y(this,"checkedLevel");y(this,"filteredText","");this.onFilter=t}add(t,r){typeof t!="string"&&(t=new TextDecoder().decode(t));const n=t;if(!n)return;let a=this.chains;for(let c=0;c<n.length;c++){if(n[c]in a)a=a[n[c]];else{if(!(a instanceof Object))break;let s,u;for(let i=c;i<n.length;i++)a[n[i]]={},[s,u]=[a,n[i]],a=a[n[i]];s&&u&&(s[u]={[this.delimit]:r||""});break}c===n.length-1&&(a[this.delimit]=r||"")}}parse(t){t.forEach(r=>{this.add(...r)})}reParse(t){this.chains={},t.forEach(r=>{this.add(r[0],r[1])})}feed(t){if(!this.checked&&!this.chains[t]){this.filteredText+=t,this.onFilter&&this.onFilter(t);return}if(!this.checked&&this.chains[t]){this.checked=!0,this.checkedLevel=this.chains[t],this.checkedText+=t;return}if(this.checked&&this.checkedLevel[t]){this.checkedLevel=this.checkedLevel[t],this.checkedText+=t;return}if(this.checked&&!this.checkedLevel[t]){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.filteredText+=n,this.onFilter&&this.onFilter(n)}),this.checked=!1,this.checkedText="",this.checkedLevel=void 0,this.chains[t]?(this.checked=!0,this.checkedLevel=this.chains[t],this.checkedText=t):(this.onFilter&&this.onFilter(t),this.filteredText+=t)}}feedAll(t){return t.length?(t.split("").forEach(n=>{this.feed(n)}),this.end()):""}end(){if(this.checked&&this.checkedText){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.onFilter&&this.onFilter(n),this.filteredText+=n}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const t=this.filteredText;return this.filteredText="",t}}const kt=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:Nt},Symbol.toStringTag,{value:"Module"}));var Xe=typeof global=="object"&&global&&global.Object===Object&&global,Bt=typeof self=="object"&&self&&self.Object===Object&&self,S=Xe||Bt||Function("return this")(),L=S.Symbol,Ze=Object.prototype,Dt=Ze.hasOwnProperty,Gt=Ze.toString,G=L?L.toStringTag:void 0;function Ut(e){var t=Dt.call(e,G),r=e[G];try{e[G]=void 0;var n=!0}catch{}var a=Gt.call(e);return n&&(t?e[G]=r:delete e[G]),a}var Rt=Object.prototype,Ht=Rt.toString;function Kt(e){return Ht.call(e)}var Vt="[object Null]",Wt="[object Undefined]",xe=L?L.toStringTag:void 0;function V(e){return e==null?e===void 0?Wt:Vt:xe&&xe in Object(e)?Ut(e):Kt(e)}function W(e){return e!=null&&typeof e=="object"}var de=Array.isArray;function q(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var qt="[object AsyncFunction]",Jt="[object Function]",Yt="[object GeneratorFunction]",Xt="[object Proxy]";function Qe(e){if(!q(e))return!1;var t=V(e);return t==Jt||t==Yt||t==qt||t==Xt}var ce=S["__core-js_shared__"],Oe=function(){var e=/[^.]+$/.exec(ce&&ce.keys&&ce.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function Zt(e){return!!Oe&&Oe in e}var Qt=Function.prototype,er=Qt.toString;function C(e){if(e!=null){try{return er.call(e)}catch{}try{return e+""}catch{}}return""}var tr=/[\\^$.*+?()[\]{}|]/g,rr=/^\[object .+?Constructor\]$/,nr=Function.prototype,ar=Object.prototype,sr=nr.toString,ir=ar.hasOwnProperty,cr=RegExp("^"+sr.call(ir).replace(tr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function or(e){if(!q(e)||Zt(e))return!1;var t=Qe(e)?cr:rr;return t.test(C(e))}function ur(e,t){return e==null?void 0:e[t]}function F(e,t){var r=ur(e,t);return or(r)?r:void 0}var ue=F(S,"WeakMap"),we=Object.create,fr=function(){function e(){}return function(t){if(!q(t))return{};if(we)return we(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();function lr(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}var Ae=function(){try{var e=F(Object,"defineProperty");return e({},"",{}),e}catch{}}();function hr(e,t){for(var r=-1,n=e==null?0:e.length;++r<n&&t(e[r],r,e)!==!1;);return e}var dr=9007199254740991,gr=/^(?:0|[1-9]\d*)$/;function pr(e,t){var r=typeof e;return t=t??dr,!!t&&(r=="number"||r!="symbol"&&gr.test(e))&&e>-1&&e%1==0&&e<t}function et(e,t,r){t=="__proto__"&&Ae?Ae(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function tt(e,t){return e===t||e!==e&&t!==t}var br=Object.prototype,yr=br.hasOwnProperty;function rt(e,t,r){var n=e[t];(!(yr.call(e,t)&&tt(n,r))||r===void 0&&!(t in e))&&et(e,t,r)}function ee(e,t,r,n){var a=!r;r||(r={});for(var c=-1,s=t.length;++c<s;){var u=t[c],i=void 0;i===void 0&&(i=e[u]),a?et(r,u,i):rt(r,u,i)}return r}var vr=9007199254740991;function nt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=vr}function at(e){return e!=null&&nt(e.length)&&!Qe(e)}var Tr=Object.prototype;function ge(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||Tr;return e===r}function mr(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}var _r="[object Arguments]";function Pe(e){return W(e)&&V(e)==_r}var st=Object.prototype,Sr=st.hasOwnProperty,jr=st.propertyIsEnumerable,$r=Pe(function(){return arguments}())?Pe:function(e){return W(e)&&Sr.call(e,"callee")&&!jr.call(e,"callee")};function xr(){return!1}var it=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ee=it&&typeof module=="object"&&module&&!module.nodeType&&module,Or=Ee&&Ee.exports===it,Ce=Or?S.Buffer:void 0,wr=Ce?Ce.isBuffer:void 0,ct=wr||xr,Ar="[object Arguments]",Pr="[object Array]",Er="[object Boolean]",Cr="[object Date]",Fr="[object Error]",Ir="[object Function]",Lr="[object Map]",Mr="[object Number]",zr="[object Object]",Nr="[object RegExp]",kr="[object Set]",Br="[object String]",Dr="[object WeakMap]",Gr="[object ArrayBuffer]",Ur="[object DataView]",Rr="[object Float32Array]",Hr="[object Float64Array]",Kr="[object Int8Array]",Vr="[object Int16Array]",Wr="[object Int32Array]",qr="[object Uint8Array]",Jr="[object Uint8ClampedArray]",Yr="[object Uint16Array]",Xr="[object Uint32Array]",d={};d[Rr]=d[Hr]=d[Kr]=d[Vr]=d[Wr]=d[qr]=d[Jr]=d[Yr]=d[Xr]=!0;d[Ar]=d[Pr]=d[Gr]=d[Er]=d[Ur]=d[Cr]=d[Fr]=d[Ir]=d[Lr]=d[Mr]=d[zr]=d[Nr]=d[kr]=d[Br]=d[Dr]=!1;function Zr(e){return W(e)&&nt(e.length)&&!!d[V(e)]}function pe(e){return function(t){return e(t)}}var ot=typeof exports=="object"&&exports&&!exports.nodeType&&exports,R=ot&&typeof module=="object"&&module&&!module.nodeType&&module,Qr=R&&R.exports===ot,oe=Qr&&Xe.process,M=function(){try{var e=R&&R.require&&R.require("util").types;return e||oe&&oe.binding&&oe.binding("util")}catch{}}(),Fe=M&&M.isTypedArray,en=Fe?pe(Fe):Zr,tn=Object.prototype,rn=tn.hasOwnProperty;function ut(e,t){var r=de(e),n=!r&&$r(e),a=!r&&!n&&ct(e),c=!r&&!n&&!a&&en(e),s=r||n||a||c,u=s?mr(e.length,String):[],i=u.length;for(var o in e)(t||rn.call(e,o))&&!(s&&(o=="length"||a&&(o=="offset"||o=="parent")||c&&(o=="buffer"||o=="byteLength"||o=="byteOffset")||pr(o,i)))&&u.push(o);return u}function ft(e,t){return function(r){return e(t(r))}}var nn=ft(Object.keys,Object),an=Object.prototype,sn=an.hasOwnProperty;function cn(e){if(!ge(e))return nn(e);var t=[];for(var r in Object(e))sn.call(e,r)&&r!="constructor"&&t.push(r);return t}function be(e){return at(e)?ut(e):cn(e)}function on(e){var t=[];if(e!=null)for(var r in Object(e))t.push(r);return t}var un=Object.prototype,fn=un.hasOwnProperty;function ln(e){if(!q(e))return on(e);var t=ge(e),r=[];for(var n in e)n=="constructor"&&(t||!fn.call(e,n))||r.push(n);return r}function ye(e){return at(e)?ut(e,!0):ln(e)}var H=F(Object,"create");function hn(){this.__data__=H?H(null):{},this.size=0}function dn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var gn="__lodash_hash_undefined__",pn=Object.prototype,bn=pn.hasOwnProperty;function yn(e){var t=this.__data__;if(H){var r=t[e];return r===gn?void 0:r}return bn.call(t,e)?t[e]:void 0}var vn=Object.prototype,Tn=vn.hasOwnProperty;function mn(e){var t=this.__data__;return H?t[e]!==void 0:Tn.call(t,e)}var _n="__lodash_hash_undefined__";function Sn(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=H&&t===void 0?_n:t,this}function E(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}E.prototype.clear=hn;E.prototype.delete=dn;E.prototype.get=yn;E.prototype.has=mn;E.prototype.set=Sn;function jn(){this.__data__=[],this.size=0}function te(e,t){for(var r=e.length;r--;)if(tt(e[r][0],t))return r;return-1}var $n=Array.prototype,xn=$n.splice;function On(e){var t=this.__data__,r=te(t,e);if(r<0)return!1;var n=t.length-1;return r==n?t.pop():xn.call(t,r,1),--this.size,!0}function wn(e){var t=this.__data__,r=te(t,e);return r<0?void 0:t[r][1]}function An(e){return te(this.__data__,e)>-1}function Pn(e,t){var r=this.__data__,n=te(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this}function x(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}x.prototype.clear=jn;x.prototype.delete=On;x.prototype.get=wn;x.prototype.has=An;x.prototype.set=Pn;var K=F(S,"Map");function En(){this.size=0,this.__data__={hash:new E,map:new(K||x),string:new E}}function Cn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function re(e,t){var r=e.__data__;return Cn(t)?r[typeof t=="string"?"string":"hash"]:r.map}function Fn(e){var t=re(this,e).delete(e);return this.size-=t?1:0,t}function In(e){return re(this,e).get(e)}function Ln(e){return re(this,e).has(e)}function Mn(e,t){var r=re(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this}function z(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}z.prototype.clear=En;z.prototype.delete=Fn;z.prototype.get=In;z.prototype.has=Ln;z.prototype.set=Mn;function lt(e,t){for(var r=-1,n=t.length,a=e.length;++r<n;)e[a+r]=t[r];return e}var ht=ft(Object.getPrototypeOf,Object);function zn(){this.__data__=new x,this.size=0}function Nn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}function kn(e){return this.__data__.get(e)}function Bn(e){return this.__data__.has(e)}var Dn=200;function Gn(e,t){var r=this.__data__;if(r instanceof x){var n=r.__data__;if(!K||n.length<Dn-1)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new z(n)}return r.set(e,t),this.size=r.size,this}function N(e){var t=this.__data__=new x(e);this.size=t.size}N.prototype.clear=zn;N.prototype.delete=Nn;N.prototype.get=kn;N.prototype.has=Bn;N.prototype.set=Gn;function Un(e,t){return e&&ee(t,be(t),e)}function Rn(e,t){return e&&ee(t,ye(t),e)}var dt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ie=dt&&typeof module=="object"&&module&&!module.nodeType&&module,Hn=Ie&&Ie.exports===dt,Le=Hn?S.Buffer:void 0,Me=Le?Le.allocUnsafe:void 0;function Kn(e,t){if(t)return e.slice();var r=e.length,n=Me?Me(r):new e.constructor(r);return e.copy(n),n}function Vn(e,t){for(var r=-1,n=e==null?0:e.length,a=0,c=[];++r<n;){var s=e[r];t(s,r,e)&&(c[a++]=s)}return c}function gt(){return[]}var Wn=Object.prototype,qn=Wn.propertyIsEnumerable,ze=Object.getOwnPropertySymbols,ve=ze?function(e){return e==null?[]:(e=Object(e),Vn(ze(e),function(t){return qn.call(e,t)}))}:gt;function Jn(e,t){return ee(e,ve(e),t)}var Yn=Object.getOwnPropertySymbols,pt=Yn?function(e){for(var t=[];e;)lt(t,ve(e)),e=ht(e);return t}:gt;function Xn(e,t){return ee(e,pt(e),t)}function bt(e,t,r){var n=t(e);return de(e)?n:lt(n,r(e))}function Zn(e){return bt(e,be,ve)}function Qn(e){return bt(e,ye,pt)}var fe=F(S,"DataView"),le=F(S,"Promise"),he=F(S,"Set"),Ne="[object Map]",ea="[object Object]",ke="[object Promise]",Be="[object Set]",De="[object WeakMap]",Ge="[object DataView]",ta=C(fe),ra=C(K),na=C(le),aa=C(he),sa=C(ue),$=V;(fe&&$(new fe(new ArrayBuffer(1)))!=Ge||K&&$(new K)!=Ne||le&&$(le.resolve())!=ke||he&&$(new he)!=Be||ue&&$(new ue)!=De)&&($=function(e){var t=V(e),r=t==ea?e.constructor:void 0,n=r?C(r):"";if(n)switch(n){case ta:return Ge;case ra:return Ne;case na:return ke;case aa:return Be;case sa:return De}return t});var ia=Object.prototype,ca=ia.hasOwnProperty;function oa(e){var t=e.length,r=new e.constructor(t);return t&&typeof e[0]=="string"&&ca.call(e,"index")&&(r.index=e.index,r.input=e.input),r}var Ue=S.Uint8Array;function Te(e){var t=new e.constructor(e.byteLength);return new Ue(t).set(new Ue(e)),t}function ua(e,t){var r=t?Te(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}var fa=/\w*$/;function la(e){var t=new e.constructor(e.source,fa.exec(e));return t.lastIndex=e.lastIndex,t}var Re=L?L.prototype:void 0,He=Re?Re.valueOf:void 0;function ha(e){return He?Object(He.call(e)):{}}function da(e,t){var r=t?Te(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}var ga="[object Boolean]",pa="[object Date]",ba="[object Map]",ya="[object Number]",va="[object RegExp]",Ta="[object Set]",ma="[object String]",_a="[object Symbol]",Sa="[object ArrayBuffer]",ja="[object DataView]",$a="[object Float32Array]",xa="[object Float64Array]",Oa="[object Int8Array]",wa="[object Int16Array]",Aa="[object Int32Array]",Pa="[object Uint8Array]",Ea="[object Uint8ClampedArray]",Ca="[object Uint16Array]",Fa="[object Uint32Array]";function Ia(e,t,r){var n=e.constructor;switch(t){case Sa:return Te(e);case ga:case pa:return new n(+e);case ja:return ua(e,r);case $a:case xa:case Oa:case wa:case Aa:case Pa:case Ea:case Ca:case Fa:return da(e,r);case ba:return new n;case ya:case ma:return new n(e);case va:return la(e);case Ta:return new n;case _a:return ha(e)}}function La(e){return typeof e.constructor=="function"&&!ge(e)?fr(ht(e)):{}}var Ma="[object Map]";function za(e){return W(e)&&$(e)==Ma}var Ke=M&&M.isMap,Na=Ke?pe(Ke):za,ka="[object Set]";function Ba(e){return W(e)&&$(e)==ka}var Ve=M&&M.isSet,Da=Ve?pe(Ve):Ba,Ga=1,Ua=2,Ra=4,yt="[object Arguments]",Ha="[object Array]",Ka="[object Boolean]",Va="[object Date]",Wa="[object Error]",vt="[object Function]",qa="[object GeneratorFunction]",Ja="[object Map]",Ya="[object Number]",Tt="[object Object]",Xa="[object RegExp]",Za="[object Set]",Qa="[object String]",es="[object Symbol]",ts="[object WeakMap]",rs="[object ArrayBuffer]",ns="[object DataView]",as="[object Float32Array]",ss="[object Float64Array]",is="[object Int8Array]",cs="[object Int16Array]",os="[object Int32Array]",us="[object Uint8Array]",fs="[object Uint8ClampedArray]",ls="[object Uint16Array]",hs="[object Uint32Array]",h={};h[yt]=h[Ha]=h[rs]=h[ns]=h[Ka]=h[Va]=h[as]=h[ss]=h[is]=h[cs]=h[os]=h[Ja]=h[Ya]=h[Tt]=h[Xa]=h[Za]=h[Qa]=h[es]=h[us]=h[fs]=h[ls]=h[hs]=!0;h[Wa]=h[vt]=h[ts]=!1;function Q(e,t,r,n,a,c){var s,u=t&Ga,i=t&Ua,o=t&Ra;if(s!==void 0)return s;if(!q(e))return e;var f=de(e);if(f){if(s=oa(e),!u)return lr(e,s)}else{var l=$(e),v=l==vt||l==qa;if(ct(e))return Kn(e,u);if(l==Tt||l==yt||v&&!a){if(s=i||v?{}:La(e),!u)return i?Xn(e,Rn(s,e)):Jn(e,Un(s,e))}else{if(!h[l])return a?e:{};s=Ia(e,l,u)}}c||(c=new N);var T=c.get(e);if(T)return T;c.set(e,s),Da(e)?e.forEach(function(g){s.add(Q(g,t,r,g,e,c))}):Na(e)&&e.forEach(function(g,p){s.set(p,Q(g,t,r,p,e,c))});var m=o?i?Qn:Zn:i?ye:be,b=f?void 0:m(e);return hr(b||e,function(g,p){b&&(p=g,g=e[p]),rt(s,p,Q(g,t,r,p,e,c))}),s}var ds=1,gs=4;function ps(e){return Q(e,ds|gs)}class mt{constructor(t){y(this,"threshold",2);y(this,"hit",0);y(this,"prevSegment");y(this,"hitSegment");y(this,"hitSegmentList",[]);y(this,"options");this.options=t||{}}push(t){var r,n;this.hitSegment&&this.hitSegment.text!==t.text&&(this.hitSegmentList.push(this.hitSegment),this.reset()),this.prevSegment&&t.text===this.prevSegment.text?(this.hit++,this.hit===1&&(this.hitSegment=ps(this.prevSegment)),this.threshold<=this.hit&&this.hitSegment&&(this.hitSegment.et=t.et,this.hitSegment.hit=this.hit,(n=(r=this.options).onHit)==null||n.call(r,this.hitSegmentList))):this.hit=0,this.prevSegment=t}end(){var t,r;this.hitSegment&&(this.hitSegmentList.push(this.hitSegment),(r=(t=this.options).onHit)==null||r.call(t,this.hitSegmentList)),this.reset()}reset(){this.hit=0,this.prevSegment=void 0,this.hitSegment=void 0}}const P={punc:/[.,?!\],。!?…]{1}/,em:/[.?!\]。!?…]{1}/,space:/^\s+|\s+$|\s{2,}/g,ep:/[.,?!,。!?…]{1}\s*$/};function bs(e,t){let r=[];const n=new mt({onHit:i=>{r=i}}),a=i=>i.trim().length===0,c=i=>{const o=A(i.st),f=A(i.et);return o>=f},s={emt:[],ep:[],zf:[],punc:[],em:[],space:[]},u=[];return e.forEach((i,o)=>{const f=P.punc.test(i.text),l=P.em.test(i.text),v=P.space.test(i.text),T=a(i.text),m=c(i),b=P.ep.test(i.text);n.push(i),i.punc=f?1:0,f&&s.punc.push(o),i.em=l?1:0,l&&s.em.push(o),i.space=v?1:0,v&&(t!=null&&t.space?i.text=i.text.replace(P.space," ").trim():s.space.push(o)),i.emt=a(i.text)?1:0,T&&(t!=null&&t.emt||s.emt.push(o)),i.zf=c(i)?1:0,m&&(t!=null&&t.zf||s.zf.push(o)),i.ep=b?1:0,b&&(t!=null&&t.ep?i.text=i.text.replace(P.ep,""):s.ep.push(o)),!(t!=null&&t.zf&&i.zf)&&(t!=null&&t.emt&&i.emt||u.push(i))}),n.end(),{result:s,repeat:r,segments:u}}const ys=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:mt,subtitleOptimization:bs,subtitleOptimizationRegExp:P},Symbol.toStringTag,{value:"Module"}));exports.filter=kt;exports.parser=zt;exports.tools=ys;exports.utils=$t;
|
|
25
|
+
${f}`,l===i.length-1&&s.push(se(c))):(c.part=f,s.push(se(c)),c.part="")))}),c=[];const o=/(<([0-9:.>]+)>)/ig;s.forEach(f=>{const _=f.part.split().map(function(g){return g.replace(o,function(p){return p.split("").reduce(function(S,N){return`==${p.replace("<","").replace(">","")}`},0)})})[0].replace(r,"").split(" "),b=[];_.forEach(function(g){if(g.indexOf("==")>-1){const p=g.split("=="),S=p[0];if(p[1],S==""||S=="##")return;b.push({word:$e(g.split("==")[0]),time:ae(g.split("==")[1])})}else b.push({word:$e(g),time:void 0})}),f.words=b,f.part=f.part.replace(r,"")}),n(s)})}function ae(e){const t=e.split(":"),r=t[t.length-3]?+t[t.length-3]:0,n=t[t.length-2]?+t[t.length-2]:0,a=+t[t.length-1];return r*3600+n*60+a}function $e(e){return e.replace(/[^0-9a-z'-]/gi,"").toLowerCase()}function se(e){if(e==null||typeof e!="object")return e;const t=e.constructor();for(const r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}function Et(e){return e.Transcription.Paragraphs.map(t=>{const r=t.Words.map(n=>({st:y(n.Start/1e3),et:y(n.End/1e3),text:n.Text,spk:t.SpeakerId}));return{st:y(t.Words[0].Start/1e3),et:y(t.Words[t.Words.length-1].End/1e3),text:r.map(n=>n.text).join(""),spk:t.SpeakerId,children:r}})}function Ct(e){const t=e.words.map(r=>({st:y(r.start),et:y(r.end),text:r.word}));return[{st:y(e.words[0].start),et:y(e.words[e.words.length-1].end),text:e.text,children:t}]}const ie={padding:[.4,0],maxGap:10,minGap:2,minStart:6};function Ft(e){let t,r,n,a,c,s,u,i,o;const f=!!(e&&e.vad&&e.vad.length>0),l="[--end--]",m="[--Single--]",T="[--Full--]",_=/\[(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})\]/;let b=!1,g=!1,p="";return S(),{feed:B,reset:S,end:N};function S(){t=!0,r="",n=!1,a="",c=!1,s=void 0,u=0,i=!1,o=0}function N(){if(i){console.log("whisper parser is already end");return}B(l)}function J($){b||(p+=$),!b&&!g&&Ve(p)&&(g=!0),!b&&p.length>50&&(b=!0)}function B($){var Te,_e,Se;J($);const w=[];r+=$,t&&((Te=e==null?void 0:e.onStart)==null||Te.call(e,{type:"event",event:"start",data:[]})),t&&It(r)&&(r=r.slice(qe.length)),t=!1;const Y=r.length;for(;u<Y;){const X=r[u];if(++u,c&&s&&X!=="["&&(s.text+=X),X==="["&&(n&&a.length&&s&&(s.text+=a),a="",n=!0,c=!1),n){if(a+=X,a===T&&(a=""),a===m&&(a="",f&&o++),a===l){s&&w.push(s),i=!0;break}if(_.test(a)){const I=_.exec(a),D=I==null?void 0:I[1],ne=I==null?void 0:I[2];if(s&&w.push(s),D&&ne){if(f&&(e!=null&&e.vad)&&e.vad.length>0){let Z=0;Z=e.vad[o].start-ie.padding[0]<0?0:e.vad[o].start-ie.padding[0];const _t=D==="00:00:00.000";let je=y(A(D)+Z);o>0&&_t&&(je=y(A(D)+Z+ie.padding[0])),s={st:je,et:y(A(ne)+Z),text:"",children:[]}}else s={st:D,et:ne,text:"",children:[]};c=!0,n=!1,a=""}}}}w.length&&((_e=e==null?void 0:e.onParse)==null||_e.call(e,{type:"event",event:"message",data:w})),i&&((Se=e==null?void 0:e.onEnd)==null||Se.call(e,{type:"event",event:"end",data:r}),S())}}const qe=[239,187,191];function It(e){return qe.every((t,r)=>e.charCodeAt(r)===t)}function Lt(e){let t,r,n,a,c,s,u,i;const o=/\[(\d+)\]/,f="[--end--]";return l(),{feed:T,reset:l,end:m};function l(){t=!0,r="",n=0,i=!1,s="",a=void 0,c=!1,u=!1}function m(){T(f)}function T(_){var p,S,N,J,B;const b=[];r+=_,t&&((p=e==null?void 0:e.onStart)==null||p.call(e,{type:"event",event:"start",data:[]})),t&&Mt(r)&&(r=r.slice(Je.length)),t=!1;const g=r.length;for(;n<g;){const $=r[n];if(++n,u&&a&&$!=="["&&(a.text+=$,(S=e==null?void 0:e.onProgress)==null||S.call(e,{type:"event",event:"message",data:[a]})),$==="["&&(c&&s.length&&a&&(a.text+=s,(N=e==null?void 0:e.onProgress)==null||N.call(e,{type:"event",event:"message",data:[a]})),s="",c=!0,u=!1),c){if(s+=$,s===f){a&&b.push(a),i=!0;break}if(o.test(s)){const w=o.exec(s),Y=w==null?void 0:w[1];a&&b.push(a),Y&&(a={index:Number(Y),text:""},u=!0,c=!1,s="")}}}b.length&&((J=e==null?void 0:e.onParse)==null||J.call(e,{type:"event",event:"message",data:b})),i&&((B=e==null?void 0:e.onEnd)==null||B.call(e,{type:"event",event:"end",data:r}),l())}}const Je=[239,187,191];function Mt(e){return Je.every((t,r)=>e.charCodeAt(r)===t)}async function zt(e){return At(e,{keepMultiLine:!0,propName:{}}).filter(n=>n.text).map(n=>({st:y(n.start),et:y(n.end),text:n.text}))}async function Ye(e){return(await Pt(e)).filter(n=>n.part).map(n=>({st:y(n.start),et:y(n.end),text:n.part}))}async function kt(e){return Ye(xt(e))}async function Nt(e){return Et(e)}async function Bt(e){return Ct(e)}const Dt=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:kt,createTranslateStreamParser:Lt,createWhisperStreamParser:Ft,openaiToAimSegments:Bt,srtToAimSegments:zt,tingwuToAimSegments:Nt,vttToAimSegments:Ye},Symbol.toStringTag,{value:"Module"}));class Gt{constructor(t){v(this,"chains",{});v(this,"delimit","__replace__");v(this,"onFilter");v(this,"checked",!1);v(this,"checkedText","");v(this,"checkedLevel");v(this,"filteredText","");this.onFilter=t}add(t,r){typeof t!="string"&&(t=new TextDecoder().decode(t));const n=t;if(!n)return;let a=this.chains;for(let c=0;c<n.length;c++){if(n[c]in a)a=a[n[c]];else{if(!(a instanceof Object))break;let s,u;for(let i=c;i<n.length;i++)a[n[i]]={},[s,u]=[a,n[i]],a=a[n[i]];s&&u&&(s[u]={[this.delimit]:r||""});break}c===n.length-1&&(a[this.delimit]=r||"")}}parse(t){t.forEach(r=>{this.add(...r)})}reParse(t){this.chains={},t.forEach(r=>{this.add(r[0],r[1])})}feed(t){if(!this.checked&&!this.chains[t]){this.filteredText+=t,this.onFilter&&this.onFilter(t);return}if(!this.checked&&this.chains[t]){this.checked=!0,this.checkedLevel=this.chains[t],this.checkedText+=t;return}if(this.checked&&this.checkedLevel[t]){this.checkedLevel=this.checkedLevel[t],this.checkedText+=t;return}if(this.checked&&!this.checkedLevel[t]){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.filteredText+=n,this.onFilter&&this.onFilter(n)}),this.checked=!1,this.checkedText="",this.checkedLevel=void 0,this.chains[t]?(this.checked=!0,this.checkedLevel=this.chains[t],this.checkedText=t):(this.onFilter&&this.onFilter(t),this.filteredText+=t)}}feedAll(t){return t.length?(t.split("").forEach(n=>{this.feed(n)}),this.end()):""}end(){if(this.checked&&this.checkedText){const r=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;r&&r.length&&r.split("").forEach(n=>{this.onFilter&&this.onFilter(n),this.filteredText+=n}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const t=this.filteredText;return this.filteredText="",t}}const Ut=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:Gt},Symbol.toStringTag,{value:"Module"}));var Xe=typeof global=="object"&&global&&global.Object===Object&&global,Rt=typeof self=="object"&&self&&self.Object===Object&&self,j=Xe||Rt||Function("return this")(),L=j.Symbol,Ze=Object.prototype,Ht=Ze.hasOwnProperty,Kt=Ze.toString,G=L?L.toStringTag:void 0;function Wt(e){var t=Ht.call(e,G),r=e[G];try{e[G]=void 0;var n=!0}catch{}var a=Kt.call(e);return n&&(t?e[G]=r:delete e[G]),a}var Vt=Object.prototype,qt=Vt.toString;function Jt(e){return qt.call(e)}var Yt="[object Null]",Xt="[object Undefined]",xe=L?L.toStringTag:void 0;function W(e){return e==null?e===void 0?Xt:Yt:xe&&xe in Object(e)?Wt(e):Jt(e)}function V(e){return e!=null&&typeof e=="object"}var de=Array.isArray;function q(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var Zt="[object AsyncFunction]",Qt="[object Function]",er="[object GeneratorFunction]",tr="[object Proxy]";function Qe(e){if(!q(e))return!1;var t=W(e);return t==Qt||t==er||t==Zt||t==tr}var ce=j["__core-js_shared__"],Oe=function(){var e=/[^.]+$/.exec(ce&&ce.keys&&ce.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function rr(e){return!!Oe&&Oe in e}var nr=Function.prototype,ar=nr.toString;function C(e){if(e!=null){try{return ar.call(e)}catch{}try{return e+""}catch{}}return""}var sr=/[\\^$.*+?()[\]{}|]/g,ir=/^\[object .+?Constructor\]$/,cr=Function.prototype,or=Object.prototype,ur=cr.toString,fr=or.hasOwnProperty,lr=RegExp("^"+ur.call(fr).replace(sr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function hr(e){if(!q(e)||rr(e))return!1;var t=Qe(e)?lr:ir;return t.test(C(e))}function dr(e,t){return e==null?void 0:e[t]}function F(e,t){var r=dr(e,t);return hr(r)?r:void 0}var ue=F(j,"WeakMap"),we=Object.create,gr=function(){function e(){}return function(t){if(!q(t))return{};if(we)return we(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();function pr(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}var Ae=function(){try{var e=F(Object,"defineProperty");return e({},"",{}),e}catch{}}();function br(e,t){for(var r=-1,n=e==null?0:e.length;++r<n&&t(e[r],r,e)!==!1;);return e}var yr=9007199254740991,vr=/^(?:0|[1-9]\d*)$/;function mr(e,t){var r=typeof e;return t=t??yr,!!t&&(r=="number"||r!="symbol"&&vr.test(e))&&e>-1&&e%1==0&&e<t}function et(e,t,r){t=="__proto__"&&Ae?Ae(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function tt(e,t){return e===t||e!==e&&t!==t}var Tr=Object.prototype,_r=Tr.hasOwnProperty;function rt(e,t,r){var n=e[t];(!(_r.call(e,t)&&tt(n,r))||r===void 0&&!(t in e))&&et(e,t,r)}function ee(e,t,r,n){var a=!r;r||(r={});for(var c=-1,s=t.length;++c<s;){var u=t[c],i=void 0;i===void 0&&(i=e[u]),a?et(r,u,i):rt(r,u,i)}return r}var Sr=9007199254740991;function nt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Sr}function at(e){return e!=null&&nt(e.length)&&!Qe(e)}var jr=Object.prototype;function ge(e){var t=e&&e.constructor,r=typeof t=="function"&&t.prototype||jr;return e===r}function $r(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}var xr="[object Arguments]";function Pe(e){return V(e)&&W(e)==xr}var st=Object.prototype,Or=st.hasOwnProperty,wr=st.propertyIsEnumerable,Ar=Pe(function(){return arguments}())?Pe:function(e){return V(e)&&Or.call(e,"callee")&&!wr.call(e,"callee")};function Pr(){return!1}var it=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ee=it&&typeof module=="object"&&module&&!module.nodeType&&module,Er=Ee&&Ee.exports===it,Ce=Er?j.Buffer:void 0,Cr=Ce?Ce.isBuffer:void 0,ct=Cr||Pr,Fr="[object Arguments]",Ir="[object Array]",Lr="[object Boolean]",Mr="[object Date]",zr="[object Error]",kr="[object Function]",Nr="[object Map]",Br="[object Number]",Dr="[object Object]",Gr="[object RegExp]",Ur="[object Set]",Rr="[object String]",Hr="[object WeakMap]",Kr="[object ArrayBuffer]",Wr="[object DataView]",Vr="[object Float32Array]",qr="[object Float64Array]",Jr="[object Int8Array]",Yr="[object Int16Array]",Xr="[object Int32Array]",Zr="[object Uint8Array]",Qr="[object Uint8ClampedArray]",en="[object Uint16Array]",tn="[object Uint32Array]",d={};d[Vr]=d[qr]=d[Jr]=d[Yr]=d[Xr]=d[Zr]=d[Qr]=d[en]=d[tn]=!0;d[Fr]=d[Ir]=d[Kr]=d[Lr]=d[Wr]=d[Mr]=d[zr]=d[kr]=d[Nr]=d[Br]=d[Dr]=d[Gr]=d[Ur]=d[Rr]=d[Hr]=!1;function rn(e){return V(e)&&nt(e.length)&&!!d[W(e)]}function pe(e){return function(t){return e(t)}}var ot=typeof exports=="object"&&exports&&!exports.nodeType&&exports,R=ot&&typeof module=="object"&&module&&!module.nodeType&&module,nn=R&&R.exports===ot,oe=nn&&Xe.process,M=function(){try{var e=R&&R.require&&R.require("util").types;return e||oe&&oe.binding&&oe.binding("util")}catch{}}(),Fe=M&&M.isTypedArray,an=Fe?pe(Fe):rn,sn=Object.prototype,cn=sn.hasOwnProperty;function ut(e,t){var r=de(e),n=!r&&Ar(e),a=!r&&!n&&ct(e),c=!r&&!n&&!a&&an(e),s=r||n||a||c,u=s?$r(e.length,String):[],i=u.length;for(var o in e)(t||cn.call(e,o))&&!(s&&(o=="length"||a&&(o=="offset"||o=="parent")||c&&(o=="buffer"||o=="byteLength"||o=="byteOffset")||mr(o,i)))&&u.push(o);return u}function ft(e,t){return function(r){return e(t(r))}}var on=ft(Object.keys,Object),un=Object.prototype,fn=un.hasOwnProperty;function ln(e){if(!ge(e))return on(e);var t=[];for(var r in Object(e))fn.call(e,r)&&r!="constructor"&&t.push(r);return t}function be(e){return at(e)?ut(e):ln(e)}function hn(e){var t=[];if(e!=null)for(var r in Object(e))t.push(r);return t}var dn=Object.prototype,gn=dn.hasOwnProperty;function pn(e){if(!q(e))return hn(e);var t=ge(e),r=[];for(var n in e)n=="constructor"&&(t||!gn.call(e,n))||r.push(n);return r}function ye(e){return at(e)?ut(e,!0):pn(e)}var H=F(Object,"create");function bn(){this.__data__=H?H(null):{},this.size=0}function yn(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var vn="__lodash_hash_undefined__",mn=Object.prototype,Tn=mn.hasOwnProperty;function _n(e){var t=this.__data__;if(H){var r=t[e];return r===vn?void 0:r}return Tn.call(t,e)?t[e]:void 0}var Sn=Object.prototype,jn=Sn.hasOwnProperty;function $n(e){var t=this.__data__;return H?t[e]!==void 0:jn.call(t,e)}var xn="__lodash_hash_undefined__";function On(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=H&&t===void 0?xn:t,this}function E(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}E.prototype.clear=bn;E.prototype.delete=yn;E.prototype.get=_n;E.prototype.has=$n;E.prototype.set=On;function wn(){this.__data__=[],this.size=0}function te(e,t){for(var r=e.length;r--;)if(tt(e[r][0],t))return r;return-1}var An=Array.prototype,Pn=An.splice;function En(e){var t=this.__data__,r=te(t,e);if(r<0)return!1;var n=t.length-1;return r==n?t.pop():Pn.call(t,r,1),--this.size,!0}function Cn(e){var t=this.__data__,r=te(t,e);return r<0?void 0:t[r][1]}function Fn(e){return te(this.__data__,e)>-1}function In(e,t){var r=this.__data__,n=te(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this}function O(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}O.prototype.clear=wn;O.prototype.delete=En;O.prototype.get=Cn;O.prototype.has=Fn;O.prototype.set=In;var K=F(j,"Map");function Ln(){this.size=0,this.__data__={hash:new E,map:new(K||O),string:new E}}function Mn(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function re(e,t){var r=e.__data__;return Mn(t)?r[typeof t=="string"?"string":"hash"]:r.map}function zn(e){var t=re(this,e).delete(e);return this.size-=t?1:0,t}function kn(e){return re(this,e).get(e)}function Nn(e){return re(this,e).has(e)}function Bn(e,t){var r=re(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this}function z(e){var t=-1,r=e==null?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}z.prototype.clear=Ln;z.prototype.delete=zn;z.prototype.get=kn;z.prototype.has=Nn;z.prototype.set=Bn;function lt(e,t){for(var r=-1,n=t.length,a=e.length;++r<n;)e[a+r]=t[r];return e}var ht=ft(Object.getPrototypeOf,Object);function Dn(){this.__data__=new O,this.size=0}function Gn(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r}function Un(e){return this.__data__.get(e)}function Rn(e){return this.__data__.has(e)}var Hn=200;function Kn(e,t){var r=this.__data__;if(r instanceof O){var n=r.__data__;if(!K||n.length<Hn-1)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new z(n)}return r.set(e,t),this.size=r.size,this}function k(e){var t=this.__data__=new O(e);this.size=t.size}k.prototype.clear=Dn;k.prototype.delete=Gn;k.prototype.get=Un;k.prototype.has=Rn;k.prototype.set=Kn;function Wn(e,t){return e&&ee(t,be(t),e)}function Vn(e,t){return e&&ee(t,ye(t),e)}var dt=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ie=dt&&typeof module=="object"&&module&&!module.nodeType&&module,qn=Ie&&Ie.exports===dt,Le=qn?j.Buffer:void 0,Me=Le?Le.allocUnsafe:void 0;function Jn(e,t){if(t)return e.slice();var r=e.length,n=Me?Me(r):new e.constructor(r);return e.copy(n),n}function Yn(e,t){for(var r=-1,n=e==null?0:e.length,a=0,c=[];++r<n;){var s=e[r];t(s,r,e)&&(c[a++]=s)}return c}function gt(){return[]}var Xn=Object.prototype,Zn=Xn.propertyIsEnumerable,ze=Object.getOwnPropertySymbols,ve=ze?function(e){return e==null?[]:(e=Object(e),Yn(ze(e),function(t){return Zn.call(e,t)}))}:gt;function Qn(e,t){return ee(e,ve(e),t)}var ea=Object.getOwnPropertySymbols,pt=ea?function(e){for(var t=[];e;)lt(t,ve(e)),e=ht(e);return t}:gt;function ta(e,t){return ee(e,pt(e),t)}function bt(e,t,r){var n=t(e);return de(e)?n:lt(n,r(e))}function ra(e){return bt(e,be,ve)}function na(e){return bt(e,ye,pt)}var fe=F(j,"DataView"),le=F(j,"Promise"),he=F(j,"Set"),ke="[object Map]",aa="[object Object]",Ne="[object Promise]",Be="[object Set]",De="[object WeakMap]",Ge="[object DataView]",sa=C(fe),ia=C(K),ca=C(le),oa=C(he),ua=C(ue),x=W;(fe&&x(new fe(new ArrayBuffer(1)))!=Ge||K&&x(new K)!=ke||le&&x(le.resolve())!=Ne||he&&x(new he)!=Be||ue&&x(new ue)!=De)&&(x=function(e){var t=W(e),r=t==aa?e.constructor:void 0,n=r?C(r):"";if(n)switch(n){case sa:return Ge;case ia:return ke;case ca:return Ne;case oa:return Be;case ua:return De}return t});var fa=Object.prototype,la=fa.hasOwnProperty;function ha(e){var t=e.length,r=new e.constructor(t);return t&&typeof e[0]=="string"&&la.call(e,"index")&&(r.index=e.index,r.input=e.input),r}var Ue=j.Uint8Array;function me(e){var t=new e.constructor(e.byteLength);return new Ue(t).set(new Ue(e)),t}function da(e,t){var r=t?me(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)}var ga=/\w*$/;function pa(e){var t=new e.constructor(e.source,ga.exec(e));return t.lastIndex=e.lastIndex,t}var Re=L?L.prototype:void 0,He=Re?Re.valueOf:void 0;function ba(e){return He?Object(He.call(e)):{}}function ya(e,t){var r=t?me(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)}var va="[object Boolean]",ma="[object Date]",Ta="[object Map]",_a="[object Number]",Sa="[object RegExp]",ja="[object Set]",$a="[object String]",xa="[object Symbol]",Oa="[object ArrayBuffer]",wa="[object DataView]",Aa="[object Float32Array]",Pa="[object Float64Array]",Ea="[object Int8Array]",Ca="[object Int16Array]",Fa="[object Int32Array]",Ia="[object Uint8Array]",La="[object Uint8ClampedArray]",Ma="[object Uint16Array]",za="[object Uint32Array]";function ka(e,t,r){var n=e.constructor;switch(t){case Oa:return me(e);case va:case ma:return new n(+e);case wa:return da(e,r);case Aa:case Pa:case Ea:case Ca:case Fa:case Ia:case La:case Ma:case za:return ya(e,r);case Ta:return new n;case _a:case $a:return new n(e);case Sa:return pa(e);case ja:return new n;case xa:return ba(e)}}function Na(e){return typeof e.constructor=="function"&&!ge(e)?gr(ht(e)):{}}var Ba="[object Map]";function Da(e){return V(e)&&x(e)==Ba}var Ke=M&&M.isMap,Ga=Ke?pe(Ke):Da,Ua="[object Set]";function Ra(e){return V(e)&&x(e)==Ua}var We=M&&M.isSet,Ha=We?pe(We):Ra,Ka=1,Wa=2,Va=4,yt="[object Arguments]",qa="[object Array]",Ja="[object Boolean]",Ya="[object Date]",Xa="[object Error]",vt="[object Function]",Za="[object GeneratorFunction]",Qa="[object Map]",es="[object Number]",mt="[object Object]",ts="[object RegExp]",rs="[object Set]",ns="[object String]",as="[object Symbol]",ss="[object WeakMap]",is="[object ArrayBuffer]",cs="[object DataView]",os="[object Float32Array]",us="[object Float64Array]",fs="[object Int8Array]",ls="[object Int16Array]",hs="[object Int32Array]",ds="[object Uint8Array]",gs="[object Uint8ClampedArray]",ps="[object Uint16Array]",bs="[object Uint32Array]",h={};h[yt]=h[qa]=h[is]=h[cs]=h[Ja]=h[Ya]=h[os]=h[us]=h[fs]=h[ls]=h[hs]=h[Qa]=h[es]=h[mt]=h[ts]=h[rs]=h[ns]=h[as]=h[ds]=h[gs]=h[ps]=h[bs]=!0;h[Xa]=h[vt]=h[ss]=!1;function Q(e,t,r,n,a,c){var s,u=t&Ka,i=t&Wa,o=t&Va;if(s!==void 0)return s;if(!q(e))return e;var f=de(e);if(f){if(s=ha(e),!u)return pr(e,s)}else{var l=x(e),m=l==vt||l==Za;if(ct(e))return Jn(e,u);if(l==mt||l==yt||m&&!a){if(s=i||m?{}:Na(e),!u)return i?ta(e,Vn(s,e)):Qn(e,Wn(s,e))}else{if(!h[l])return a?e:{};s=ka(e,l,u)}}c||(c=new k);var T=c.get(e);if(T)return T;c.set(e,s),Ha(e)?e.forEach(function(g){s.add(Q(g,t,r,g,e,c))}):Ga(e)&&e.forEach(function(g,p){s.set(p,Q(g,t,r,p,e,c))});var _=o?i?na:ra:i?ye:be,b=f?void 0:_(e);return br(b||e,function(g,p){b&&(p=g,g=e[p]),rt(s,p,Q(g,t,r,p,e,c))}),s}var ys=1,vs=4;function ms(e){return Q(e,ys|vs)}class Tt{constructor(t){v(this,"threshold",2);v(this,"hit",0);v(this,"prevSegment");v(this,"hitSegment");v(this,"hitSegmentList",[]);v(this,"options");this.options=t||{}}push(t){var r,n;this.hitSegment&&this.hitSegment.text!==t.text&&(this.hitSegmentList.push(this.hitSegment),this.reset()),this.prevSegment&&t.text===this.prevSegment.text?(this.hit++,this.hit===1&&(this.hitSegment=ms(this.prevSegment)),this.threshold<=this.hit&&this.hitSegment&&(this.hitSegment.et=t.et,this.hitSegment.hit=this.hit,(n=(r=this.options).onHit)==null||n.call(r,this.hitSegmentList))):this.hit=0,this.prevSegment=t}end(){var t,r;this.hitSegment&&(this.hitSegmentList.push(this.hitSegment),(r=(t=this.options).onHit)==null||r.call(t,this.hitSegmentList)),this.reset()}reset(){this.hit=0,this.prevSegment=void 0,this.hitSegment=void 0}}const P={punc:/[.,?!\],。!?…]{1}/,em:/[.?!\]。!?…]{1}/,space:/^\s+|\s+$|\s{2,}/g,ep:/[.,?!,。!?…]{1}\s*$/};function Ts(e,t){let r=[];const n=new Tt({onHit:i=>{r=i}}),a=i=>i.trim().length===0,c=i=>{const o=A(i.st),f=A(i.et);return o>=f},s={emt:[],ep:[],zf:[],punc:[],em:[],space:[]},u=[];return e.forEach((i,o)=>{const f=P.punc.test(i.text),l=P.em.test(i.text),m=P.space.test(i.text),T=a(i.text),_=c(i),b=P.ep.test(i.text);n.push(i),i.punc=f?1:0,f&&s.punc.push(o),i.em=l?1:0,l&&s.em.push(o),i.space=m?1:0,m&&(t!=null&&t.space?i.text=i.text.replace(P.space," ").trim():s.space.push(o)),i.emt=a(i.text)?1:0,T&&(t!=null&&t.emt||s.emt.push(o)),i.zf=c(i)?1:0,_&&(t!=null&&t.zf||s.zf.push(o)),i.ep=b?1:0,b&&(t!=null&&t.ep?i.text=i.text.replace(P.ep,""):s.ep.push(o)),!(t!=null&&t.zf&&i.zf)&&(t!=null&&t.emt&&i.emt||u.push(i))}),n.end(),{result:s,repeat:r,segments:u}}const _s=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:Tt,subtitleOptimization:Ts,subtitleOptimizationRegExp:P},Symbol.toStringTag,{value:"Module"}));exports.filter=Ut;exports.parser=Dt;exports.tools=_s;exports.utils=$t;
|
package/dist/index.d.ts
CHANGED
|
@@ -114,6 +114,19 @@ export declare namespace filter {
|
|
|
114
114
|
*/
|
|
115
115
|
declare function formatTime(seconds: number): string;
|
|
116
116
|
|
|
117
|
+
declare interface OpenAIResult {
|
|
118
|
+
task: string;
|
|
119
|
+
language: string;
|
|
120
|
+
text: string;
|
|
121
|
+
words: {
|
|
122
|
+
word: string;
|
|
123
|
+
start: number;
|
|
124
|
+
end: number;
|
|
125
|
+
}[];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare function openaiToAimSegments(json: OpenAIResult): Promise<AimSegments[]>;
|
|
129
|
+
|
|
117
130
|
declare interface OptimizationOptions {
|
|
118
131
|
emt: boolean;
|
|
119
132
|
ep: boolean;
|
|
@@ -173,6 +186,8 @@ export declare namespace parser {
|
|
|
173
186
|
srtToAimSegments,
|
|
174
187
|
vttToAimSegments,
|
|
175
188
|
assToAimSegments,
|
|
189
|
+
tingwuToAimSegments,
|
|
190
|
+
openaiToAimSegments,
|
|
176
191
|
create as createWhisperStreamParser,
|
|
177
192
|
create_2 as createTranslateStreamParser
|
|
178
193
|
}
|
|
@@ -255,6 +270,31 @@ declare const subtitleOptimizationRegExp: {
|
|
|
255
270
|
ep: RegExp;
|
|
256
271
|
};
|
|
257
272
|
|
|
273
|
+
declare interface TingwuResult {
|
|
274
|
+
TaskId: string;
|
|
275
|
+
Transcription: {
|
|
276
|
+
AudioInfo: {
|
|
277
|
+
"Size": number;
|
|
278
|
+
"Duration": number;
|
|
279
|
+
"SampleRate": number;
|
|
280
|
+
"Language": string;
|
|
281
|
+
};
|
|
282
|
+
Paragraphs: {
|
|
283
|
+
ParagraphId: string;
|
|
284
|
+
SpeakerId: string;
|
|
285
|
+
Words: {
|
|
286
|
+
"Id": number;
|
|
287
|
+
"SentenceId": number;
|
|
288
|
+
"Start": number;
|
|
289
|
+
"End": number;
|
|
290
|
+
"Text": string;
|
|
291
|
+
}[];
|
|
292
|
+
}[];
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
declare function tingwuToAimSegments(json: TingwuResult): Promise<AimSegments[]>;
|
|
297
|
+
|
|
258
298
|
export declare namespace tools {
|
|
259
299
|
export {
|
|
260
300
|
subtitleOptimization,
|