xvai-loi 0.1.87 → 0.1.89

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.
Files changed (3) hide show
  1. package/co.txt +1 -1
  2. package/package.json +1 -1
  3. package/xvai-loi.js +26 -6
package/co.txt CHANGED
@@ -1 +1 @@
1
- xvaiLoi120323
1
+ xvaiLoi120610
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xvai-loi",
3
- "version": "0.1.87",
3
+ "version": "0.1.89",
4
4
  "description": "Loi dung video (Edit Video Tu Dong) nap vao tool Google Flow qua o cam engine/oCam.ts",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
package/xvai-loi.js CHANGED
@@ -16029,7 +16029,12 @@ var MontagePanel = ({ project, onUpdate, onExport }) => {
16029
16029
  var parse2 = (text2) => {
16030
16030
  const a = text2.indexOf("{"), b = text2.lastIndexOf("}");
16031
16031
  if (a < 0 || b < a) throw new Error("AI ch\u01B0a tr\u1EA3 d\u1EEF li\u1EC7u l\u1EDDi n\xF3i.");
16032
- return JSON.parse(text2.slice(a, b + 1));
16032
+ const t = text2.slice(a, b + 1);
16033
+ try {
16034
+ return JSON.parse(t);
16035
+ } catch (e) {
16036
+ return JSON.parse(t.replace(/([{,]\s*)([A-Za-z_][A-Za-z0-9_]*)\s*:/g, '$1"$2":').replace(/,\s*([}\]])/g, "$1"));
16037
+ }
16033
16038
  };
16034
16039
  async function analyzeSpeech(project, scene, item, request, onProgress, onCache, cancel, templateMode = false, dense = false, boNhan = false) {
16035
16040
  const active = () => {
@@ -16060,10 +16065,18 @@ async function analyzeSpeech(project, scene, item, request, onProgress, onCache,
16060
16065
  let part = cached[n];
16061
16066
  if (!part) {
16062
16067
  const prompt = "Ch\xE9p CH\xCDNH X\xC1C ti\u1EBFng Vi\u1EC7t nghe \u0111\u01B0\u1EE3c, kh\xF4ng vi\u1EBFt l\u1EA1i, kh\xF4ng th\xEAm l\u1EDDi t\u1EEB ki\u1EBFn th\u1EE9c. Ch\u1ED7 im l\u1EB7ng/nh\u1EA1c kh\xF4ng c\xF3 l\u1EDDi tr\u1EA3 r\u1ED7ng. Tr\u1EA3 JSON {words:[{t0,t1,text}],unclear:[]}. M\u1ED7i text l\xE0 m\u1ED9t ti\u1EBFng/t\u1EEB nghe \u0111\u01B0\u1EE3c, timestamp gi\xE2y t\xEDnh t\u1EEB \u0111\u1EA7u t\u1EC7p \xE2m thanh n\xE0y, t\u0103ng d\u1EA7n, kh\xF4ng ch\u1ED3ng, trong 0.." + (b - a).toFixed(3) + ". Kh\xF4ng g\u1ED9p c\xE2u v\xE0o m\u1ED9t t\u1EEB. Gi\u1EEF t\xEAn ri\xEAng v\xE0 d\u1EA5u ti\u1EBFng Vi\u1EC7t. N\u1EBFu kh\xF4ng ch\u1EAFc ghi unclear, kh\xF4ng b\u1ECBa.";
16063
- const result = await Flow.generate.text(prompt, { audios: [{ base64: wav64(pcm.subarray(Math.round(a * 16e3), Math.round(b * 16e3))), mimeType: "audio/wav" }], thinkingLevel: "medium" });
16064
- calls++;
16065
- active();
16066
- const parsed = parse2(result.text), valid2 = validateWords(parsed.words, 0, b - a);
16068
+ let parsed = null;
16069
+ for (let lan2 = 0; lan2 < 2 && !parsed; lan2++) {
16070
+ const result = await Flow.generate.text(prompt, { audios: [{ base64: wav64(pcm.subarray(Math.round(a * 16e3), Math.round(b * 16e3))), mimeType: "audio/wav" }], thinkingLevel: "medium" });
16071
+ calls++;
16072
+ active();
16073
+ try {
16074
+ parsed = parse2(result.text);
16075
+ } catch (e) {
16076
+ if (lan2) throw e;
16077
+ }
16078
+ }
16079
+ const valid2 = validateWords(parsed.words, 0, b - a);
16067
16080
  part = { start, end, words: valid2.map((w) => ({ ...w, t0: w.t0 + a, t1: w.t1 + a })).filter((w) => (w.t0 + w.t1) / 2 >= start && (w.t0 + w.t1) / 2 < end), unclear: Array.isArray(parsed.unclear) ? parsed.unclear : [] };
16068
16081
  }
16069
16082
  parts.push(part);
@@ -18812,6 +18825,13 @@ function lichDoan(clips) {
18812
18825
  });
18813
18826
  t += Math.max(0, e - s);
18814
18827
  });
18828
+ {
18829
+ const nen2 = ra.filter((x) => /^(cmNen|cmAnh|cmKinh)$/.test(String(x.doan && x.doan.loai))).sort((p, q) => p.T0 - q.T0);
18830
+ for (let i = 0; i + 1 < nen2.length; i++) {
18831
+ const x = nen2[i], y = nen2[i + 1];
18832
+ if (y.T0 > x.T0 + 0.05 && y.T0 < x.T1 && x.T1 - y.T0 < 0.1) x.T1 = y.T0;
18833
+ }
18834
+ }
18815
18835
  globalThis.__doanRoi = [...new Set(clips.flatMap((c) => (c.textMoments || []).filter((m) => m.kind === "doan" && !da.has(m))))].map((m) => [+(+m.t0).toFixed(2), +(+m.t1).toFixed(2), m.doan?.loai, m.doan?.bo, m.doan?.giant, clips.filter((c) => c.trimEnd > m.t0 - 1 && c.trimStart < m.t0 + 1).map((c) => [+c.trimStart.toFixed(3), +c.trimEnd.toFixed(3)])]);
18816
18836
  return ra;
18817
18837
  }
@@ -21009,7 +21029,7 @@ function datCauLenh(a) {
21009
21029
  on2 = true;
21010
21030
  window.addEventListener("message", async (ev) => {
21011
21031
  const d = ev.data;
21012
- if (!d || d.xvaiLoi120323 !== true) return;
21032
+ if (!d || d.xvaiLoi120610 !== true) return;
21013
21033
  const o = String(ev.origin || "");
21014
21034
  if (!(o.indexOf("https://flow.google.com") === 0 || o.indexOf("https://labs.google") === 0)) return;
21015
21035
  const tra = (kq) => {