@aim-packages/subtitle 0.1.6 → 0.1.7
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 +1 -1
- package/dist/index.es.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -2863,4 +2863,4 @@ ${((V=A[N.spk])==null?void 0:V.name)||((o==null?void 0:o.speaker)||"")+N.spk} ${
|
|
|
2863
2863
|
`:`${A[O].join(S.includes(B[1])?"":" ")}
|
|
2864
2864
|
`)})}return t?`${a}\r
|
|
2865
2865
|
${s.join("")}`:`${a}
|
|
2866
|
-
${s.join("")}`}function p7(n){let e="",a=0;for(;a<n.length;){let t=n[a],i=0,r=!0;if(t>>7?t>>5===6?i=2:t>>4===14?i=3:t>>3===30?i=4:r=!1:i=1,r&&a+i<=n.length){for(let o=1;o<i;o++)if(n[a+o]>>6!==2){r=!1;break}if(r){const o=n.slice(a,a+i);try{e+=o.toString("utf8"),a+=i;continue}catch{r=!1}}}else r=!1;e+="x"+n[a].toString(16).padStart(2,"0"),a++}return e}function R7(n){const e=/x[0-9a-f]{1,2}/,a=[];let t=null;for(let i=0;i<n.length;i++){const r=n[i];e.test(r.text)?t?(t.text+=r.text,t.timestamps.to=r.timestamps.to,t.offsets.to=r.offsets.to):t={...r}:(t&&(t.text=U7(t.text),a.push(t),t=null),a.push(r))}return t&&a.push(t),a}function X7(n){return n.split("x").filter(e=>e.length===2).map(e=>parseInt(e,16))}function U7(n){const e=X7(n),a=new Uint8Array(e);return new TextDecoder("utf-8").decode(a)}async function y7(n){const e=p7(n),a=JSON.parse(e);return a.transcription.forEach(t=>{t.tokens=R7(t.tokens)}),a}const v7=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:S0,detectAllLanguage:h7,detectLanguage:L1,fixWhisperJsonDecode:y7,outputAss:Q7,outputLrc:k7,outputMarkdown:T7,outputSrt:V7,outputTxt:C7,outputVtt:F7,splitToSentences:K0,subtitleOptimization:G6,subtitleOptimizationRegExp:w},Symbol.toStringTag,{value:"Module"}));function f7(n=[],e){for(let a=0;a<n.length;a++)if(e.startsWith(n[a].text))e=e.slice(n[a].text.length);else return a-1;return n.length-1}function b7(n,e,a){var o;let t,i,r=-1;if((o=n.children)!=null&&o.length){for(let l=0;l<n.children.length;l++)r+n.children[l].text.length<e||r>=e&&r<=a&&(t===void 0&&(t=l),i=l),r+=n.children[l].text.length;return{start:t,end:i}}}function Z7(n){if(n.length===0)return;const e={};for(const i of n){const r=i.text;e[r]?e[r].count++:e[r]={count:1,segment:i}}let a=n[0],t=e[a.text].count;for(const i in e)e[i].count>t&&(a=e[i].segment,t=e[i].count);return a}function Y7(n){if(n.length>0){const e=n[0].st;let a=n[0].et;const t=[];for(let r=0;r<n.length;r++)a=n[r].et,t.push(n[r]);const i=Z7(n);return{st:e,et:a,text:(i==null?void 0:i.text)||"",punc:i==null?void 0:i.punc,em:i==null?void 0:i.em,rs:t}}}function q0(n){n.children&&n.children.length>0&&(n.children.forEach(e=>{q0(e)}),n.st=n.children[0].st,n.et=n.children[n.children.length-1].et,n.text=n.children.map(e=>e.text).join(""),n.punc=n.children.reduce((e,a)=>e||a.punc,0),n.em=n.children.reduce((e,a)=>e||a.em,0))}function c0(n,e=0,a=2){if(n.children&&n.children.length>=e+a){const t=n.children.slice(e,e+a),i=Y7(t);return i?n.children.splice(e,a,i):n.children.splice(e,a),q0(n),i?i.text.length:0}return 0}function S7(n){const a=(n==null?void 0:n.sentenceLength)||75;let t,i,r,o,l,D,s=[];const B=/[
|
|
2866
|
+
${s.join("")}`}function p7(n){let e="",a=0;for(;a<n.length;){let t=n[a],i=0,r=!0;if(t>>7?t>>5===6?i=2:t>>4===14?i=3:t>>3===30?i=4:r=!1:i=1,r&&a+i<=n.length){for(let o=1;o<i;o++)if(n[a+o]>>6!==2){r=!1;break}if(r){const o=n.slice(a,a+i);try{e+=o.toString("utf8"),a+=i;continue}catch{r=!1}}}else r=!1;e+="x"+n[a].toString(16).padStart(2,"0"),a++}return e}function R7(n){const e=/x[0-9a-f]{1,2}/,a=[];let t=null;for(let i=0;i<n.length;i++){const r=n[i];e.test(r.text)?t?(t.text+=r.text,t.timestamps.to=r.timestamps.to,t.offsets.to=r.offsets.to):t={...r}:(t&&(t.text=U7(t.text),a.push(t),t=null),a.push(r))}return t&&a.push(t),a}function X7(n){return n.split("x").filter(e=>e.length===2).map(e=>parseInt(e,16))}function U7(n){const e=X7(n),a=new Uint8Array(e);return new TextDecoder("utf-8").decode(a)}async function y7(n){const e=p7(n),a=JSON.parse(e);return a.transcription.forEach(t=>{t.tokens=R7(t.tokens)}),a}const v7=Object.freeze(Object.defineProperty({__proto__:null,RepeatCheck:S0,detectAllLanguage:h7,detectLanguage:L1,fixWhisperJsonDecode:y7,outputAss:Q7,outputLrc:k7,outputMarkdown:T7,outputSrt:V7,outputTxt:C7,outputVtt:F7,splitToSentences:K0,subtitleOptimization:G6,subtitleOptimizationRegExp:w},Symbol.toStringTag,{value:"Module"}));function f7(n=[],e){for(let a=0;a<n.length;a++)if(e.startsWith(n[a].text))e=e.slice(n[a].text.length);else return a-1;return n.length-1}function b7(n,e,a){var o;let t,i,r=-1;if((o=n.children)!=null&&o.length){for(let l=0;l<n.children.length;l++)r+n.children[l].text.length<e||r>=e&&r<=a&&(t===void 0&&(t=l),i=l),r+=n.children[l].text.length;return{start:t,end:i}}}function Z7(n){if(n.length===0)return;const e={};for(const i of n){const r=i.text;e[r]?e[r].count++:e[r]={count:1,segment:i}}let a=n[0],t=e[a.text].count;for(const i in e)e[i].count>t&&(a=e[i].segment,t=e[i].count);return a}function Y7(n){if(n.length>0){const e=n[0].st;let a=n[0].et;const t=[];for(let r=0;r<n.length;r++)a=n[r].et,t.push(n[r]);const i=Z7(n);return{st:e,et:a,text:(i==null?void 0:i.text)||"",punc:i==null?void 0:i.punc,em:i==null?void 0:i.em,rs:t}}}function q0(n){n.children&&n.children.length>0&&(n.children.forEach(e=>{q0(e)}),n.st=n.children[0].st,n.et=n.children[n.children.length-1].et,n.text=n.children.map(e=>e.text).join(""),n.punc=n.children.reduce((e,a)=>e||a.punc,0),n.em=n.children.reduce((e,a)=>e||a.em,0))}function c0(n,e=0,a=2){if(n.children&&n.children.length>=e+a){const t=n.children.slice(e,e+a),i=Y7(t);return i?n.children.splice(e,a,i):n.children.splice(e,a),q0(n),i?i.text.length:0}return 0}function S7(n){const a=(n==null?void 0:n.sentenceLength)||75;let t,i,r,o,l,D,s=[];const B=/[.,、?!\],。!?…;]{1}/,A=/[.?!\]。!?…;]{1}/;let h=!1,O=!1,u="",N=null;return c(),{feed:Q,reset:c,end:V};function c(){i=[],r=0,o=!1,l=null,D=[],s=[]}function V(){Q([{st:"",et:"",text:"[--end--]"}])}function F(g){h||(u+=g.map(R=>R.text).join("")),!h&&!O&&v1(u)&&(O=!0),u.length>50&&(h=!0),!N&&h&&(N=L1(u),console.log("detect language",u,N),console.log(N))}function p(){var g,R;D.length&&((g=n==null?void 0:n.repeatString)!=null&&g.length&&D.forEach(C=>{var k;(k=n.repeatString)==null||k.forEach(L=>{const m=A0(C.text,L);if(m.length){console.log("===================================="),console.log(C.text),console.log(m);let d=0;m.forEach((M,P)=>{var T;if(M.start===0){const X=f7(C.children,M.match);d+=c0(C,0,X+1),console.log(d)}if(M.start>0){const X=P>0?M.start-m[P-1].end+d:M.start,f=P>0?M.end-m[P-1].end+d:M.end;console.log(X,f,"=============================");const b=b7(C,X,f);console.log((T=C.children)==null?void 0:T.map((E,J)=>E.text+"--"+E.text.length+" "+J).join("||")),console.log(b),b&&b.start!==void 0&&b.end!==void 0&&(d+=c0(C,b.start,b.end-b.start+1),console.log(d),console.log(C.text))}}),console.log("----------"),console.log(C.text),console.log("----------")}})}),s.push(...D),(R=n==null?void 0:n.onParse)==null||R.call(n,{type:"event",event:"message",data:D}))}function Q(g){var C,k,L,m;F(g),i.push(...g),t&&((C=n==null?void 0:n.onStart)==null||C.call(n,{type:"event",event:"start",data:[]})),t=!1;const R=i.length;for(;r<R;){const d=i[r];if(++r,d.punc=B.test(d.text)?1:0,d.em=A.test(d.text)?1:0,d.text==="[--end--]"){l&&D.push(l),o=!0;break}if(l?(l.et=d.et,l.text=l.text+d.text,l.em=l.em||d.em,l.punc=l.punc||d.punc,(k=l.children)==null||k.push({...d})):l={...d,children:[{...d}]},d.punc||o&&l){const M=D[D.length-1];let P=!0;M&&!M.em&&(M.text+l.text).length<=a?P=!1:M&&M.em&&d.em&&(P=K0(M.text+l.text).length!==1),P?D.push(Y0(l)):(M.et=l.et,M.text=M.text+l.text,M.em=l.em||M.em,M.punc=l.punc||M.punc,(L=M.children)==null||L.push(...l.children||[])),l=null}else!d.punc&&!l.punc&&l.text.length>a;if(D.length>0){const M=D.pop();p(),D=[M]}}o&&(p(),(m=n==null?void 0:n.onEnd)==null||m.call(n,{type:"event",event:"end",data:i,result:s}),c())}}async function j7(n){return s2(n,{keepMultiLine:!0,propName:{}}).filter(t=>t.text).map(t=>({st:v(t.start),et:v(t.end),text:t.text}))}async function W0(n){return(await u2(n)).filter(t=>t.part).map(t=>({st:v(t.start),et:v(t.end),text:t.part}))}async function E7(n){return W0(r2(n))}async function H7(n){return d2(n)}async function G7(n){return h2(n)}async function I7(n){return L2(n)}const z7=Object.freeze(Object.defineProperty({__proto__:null,assToAimSegments:E7,createSegmentStreamParser:S7,createTranslateStreamParser:D2,createWhisperStreamParser:O2,openaiToAimSegments:G7,srtToAimSegments:j7,tingwuToAimSegments:H7,vttToAimSegments:W0,whisperJsonToAimSegments:I7},Symbol.toStringTag,{value:"Module"}));class J7{constructor(e){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=e}add(e,a){typeof e!="string"&&(e=new TextDecoder().decode(e));const t=e;if(!t)return;let i=this.chains;for(let r=0;r<t.length;r++){if(t[r]in i)i=i[t[r]];else{if(!(i instanceof Object))break;let o,l;for(let D=r;D<t.length;D++)i[t[D]]={},[o,l]=[i,t[D]],i=i[t[D]];o&&l&&(o[l]={[this.delimit]:a||""});break}r===t.length-1&&(i[this.delimit]=a||"")}}parse(e){e.forEach(a=>{this.add(...a)})}reParse(e){this.chains={},e.forEach(a=>{this.add(a[0],a[1])})}feed(e){if(!this.checked&&!this.chains[e]){this.filteredText+=e,this.onFilter&&this.onFilter(e);return}if(!this.checked&&this.chains[e]){this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText+=e;return}if(this.checked&&this.checkedLevel[e]){this.checkedLevel=this.checkedLevel[e],this.checkedText+=e;return}if(this.checked&&!this.checkedLevel[e]){const a=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;a&&a.length&&a.split("").forEach(t=>{this.filteredText+=t,this.onFilter&&this.onFilter(t)}),this.checked=!1,this.checkedText="",this.checkedLevel=void 0,this.chains[e]?(this.checked=!0,this.checkedLevel=this.chains[e],this.checkedText=e):(this.onFilter&&this.onFilter(e),this.filteredText+=e)}}feedAll(e){return e.length?(e.split("").forEach(t=>{this.feed(t)}),this.end()):""}end(){if(this.checked&&this.checkedText){const a=typeof this.checkedLevel[this.delimit]=="string"?this.checkedLevel[this.delimit]:this.checkedText;a&&a.length&&a.split("").forEach(t=>{this.onFilter&&this.onFilter(t),this.filteredText+=t}),this.checkedText="",this.checkedLevel=void 0,this.checked=!1}const e=this.filteredText;return this.filteredText="",e}}const K7=Object.freeze(Object.defineProperty({__proto__:null,StreamFilter:J7},Symbol.toStringTag,{value:"Module"}));exports.filter=K7;exports.parser=z7;exports.tools=v7;exports.utils=t2;
|
package/dist/index.es.js
CHANGED
|
@@ -5273,7 +5273,7 @@ function c0(n, e = 0, a = 2) {
|
|
|
5273
5273
|
function Z7(n) {
|
|
5274
5274
|
const a = (n == null ? void 0 : n.sentenceLength) || 75;
|
|
5275
5275
|
let t, i, r, o, l, D, s = [];
|
|
5276
|
-
const B = /[
|
|
5276
|
+
const B = /[.,、?!\],。!?…;]{1}/, A = /[.?!\]。!?…;]{1}/;
|
|
5277
5277
|
let h = !1, O = !1, u = "", N = null;
|
|
5278
5278
|
return c(), { feed: Q, reset: c, end: V };
|
|
5279
5279
|
function c() {
|