@kangsicj/nexussync 1.6.5 → 1.6.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/NexusSync.meta.js +1 -1
- package/dist/NexusSync.user.js +310 -17
- package/package.json +1 -1
package/dist/NexusSync.meta.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
|
|
9
9
|
// @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
|
|
10
10
|
// @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
|
|
11
|
-
// @version 1.6.
|
|
11
|
+
// @version 1.6.7
|
|
12
12
|
// @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
|
|
13
13
|
// @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
|
|
14
14
|
// @match *://*/*
|
package/dist/NexusSync.user.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @icon https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/assets/icon.svg
|
|
9
9
|
// @updateURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.meta.js
|
|
10
10
|
// @downloadURL https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@latest/dist/NexusSync.user.js
|
|
11
|
-
// @version 1.6.
|
|
11
|
+
// @version 1.6.7
|
|
12
12
|
// @description Watch any web video together in perfect sync: cinema mode, live AI subtitles & translation, chat bubbles with auto-translation, quick ink, cover, go-together to the next episode.
|
|
13
13
|
// @description:ko 어떤 웹 영상이든 완벽한 싱크로 함께 보기: 시네마 모드, 실시간 AI 자막·번역, 자동 번역 말풍선 채팅, 잠깐 그리기, 가리기, 다음 화도 함께.
|
|
14
14
|
// @match *://*/*
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
|
|
47
47
|
// The version of the code that is actually running (the manager's metadata can lag
|
|
48
48
|
// behind when an old copy is still installed).
|
|
49
|
-
const NXU_VERSION = '1.6.
|
|
49
|
+
const NXU_VERSION = '1.6.7';
|
|
50
50
|
// Rank used by the one-instance guard below and to tell newer builds apart in a room.
|
|
51
51
|
// It is independent of the public version (1.0.0 is the first public release, after
|
|
52
52
|
// private builds that reached ranks up to 10.2.0), so every older copy still installed
|
|
53
53
|
// steps aside instead of this release.
|
|
54
|
-
const NXU_RANK = '11.6.
|
|
54
|
+
const NXU_RANK = '11.6.7';
|
|
55
55
|
const NXU_SESSION = Math.random().toString(36).slice(2, 10); // this page load // raise with every release
|
|
56
56
|
// App icon (same artwork as assets/icon.svg / @icon), inlined so it shows offline too.
|
|
57
57
|
const NXU_ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTYgMjU2IiByb2xlPSJpbWciIGFyaWEtbGFiZWw9Ik5leHVzU3luYyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJueGJnIiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjNWIyZWZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmY0ZmEzIi8+PC9saW5lYXJHcmFkaWVudD48cmFkaWFsR3JhZGllbnQgaWQ9Im54Z2xvdyIgY3g9IjAuODIiIGN5PSIwLjE0IiByPSIwLjciPjxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iIzdjZjlmZiIgc3RvcC1vcGFjaXR5PSIwLjU1Ii8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjN2NmOWZmIiBzdG9wLW9wYWNpdHk9IjAiLz48L3JhZGlhbEdyYWRpZW50PjxsaW5lYXJHcmFkaWVudCBpZD0ibnhwbGF5IiB4MT0iMCIgeTE9IjAiIHgyPSIxIiB5Mj0iMSI+PHN0b3Agb2Zmc2V0PSIwIiBzdG9wLWNvbG9yPSIjZmZmZmZmIi8+PHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjZmZlM2YxIi8+PC9saW5lYXJHcmFkaWVudD48Y2xpcFBhdGggaWQ9Im54ciI+PHJlY3Qgd2lkdGg9IjI1NiIgaGVpZ2h0PSIyNTYiIHJ4PSI1OCIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNueHIpIj48cmVjdCB3aWR0aD0iMjU2IiBoZWlnaHQ9IjI1NiIgZmlsbD0idXJsKCNueGJnKSIvPjxyZWN0IHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2IiBmaWxsPSJ1cmwoI254Z2xvdykiLz48ZyBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMTUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCI+PHBhdGggZD0iTTYwIDExNiBBNzAgNzAgMCAwIDEgMTc4IDcyIi8+PHBhdGggZD0iTTE5NiAxNDAgQTcwIDcwIDAgMCAxIDc4IDE4NCIvPjwvZz48cGF0aCBkPSJNMTg2IDUwIEwyMDAgOTIgTDE1NyA4NiBaIiBmaWxsPSIjZmZmZmZmIi8+PHBhdGggZD0iTTcwIDIwNiBMNTYgMTY0IEw5OSAxNzAgWiIgZmlsbD0iI2ZmZmZmZiIvPjxwYXRoIGQ9Ik0xMTAgOTIgUTEwNCA4OCAxMDQgOTYgTDEwNCAxNjAgUTEwNCAxNjggMTEwIDE2NCBMMTYyIDEzMiBRMTY4IDEyOCAxNjIgMTI0IFoiIGZpbGw9InVybCgjbnhwbGF5KSIvPjwvZz48L3N2Zz4=';
|
|
@@ -64,6 +64,76 @@
|
|
|
64
64
|
return 0;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
+
// ── Offline Whisper helper. Speech recognition with the open-source Whisper model runs
|
|
68
|
+
// in a hidden frame on NexusSync's own package page on jsDelivr: many sites forbid the
|
|
69
|
+
// background worker it needs (their security policy), that page does not, and the page
|
|
70
|
+
// keeps the downloaded model for later visits. The copy of this script inside that frame
|
|
71
|
+
// does nothing else.
|
|
72
|
+
if (!IS_TOP && location.hostname === 'cdn.jsdelivr.net' && location.hash.startsWith('#nxu-whisper=')) {
|
|
73
|
+
const token = location.hash.slice('#nxu-whisper='.length);
|
|
74
|
+
const LIB = 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.1/dist/transformers.min.js';
|
|
75
|
+
const WORKER_SRC = `
|
|
76
|
+
let T = null, asr = null, key = '';
|
|
77
|
+
const post = (m) => self.postMessage(m);
|
|
78
|
+
let chain = Promise.resolve();
|
|
79
|
+
self.onmessage = (e) => { const m = e.data; chain = chain.then(() => handle(m)).catch(() => { }); };
|
|
80
|
+
async function handle(m) {
|
|
81
|
+
try {
|
|
82
|
+
if (m.type === 'load') {
|
|
83
|
+
if (!T) {
|
|
84
|
+
T = await import(m.lib); T.env.allowLocalModels = false; T.env.useBrowserCache = true;
|
|
85
|
+
const onnx = T.env.backends.onnx;
|
|
86
|
+
try { onnx.wasm.numThreads = 1; } catch (_) { }
|
|
87
|
+
// The runtime build that is tested with this library (one file pair, same CDN).
|
|
88
|
+
const ver = (onnx.versions && onnx.versions.web) || m.ort;
|
|
89
|
+
try { onnx.wasm.wasmPaths = { mjs: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@' + ver + '/dist/ort-wasm-simd-threaded.jsep.mjs', wasm: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@' + ver + '/dist/ort-wasm-simd-threaded.jsep.wasm' }; } catch (_) { }
|
|
90
|
+
}
|
|
91
|
+
const want = m.repo + '|' + m.device;
|
|
92
|
+
if (asr && key === want) { post({ type: 'ready', id: m.id, device: m.device }); return; }
|
|
93
|
+
if (asr) { try { await asr.dispose?.(); } catch (_) { } asr = null; }
|
|
94
|
+
const progress = (p) => { if (p && (p.status === 'progress' || p.status === 'progress_total')) post({ type: 'progress', id: m.id, file: p.file || '', loaded: p.loaded || 0, total: p.total || 0, all: p.status === 'progress_total' }); };
|
|
95
|
+
asr = await T.pipeline('automatic-speech-recognition', m.repo, { device: m.device, dtype: m.dtype, progress_callback: progress });
|
|
96
|
+
key = want;
|
|
97
|
+
post({ type: 'ready', id: m.id, device: m.device });
|
|
98
|
+
} else if (m.type === 'run') {
|
|
99
|
+
if (!asr) throw new Error('model not loaded');
|
|
100
|
+
const out = await asr(m.audio, { language: m.lang || null, task: 'transcribe', chunk_length_s: 30 });
|
|
101
|
+
post({ type: 'text', id: m.id, text: String((out && out.text) || '').trim() });
|
|
102
|
+
}
|
|
103
|
+
} catch (err) { post({ type: 'error', id: m.id, message: String((err && err.message) || err) }); }
|
|
104
|
+
}`;
|
|
105
|
+
let worker = null, parentOrigin = '*';
|
|
106
|
+
const send = (m) => { try { window.parent.postMessage(Object.assign({ nxuWhisper: token }, m), parentOrigin); } catch (_) { } };
|
|
107
|
+
const getWorker = () => {
|
|
108
|
+
if (worker) return worker;
|
|
109
|
+
worker = new Worker(URL.createObjectURL(new Blob([WORKER_SRC], { type: 'text/javascript' })), { type: 'module' });
|
|
110
|
+
worker.onmessage = (e) => send(e.data);
|
|
111
|
+
worker.onerror = (e) => send({ type: 'error', message: 'worker: ' + (e.message || 'failed') });
|
|
112
|
+
return worker;
|
|
113
|
+
};
|
|
114
|
+
const cacheHas = async (urls) => {
|
|
115
|
+
try { const c = await caches.open('transformers-cache'); for (const u of urls) if (!(await c.match(u))) return false; return true; } catch (_) { return false; }
|
|
116
|
+
};
|
|
117
|
+
window.addEventListener('message', async (e) => {
|
|
118
|
+
const m = e.data;
|
|
119
|
+
if (!m || m.nxuWhisper !== token || e.source !== window.parent) return;
|
|
120
|
+
parentOrigin = e.origin || '*';
|
|
121
|
+
try {
|
|
122
|
+
if (m.cmd === 'status') send({ type: 'status', id: m.id, cached: await cacheHas(m.urls || []), gpu: !!navigator.gpu, f16: navigator.gpu ? await navigator.gpu.requestAdapter().then(a => !!a && a.features.has('shader-f16')).catch(() => false) : false });
|
|
123
|
+
else if (m.cmd === 'load') getWorker().postMessage({ type: 'load', id: m.id, lib: LIB, ort: '1.31.0-dev.20260914-8d85527a0', repo: m.repo, device: m.device, dtype: m.dtype });
|
|
124
|
+
else if (m.cmd === 'run') getWorker().postMessage({ type: 'run', id: m.id, audio: m.audio, lang: m.lang }, [m.audio.buffer]);
|
|
125
|
+
else if (m.cmd === 'remove') {
|
|
126
|
+
const c = await caches.open('transformers-cache');
|
|
127
|
+
for (const req of await c.keys()) if (req.url.includes('/' + m.repo + '/')) await c.delete(req);
|
|
128
|
+
if (worker) { worker.terminate(); worker = null; }
|
|
129
|
+
send({ type: 'removed', id: m.id });
|
|
130
|
+
}
|
|
131
|
+
} catch (err) { send({ type: 'error', id: m.id, message: String(err && err.message || err) }); }
|
|
132
|
+
});
|
|
133
|
+
send({ type: 'hello' });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
67
137
|
// ── One instance per page, across userscript sandboxes (shared DOM marker).
|
|
68
138
|
// The flag is per build, so an older build that ran first cannot stop this one (the
|
|
69
139
|
// shared DOM marker below decides which build stays).
|
|
@@ -628,6 +698,7 @@
|
|
|
628
698
|
const I18N = {
|
|
629
699
|
en: {
|
|
630
700
|
asrEngine: 'Speech recognition engine', asrBrowser: 'Browser built-in (free)', asrOpenAI: 'OpenAI gpt-4o-mini-transcribe (fast, accurate)', asrOpenAIHQ: 'OpenAI gpt-4o-transcribe (best accuracy)',
|
|
701
|
+
asrLocal: 'Whisper offline (this PC, free, no key)', whisperModel_base: 'Whisper base · fast · {mb} MB', whisperModel_small: 'Whisper small · more accurate, slower · {mb} MB', whisperModel_turbo: 'Whisper large-v3 turbo · best · {mb} MB · needs a graphics card (WebGPU)', whisperDownload: 'Download ({mb} MB)', whisperRemove: 'Remove', whisperChecking: 'Checking…', whisperReady: 'Ready (offline)', whisperDownloading: 'Downloading the model — only this once on this site, then it works offline.', whisperDone: 'Offline Whisper is ready', whisperFailed: 'The Whisper download failed — check the connection and try again', whisperHelp: 'Open-source speech recognition that runs on this PC: nothing is sent anywhere, no key needed. Downloaded once per site, then it works offline.', whisperReadyHelp: 'Recognition runs on this PC. Bigger models are more accurate but need a faster PC.', whisperNeedsGpu: 'Needs a graphics card', whisperGpuHelp: 'This model needs WebGPU with 16-bit support, which this browser or PC does not offer. Pick base or small.', whisperBlocked: 'Not available here', whisperBlockedHelp: 'The helper NexusSync needs could not start here (blocked by the site, or the userscript manager does not run in frames). Allow it to run in frames, or use another site.', whisperBlockedHere: '⚠️ Offline Whisper cannot start on this site — using the browser engine.',
|
|
631
702
|
asrGroq: 'Groq Whisper large-v3 turbo (very fast)', providerClaude: 'Claude (context-aware, most natural)', providerGPT: 'GPT (context-aware)', providerDeepL: 'DeepL',
|
|
632
703
|
engineHelp: 'AI engines (OpenAI, Claude, Groq, DeepL) use your own API key and give the best accuracy; without a key the free engines are used.',
|
|
633
704
|
aiNeedKey: 'Enter the {names} API key under Advanced — until then the free engine is used.', aiKeys: 'API keys', aiTest: 'Test',
|
|
@@ -714,6 +785,7 @@
|
|
|
714
785
|
subUsingMicFallback: 'The video sound could not be heard directly — listening through the microphone (turn the speakers up).',
|
|
715
786
|
subTabShareEnded: 'Tab audio sharing stopped, so subtitles were turned off.',
|
|
716
787
|
subHearVideo: '🎧 Listening to the video', subHearMic: '🎧 Listening through the microphone', subVideoSilent: '🔇 No sound reaches the subtitles from this video',
|
|
788
|
+
subNoWords: '⚠️ The speech engine hears sound but returns no words here. In AI Sub → Advanced, pick “Whisper offline” (free, runs on this PC) or add a free Groq key.', subNoWordsEdge: '⚠️ Edge’s speech engine hears the video but returns no words. In AI Sub → Advanced, pick “Whisper offline” (free, runs on this PC), use Chrome, or add a free Groq key.', subNoWordsKey: '⚠️ The browser’s speech engine returns no words here — switching to AI recognition with your key.',
|
|
717
789
|
subDiagCopy: 'Copy a problem report', subDiagCopied: '🔬 Report copied — paste it in your message', subDiagInDebug: '🔬 Report written to the debug console (Settings → Advanced → Debug)',
|
|
718
790
|
subNoTrackInput: '⚠️ This browser’s speech engine cannot listen to the video sound directly — it only hears the microphone (play the sound through speakers, not headphones), or add a free Groq key in AI Sub → Advanced.', subIssueNoTrack: 'The speech engine only hears the microphone here', subNoService: '⚠️ This browser has no working speech recognition service (it works in Chrome). Add a free Groq or an OpenAI key in AI Sub → Advanced to use AI recognition instead.', subNoServiceKey: '⚠️ This browser has no working speech recognition service — switching to AI recognition with your key.',
|
|
719
791
|
subIssueNet: '⚠️ Speech service connection is unstable — retrying', subIssueNoResult: '⚠️ Sound arrives but no words are recognised', subSiteBlocksSpeech: 'This site does not allow the browser’s speech recognition. Add an OpenAI or Groq key (AI subtitles → Advanced) to use AI subtitles here.', subSiteBlocksSpeechKey: 'This site blocks the browser’s speech recognition — switching to cloud recognition with your key.', subTryMic: '🎤 Listen through the mic', subTryKey: '🔑 Use an AI recognition key', subShareTab: '🎬 Connect tab sound', subTabNotShared: 'Tab audio was not shared. Choose this tab and turn on “Share tab audio”.',
|
|
@@ -746,6 +818,7 @@
|
|
|
746
818
|
},
|
|
747
819
|
ko: {
|
|
748
820
|
asrEngine: '음성 인식 엔진', asrBrowser: '브라우저 내장 (무료)', asrOpenAI: 'OpenAI gpt-4o-mini-transcribe (빠르고 정확)', asrOpenAIHQ: 'OpenAI gpt-4o-transcribe (최고 정확도)',
|
|
821
|
+
asrLocal: 'Whisper 오프라인 (이 PC, 무료, 키 없음)', whisperModel_base: 'Whisper base · 빠름 · {mb}MB', whisperModel_small: 'Whisper small · 더 정확, 느림 · {mb}MB', whisperModel_turbo: 'Whisper large-v3 turbo · 최고 · {mb}MB · 그래픽카드(WebGPU) 필요', whisperDownload: '다운로드 ({mb}MB)', whisperRemove: '삭제', whisperChecking: '확인 중…', whisperReady: '준비됨 (오프라인)', whisperDownloading: '모델을 받는 중이에요 — 이 사이트에서는 이번 한 번만 받고, 이후엔 오프라인으로 동작해요.', whisperDone: '오프라인 Whisper 준비 완료', whisperFailed: 'Whisper 다운로드에 실패했어요 — 연결을 확인하고 다시 시도해 주세요', whisperHelp: '이 PC에서 직접 돌아가는 오픈소스 음성 인식이에요. 어디에도 보내지 않고 키도 필요 없어요. 사이트마다 한 번 받으면 이후엔 오프라인으로 동작해요.', whisperReadyHelp: '음성 인식이 이 PC에서 돌아가요. 큰 모델일수록 정확하지만 더 빠른 PC가 필요해요.', whisperNeedsGpu: '그래픽카드 필요', whisperGpuHelp: '이 모델은 16비트를 지원하는 WebGPU가 필요한데, 이 브라우저나 PC에서는 쓸 수 없어요. base나 small을 골라 주세요.', whisperBlocked: '여기서는 쓸 수 없음', whisperBlockedHelp: 'NexusSync가 쓰는 도우미가 여기서 시작되지 못했어요 (사이트가 막았거나, 유저스크립트 관리자가 프레임 안에서 실행되지 않아요). 프레임 안 실행을 허용하거나 다른 사이트에서 써 주세요.', whisperBlockedHere: '⚠️ 이 사이트에서는 오프라인 Whisper를 시작할 수 없어 브라우저 엔진을 써요.',
|
|
749
822
|
asrGroq: 'Groq Whisper large-v3 turbo (매우 빠름)', providerClaude: 'Claude (문맥 이해, 가장 자연스러움)', providerGPT: 'GPT (문맥 이해)', providerDeepL: 'DeepL',
|
|
750
823
|
engineHelp: 'AI 엔진(OpenAI·Claude·Groq·DeepL)은 본인 API 키로 동작하며 정확도가 가장 높습니다. 키가 없으면 무료 엔진을 사용합니다.',
|
|
751
824
|
aiNeedKey: '고급 설정에서 {names} API 키를 입력하세요 — 그전까지는 무료 엔진을 사용합니다.', aiKeys: 'API 키', aiTest: '확인',
|
|
@@ -832,6 +905,7 @@
|
|
|
832
905
|
subUsingMicFallback: '영상 소리를 직접 들을 수 없어 마이크로 들어요. 스피커 소리를 키워 주세요.',
|
|
833
906
|
subTabShareEnded: '탭 오디오 공유가 끝나서 자막을 껐어요.',
|
|
834
907
|
subHearVideo: '🎧 영상 소리 듣는 중', subHearMic: '🎧 마이크로 듣는 중', subVideoSilent: '🔇 이 영상의 소리가 자막에 전달되지 않아요',
|
|
908
|
+
subNoWords: '⚠️ 음성 인식이 소리는 듣지만 말을 알아듣지 못하고 있어요. AI 자막 → 고급에서 “Whisper 오프라인”(무료, 이 PC에서 동작)을 고르거나 무료 Groq 키를 넣어 주세요.', subNoWordsEdge: '⚠️ Edge의 음성 인식이 영상 소리를 받지만 말을 알아듣지 못하고 있어요. AI 자막 → 고급에서 “Whisper 오프라인”(무료, 이 PC에서 동작)을 고르거나, Chrome을 쓰거나, 무료 Groq 키를 넣어 주세요.', subNoWordsKey: '⚠️ 브라우저 음성 인식이 말을 알아듣지 못해 입력한 키로 AI 인식을 시작해요.',
|
|
835
909
|
subDiagCopy: '문제 진단 보고서 복사', subDiagCopied: '🔬 진단 보고서를 복사했어요 — 메시지에 붙여 넣어 주세요', subDiagInDebug: '🔬 진단 보고서를 디버그 콘솔에 남겼어요 (설정 → 고급 → 디버그)',
|
|
836
910
|
subNoTrackInput: '⚠️ 이 브라우저의 음성 인식은 영상 소리를 직접 듣지 못하고 마이크로만 들어요. 이어폰 대신 스피커로 소리를 내거나, AI 자막 → 고급에서 무료 Groq 키를 넣어 주세요.', subIssueNoTrack: '이 브라우저는 마이크로만 들을 수 있어요', subNoService: '⚠️ 이 브라우저에는 동작하는 음성 인식 서비스가 없어요 (Chrome에서는 동작해요). AI 자막 → 고급에서 무료 Groq 키나 OpenAI 키를 넣으면 AI 인식으로 쓸 수 있어요.', subNoServiceKey: '⚠️ 이 브라우저에는 동작하는 음성 인식 서비스가 없어 입력한 키로 AI 인식을 시작해요.',
|
|
837
911
|
subIssueNet: '⚠️ 음성 인식 서버 연결이 불안정해요 — 다시 시도 중', subIssueNoResult: '⚠️ 소리는 들어오는데 말이 인식되지 않아요', subSiteBlocksSpeech: '이 사이트는 브라우저 음성 인식을 막아 두었어요. AI 자막 → 고급에서 OpenAI 또는 Groq 키를 넣으면 여기서도 쓸 수 있어요.', subSiteBlocksSpeechKey: '이 사이트는 브라우저 음성 인식을 막아 두어서, 넣어 둔 키로 클라우드 인식으로 바꿀게요.', subTryMic: '🎤 마이크로 듣기', subTryKey: '🔑 AI 인식 키 사용', subShareTab: '🎬 탭 소리 연결', subTabNotShared: '탭 오디오가 공유되지 않았어요. 이 탭을 고르고 “탭 오디오 공유”를 켜 주세요.',
|
|
@@ -2797,8 +2871,14 @@
|
|
|
2797
2871
|
const mixGain = ctx.createGain();
|
|
2798
2872
|
mixGain.gain.value = micForMix && web ? 0.75 : 1;
|
|
2799
2873
|
const dest = ctx.createMediaStreamDestination();
|
|
2800
|
-
|
|
2801
|
-
|
|
2874
|
+
// The copy the engine may listen to: quiet speech (a low player volume, a
|
|
2875
|
+
// shared tab) is evened out and raised, loud effects are held back.
|
|
2876
|
+
const comp = ctx.createDynamicsCompressor();
|
|
2877
|
+
try { comp.threshold.value = -42; comp.knee.value = 18; comp.ratio.value = 6; comp.attack.value = 0.005; comp.release.value = 0.25; } catch (_) { }
|
|
2878
|
+
const makeup = ctx.createGain();
|
|
2879
|
+
makeup.gain.value = 3;
|
|
2880
|
+
mixGain.connect(comp); comp.connect(makeup); makeup.connect(dest);
|
|
2881
|
+
const nodes = { list: [mixGain, comp, makeup], analysers: {}, mix: mixGain };
|
|
2802
2882
|
const connect = (stream, label) => {
|
|
2803
2883
|
if (!stream) return;
|
|
2804
2884
|
const source = ctx.createMediaStreamSource(stream);
|
|
@@ -3056,18 +3136,63 @@
|
|
|
3056
3136
|
// Plenty of sound but not a single word back: try the other ways of feeding the
|
|
3057
3137
|
// engine on its own first, then say so, with a one-tap way out.
|
|
3058
3138
|
if (this._useWebSpeech && !this._cloud && this._rescueNoWords()) { updateAIBtnUX(); return; }
|
|
3059
|
-
|
|
3139
|
+
const lastStepTried = this._rescueStage >= 3 && Date.now() - (this._stageAt || 0) >= 10000
|
|
3140
|
+
&& ((this._stageSoundMs || 0) >= 10000 || (this._diag.empty || 0) - (this._stageEmpty || 0) >= 6);
|
|
3141
|
+
if (this._useWebSpeech && !this._issue && (this._soundMs > 15000 || (this._diag.empty || 0) >= 10) && (this._lastResultAt || 0) < (this._startedAt || 0) && (this._cloud || lastStepTried)) {
|
|
3142
|
+
if (this._feedFromMemory) STORE.set(this._feedKey(), ''); // it no longer works: start fresh next time
|
|
3143
|
+
this._issue = 'noresult';
|
|
3144
|
+
if (!this._cloud && !this._toldNoWords) {
|
|
3145
|
+
this._toldNoWords = true;
|
|
3146
|
+
const key = AI.key('groq') || AI.key('openai');
|
|
3147
|
+
logDebug('AI Sub: the speech engine returns no words here (' + (this._diag.empty || 0) + ' empty results).', 'error');
|
|
3148
|
+
if (key && STORE.get('nxu_asr_provider', 'browser') === 'browser') {
|
|
3149
|
+
showToast(t('subNoWordsKey'));
|
|
3150
|
+
STORE.set('nxu_asr_provider', AI.key('groq') ? 'groq' : 'openai');
|
|
3151
|
+
this.restart('no words from the browser engine');
|
|
3152
|
+
} else showToast(t(/\bEdg\//.test(navigator.userAgent) ? 'subNoWordsEdge' : 'subNoWords'));
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3060
3155
|
this._updateListenChip();
|
|
3061
3156
|
updateAIBtnUX();
|
|
3062
3157
|
},
|
|
3158
|
+
// Which way of feeding the speech engine gave words in this browser last time. Some
|
|
3159
|
+
// engines (Edge) answer a captured track with empty results for minutes; once a rescue
|
|
3160
|
+
// step has worked, the next start begins there instead of waiting through the others.
|
|
3161
|
+
_feedKey() {
|
|
3162
|
+
const ua = navigator.userAgent || '';
|
|
3163
|
+
return 'nxu_ai_feed_' + (/\bEdg\//.test(ua) ? 'edge' : /\bOPR\//.test(ua) ? 'opera' : /\bWhale\//.test(ua) ? 'whale' : /SamsungBrowser/.test(ua) ? 'samsung' : /Firefox\//.test(ua) ? 'firefox' : 'chrome');
|
|
3164
|
+
},
|
|
3165
|
+
_applyFeedMemory() {
|
|
3166
|
+
this._feedSaved = false;
|
|
3167
|
+
this._feedFromMemory = '';
|
|
3168
|
+
if (this._cloud || this._isAppleMobile()) return;
|
|
3169
|
+
const feed = STORE.get(this._feedKey(), '');
|
|
3170
|
+
if (feed === 'mix') { this._useMixTrack = true; this._rescueStage = 2; }
|
|
3171
|
+
else if (feed === 'mic') { this._trackDisabled = true; this._rescueStage = 3; }
|
|
3172
|
+
else return;
|
|
3173
|
+
this._stageAt = Date.now(); this._stageSoundMs = 0; this._stageEmpty = 0;
|
|
3174
|
+
this._feedFromMemory = feed;
|
|
3175
|
+
logDebug('AI Sub: starting with ' + (feed === 'mix' ? 'the Web Audio copy of the sound' : 'the engine’s own microphone') + ' (it gave words last time in this browser).', 'info');
|
|
3176
|
+
},
|
|
3177
|
+
_rememberFeed() {
|
|
3178
|
+
if (this._feedSaved || this._cloud) return;
|
|
3179
|
+
this._feedSaved = true;
|
|
3180
|
+
const feed = this._trackDisabled ? 'mic' : this._useMixTrack ? 'mix' : '';
|
|
3181
|
+
if ((STORE.get(this._feedKey(), '') || '') === feed) return;
|
|
3182
|
+
STORE.set(this._feedKey(), feed);
|
|
3183
|
+
if (feed) logDebug('AI Sub: words came with ' + (feed === 'mix' ? 'the Web Audio copy' : 'the own microphone') + '; next time this browser starts that way.', 'success');
|
|
3184
|
+
},
|
|
3063
3185
|
// Sound keeps arriving but the speech engine returns no words (some Chrome builds take
|
|
3064
3186
|
// a captured track and then never answer, or the on-device model hears nothing).
|
|
3065
3187
|
// Each step is tried for about ten seconds of sound: online recognition instead of
|
|
3066
3188
|
// the on-device model → the Web Audio copy of the sound → the engine's own microphone.
|
|
3067
3189
|
_rescueNoWords() {
|
|
3068
3190
|
if (this.captureMode === 'ios-mic' || (this._lastResultAt || 0) >= (this._stageAt || 0)) return false;
|
|
3069
|
-
|
|
3070
|
-
|
|
3191
|
+
// Evidence of "hears but no words": ten seconds of speech-level sound, or a run of
|
|
3192
|
+
// empty results from the engine itself (it is hearing something, but no words).
|
|
3193
|
+
const emptyRun = (this._diag.empty || 0) - (this._stageEmpty || 0);
|
|
3194
|
+
if (((this._stageSoundMs || 0) < 10000 && emptyRun < 6) || Date.now() - (this._stageAt || 0) < 8000) return false;
|
|
3195
|
+
const next = () => { this._rescueStage++; this._stageAt = Date.now(); this._stageSoundMs = 0; this._stageEmpty = this._diag.empty || 0; };
|
|
3071
3196
|
const rebuild = (why) => { this._commitInterim('rescue', 0); this._resetSegment(); this._destroyRecognizer(); this._createRecognizer(); this._scheduleRestart(why, 150, true); };
|
|
3072
3197
|
if (this._rescueStage === 0) {
|
|
3073
3198
|
next();
|
|
@@ -3213,7 +3338,20 @@
|
|
|
3213
3338
|
},
|
|
3214
3339
|
_onResult(event) {
|
|
3215
3340
|
this._touch();
|
|
3341
|
+
// Some engines (seen with Edge listening to a captured track) send result events
|
|
3342
|
+
// that carry no words at all. Those are not a sign of success: counting them as
|
|
3343
|
+
// results kept every rescue step and every warning from ever starting.
|
|
3344
|
+
let anyWords = false;
|
|
3345
|
+
try {
|
|
3346
|
+
for (let i = event.resultIndex || 0; i < event.results.length; i++) {
|
|
3347
|
+
const tx = event.results[i]?.[0]?.transcript;
|
|
3348
|
+
if (tx && String(tx).trim()) { anyWords = true; this._diag.lastText = String(tx).trim().slice(-60); break; }
|
|
3349
|
+
}
|
|
3350
|
+
} catch (_) { }
|
|
3351
|
+
if (!anyWords) { this._diag.empty = (this._diag.empty || 0) + 1; return; }
|
|
3352
|
+
this._diag.words = (this._diag.words || 0) + 1;
|
|
3216
3353
|
this._lastResultAt = Date.now();
|
|
3354
|
+
this._rememberFeed();
|
|
3217
3355
|
this._networkErrors = 0;
|
|
3218
3356
|
this._networkRetryMs = 0;
|
|
3219
3357
|
this._audioCaptureErrors = 0;
|
|
@@ -3959,6 +4097,7 @@
|
|
|
3959
4097
|
this._rescueStage = 0;
|
|
3960
4098
|
this._stageAt = Date.now();
|
|
3961
4099
|
this._stageSoundMs = 0;
|
|
4100
|
+
this._stageEmpty = 0;
|
|
3962
4101
|
this._waitOnline = false;
|
|
3963
4102
|
this._googleBackoffUntil = 0;
|
|
3964
4103
|
this._providerStatus = '';
|
|
@@ -3992,6 +4131,7 @@
|
|
|
3992
4131
|
const token = ++this._startToken;
|
|
3993
4132
|
this.state = 'starting';
|
|
3994
4133
|
this._resetRuntime();
|
|
4134
|
+
this._applyFeedMemory();
|
|
3995
4135
|
this._abortCtrl = new AbortController();
|
|
3996
4136
|
this._syncUI();
|
|
3997
4137
|
try {
|
|
@@ -4021,6 +4161,7 @@
|
|
|
4021
4161
|
this.state = 'running';
|
|
4022
4162
|
this._diag = { sound: 0, results: 0, err: '' };
|
|
4023
4163
|
this._toldNoTrack = false;
|
|
4164
|
+
this._toldNoWords = false;
|
|
4024
4165
|
this._startedAt = Date.now();
|
|
4025
4166
|
this._soundMs = 0;
|
|
4026
4167
|
this._stageAt = Date.now();
|
|
@@ -4054,10 +4195,10 @@
|
|
|
4054
4195
|
'microphone blocked by site: ' + (this._micBlockedByPolicy() ? 'YES' : 'no') + ' · permission: ' + (await this._micPermissionState()),
|
|
4055
4196
|
'recognition: ' + (this._cloud ? 'cloud ' + AI.asrModel() : (this._useWebSpeech ? this._sttProvider || 'web-speech' : '-')) + ' · state: ' + this.state,
|
|
4056
4197
|
'wanted sound: ' + (this.audioMode || this._audioMode()) + ' · capturing: ' + (this.captureMode || '-') + ' · engine input: ' + (this._recognitionInput || '-') + (this._trackDisabled ? ' (track refused)' : '') + (this._micMixed ? ' · mic mixed in' : '') + (this._useMixTrack ? ' · web-audio track' : '') + ' · rescue step ' + (this._rescueStage || 0),
|
|
4057
|
-
'video: ' + (v ? (v.paused ? 'paused' : 'playing') + (v.muted ? ', muted' : '') + ', volume ' + Math.round((v.volume || 0) * 100) + '%' : 'none') + ' · video sound peak: ' + (this._mediaPeak || 0).toFixed(4),
|
|
4198
|
+
'video: ' + (v ? (v.paused ? 'paused' : 'playing') + (v.muted ? ', muted' : '') + ', volume ' + Math.round((v.volume || 0) * 100) + '%' : (STATE.cinemaIframe || STATE.frameMedia ? 'in a frame' : 'none')) + ' · sound from: ' + (this._sharedTab && this.webMediaStream === this._sharedTab ? 'shared tab' : this._webFromElement ? 'video element' : this.captureMode) + ' · video sound peak: ' + (this._mediaPeak || 0).toFixed(4),
|
|
4058
4199
|
'levels: video ' + Math.round((this._levels?.media || 0) * 400) + ' · mic ' + Math.round((this._levels?.mic || 0) * 400),
|
|
4059
|
-
'engine events: sound ' + this._diag.sound + ' · results ' + this._diag.results + ' · last error ' + (this._diag.err || '-') + ' · network errors ' + (this._networkErrors || 0),
|
|
4060
|
-
'issue: ' + (this._issue || '-')
|
|
4200
|
+
'engine events: sound ' + this._diag.sound + ' · results ' + this._diag.results + ' (with words ' + (this._diag.words || 0) + ', empty ' + (this._diag.empty || 0) + ')' + (this._diag.lastText ? ' · last heard "' + this._diag.lastText + '"' : '') + ' · last error ' + (this._diag.err || '-') + ' · network errors ' + (this._networkErrors || 0),
|
|
4201
|
+
'issue: ' + (this._issue || '-') + ' · started with: ' + (this._feedFromMemory || 'video track') + ' · remembered for this browser: ' + (STORE.get(this._feedKey(), '') || '-') + ' · running ' + Math.round((Date.now() - (this._startedAt || Date.now())) / 1000) + ' s'
|
|
4061
4202
|
];
|
|
4062
4203
|
return lines.join('\n');
|
|
4063
4204
|
},
|
|
@@ -4073,7 +4214,7 @@
|
|
|
4073
4214
|
this._cloud = false;
|
|
4074
4215
|
CLOUD_ASR.stop();
|
|
4075
4216
|
const bad = err?.status === 401 || err?.status === 403;
|
|
4076
|
-
showToast(t(bad ? 'aiKeyInvalid' : 'cloudAsrFallback'));
|
|
4217
|
+
showToast(t(err?.code === 'helper' ? 'whisperBlockedHere' : bad ? 'aiKeyInvalid' : 'cloudAsrFallback'));
|
|
4077
4218
|
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
|
|
4078
4219
|
if (SR && this.active && !this.recognizer) {
|
|
4079
4220
|
this._useWebSpeech = true;
|
|
@@ -4615,6 +4756,7 @@
|
|
|
4615
4756
|
key(name) { return String(STORE.get('nxu_key_' + name, '') || '').trim(); },
|
|
4616
4757
|
asrProvider() {
|
|
4617
4758
|
const p = STORE.get('nxu_asr_provider', 'browser');
|
|
4759
|
+
if (p === 'local' && LOCAL_WHISPER.available() && STORE.get('nxu_whisper_ready_' + LOCAL_WHISPER.model(), false)) return p;
|
|
4618
4760
|
if ((p === 'openai' || p === 'openai-hq') && this.key('openai')) return p;
|
|
4619
4761
|
if (p === 'groq' && this.key('groq')) return p;
|
|
4620
4762
|
return 'browser';
|
|
@@ -4627,6 +4769,7 @@
|
|
|
4627
4769
|
return ['auto', 'browser', 'device', 'google', 'openai', 'anthropic', 'deepl'].includes(p) ? p : 'auto';
|
|
4628
4770
|
},
|
|
4629
4771
|
asrModel(p = this.asrProvider()) {
|
|
4772
|
+
if (p === 'local') return 'whisper-' + LOCAL_WHISPER.model() + ' (offline)';
|
|
4630
4773
|
if (p === 'groq') return 'whisper-large-v3-turbo';
|
|
4631
4774
|
if (p === 'openai-hq') return 'gpt-4o-transcribe';
|
|
4632
4775
|
return 'gpt-4o-mini-transcribe';
|
|
@@ -4807,6 +4950,93 @@
|
|
|
4807
4950
|
// Raw audio is resampled to 16 kHz mono; an adaptive energy detector cuts it at natural
|
|
4808
4951
|
// pauses (with 300 ms pre-roll so first syllables are kept) and each utterance is sent
|
|
4809
4952
|
// as a small WAV clip. Results are released strictly in speaking order.
|
|
4953
|
+
// Offline speech recognition with the open-source Whisper model (transformers.js, run by
|
|
4954
|
+
// the hidden helper frame above). PC only, downloaded once when the user asks for it.
|
|
4955
|
+
const LOCAL_WHISPER = {
|
|
4956
|
+
HELPER: 'https://cdn.jsdelivr.net/npm/@kangsicj/nexussync@1.6.4/package.json',
|
|
4957
|
+
MODELS: {
|
|
4958
|
+
base: { repo: 'onnx-community/whisper-base', mb: 73, device: 'wasm', dtype: { encoder_model: 'q8', decoder_model_merged: 'q8' } },
|
|
4959
|
+
small: { repo: 'onnx-community/whisper-small', mb: 237, device: 'wasm', dtype: { encoder_model: 'q8', decoder_model_merged: 'q8' } },
|
|
4960
|
+
turbo: { repo: 'onnx-community/whisper-large-v3-turbo', mb: 536, device: 'webgpu', gpu: true, dtype: { encoder_model: 'q4f16', decoder_model_merged: 'q4f16' } }
|
|
4961
|
+
},
|
|
4962
|
+
_frame: null, _token: '', _ready: null, _n: 0, _wait: new Map(), _loaded: '', _gpu: null, _queue: 0,
|
|
4963
|
+
available() { return !IS_IOS && !/Android/i.test(navigator.userAgent) && typeof Worker === 'function'; },
|
|
4964
|
+
model() { const m = STORE.get('nxu_whisper_model', 'base'); return this.MODELS[m] ? m : 'base'; },
|
|
4965
|
+
files(id) {
|
|
4966
|
+
const M = this.MODELS[id], base = `https://huggingface.co/${M.repo}/resolve/main/`;
|
|
4967
|
+
const sfx = (d) => (d === 'q8' ? '_quantized' : d === 'fp32' ? '' : '_' + d);
|
|
4968
|
+
return ['config.json', 'tokenizer.json', `onnx/encoder_model${sfx(M.dtype.encoder_model)}.onnx`, `onnx/decoder_model_merged${sfx(M.dtype.decoder_model_merged)}.onnx`].map(f => base + f);
|
|
4969
|
+
},
|
|
4970
|
+
_connect() {
|
|
4971
|
+
if (this._ready) return this._ready;
|
|
4972
|
+
this._ready = new Promise((resolve, reject) => {
|
|
4973
|
+
this._token = Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
4974
|
+
const f = document.createElement('iframe');
|
|
4975
|
+
f.src = this.HELPER + '#nxu-whisper=' + this._token;
|
|
4976
|
+
f.setAttribute('allow', 'webgpu');
|
|
4977
|
+
f.setAttribute('aria-hidden', 'true');
|
|
4978
|
+
f.tabIndex = -1;
|
|
4979
|
+
f.style.cssText = 'position:fixed;width:1px;height:1px;left:-10px;top:-10px;border:0;opacity:0;pointer-events:none;';
|
|
4980
|
+
const timer = setTimeout(() => { this._ready = null; f.remove(); reject(Object.assign(new Error('helper frame did not answer'), { code: 'helper' })); }, 12000);
|
|
4981
|
+
const onMsg = (e) => {
|
|
4982
|
+
const m = e.data;
|
|
4983
|
+
if (!m || m.nxuWhisper !== this._token || e.source !== f.contentWindow) return;
|
|
4984
|
+
if (m.type === 'hello') { clearTimeout(timer); resolve(f); return; }
|
|
4985
|
+
const w = this._wait.get(m.id);
|
|
4986
|
+
if (!w) return;
|
|
4987
|
+
if (m.type === 'progress') { w.progress?.(m); return; }
|
|
4988
|
+
this._wait.delete(m.id);
|
|
4989
|
+
if (m.type === 'error') w.reject(new Error(m.message || 'whisper failed'));
|
|
4990
|
+
else w.resolve(m);
|
|
4991
|
+
};
|
|
4992
|
+
window.addEventListener('message', onMsg);
|
|
4993
|
+
(document.body || document.documentElement).appendChild(f);
|
|
4994
|
+
this._frame = f;
|
|
4995
|
+
});
|
|
4996
|
+
return this._ready;
|
|
4997
|
+
},
|
|
4998
|
+
async _call(msg, { progress = null, transfer = [], timeout = 0 } = {}) {
|
|
4999
|
+
const f = await this._connect();
|
|
5000
|
+
const id = ++this._n;
|
|
5001
|
+
return new Promise((resolve, reject) => {
|
|
5002
|
+
const timer = timeout ? setTimeout(() => { this._wait.delete(id); reject(new Error('whisper timed out')); }, timeout) : 0;
|
|
5003
|
+
this._wait.set(id, { resolve: (v) => { clearTimeout(timer); resolve(v); }, reject: (e) => { clearTimeout(timer); reject(e); }, progress });
|
|
5004
|
+
f.contentWindow.postMessage(Object.assign({ nxuWhisper: this._token, id }, msg), 'https://cdn.jsdelivr.net', transfer);
|
|
5005
|
+
});
|
|
5006
|
+
},
|
|
5007
|
+
async status(id = this.model()) {
|
|
5008
|
+
const r = await this._call({ cmd: 'status', urls: this.files(id) }, { timeout: 15000 });
|
|
5009
|
+
this._gpu = { gpu: r.gpu, f16: r.f16 };
|
|
5010
|
+
return r;
|
|
5011
|
+
},
|
|
5012
|
+
canRun(id = this.model()) { return !this.MODELS[id].gpu || !!(this._gpu && this._gpu.f16); },
|
|
5013
|
+
// Downloads (first time) and loads the model; progress gets 0..1.
|
|
5014
|
+
async load(id = this.model(), progress = null) {
|
|
5015
|
+
const M = this.MODELS[id];
|
|
5016
|
+
if (this._loaded === id) return true;
|
|
5017
|
+
const seen = new Map();
|
|
5018
|
+
await this._call({ cmd: 'load', repo: M.repo, device: M.device, dtype: M.dtype }, {
|
|
5019
|
+
progress: (p) => {
|
|
5020
|
+
if (!progress) return;
|
|
5021
|
+
if (p.all && p.total) { progress(p.loaded / p.total); return; }
|
|
5022
|
+
if (p.file && p.total) { seen.set(p.file, [p.loaded, p.total]); let a = 0, b = 0; seen.forEach(([l, t]) => { a += l; b += t; }); progress(Math.min(1, a / Math.max(b, M.mb * 1048576 * 0.9))); }
|
|
5023
|
+
}
|
|
5024
|
+
});
|
|
5025
|
+
this._loaded = id;
|
|
5026
|
+
return true;
|
|
5027
|
+
},
|
|
5028
|
+
async remove(id = this.model()) { await this._call({ cmd: 'remove', repo: this.MODELS[id].repo }, { timeout: 20000 }); if (this._loaded === id) this._loaded = ''; },
|
|
5029
|
+
async transcribe(samples, lang) {
|
|
5030
|
+
if (this._queue > 3) { logDebug('AI Sub: offline Whisper is behind; skipping a line to catch up.', 'warn'); return ''; }
|
|
5031
|
+
this._queue++;
|
|
5032
|
+
try {
|
|
5033
|
+
await this.load();
|
|
5034
|
+
const r = await this._call({ cmd: 'run', audio: samples, lang: lang || '' }, { transfer: [samples.buffer], timeout: 120000 });
|
|
5035
|
+
return String(r.text || '').trim();
|
|
5036
|
+
} finally { this._queue--; }
|
|
5037
|
+
}
|
|
5038
|
+
};
|
|
5039
|
+
|
|
4810
5040
|
const CLOUD_ASR = {
|
|
4811
5041
|
RATE: 16000,
|
|
4812
5042
|
FRAME: 320, // 20 ms
|
|
@@ -4943,13 +5173,17 @@
|
|
|
4943
5173
|
const seconds = (frames.length * 0.02).toFixed(1);
|
|
4944
5174
|
let text = '';
|
|
4945
5175
|
try {
|
|
4946
|
-
|
|
5176
|
+
if (AI.asrProvider() === 'local') {
|
|
5177
|
+
const pcm = new Float32Array(frames.reduce((n, f) => n + f.length, 0));
|
|
5178
|
+
let o = 0; for (const f of frames) { pcm.set(f, o); o += f.length; }
|
|
5179
|
+
text = await LOCAL_WHISPER.transcribe(pcm, baseLang(TRANSLATOR._recognitionLanguage()));
|
|
5180
|
+
} else text = await AI.transcribe(this._wav(frames), { lang: baseLang(TRANSLATOR._recognitionLanguage()), prompt: [glossaryTerms().join(', '), TRANSLATOR._cloudPrompt].filter(Boolean).join('. '), signal: ctrl.signal });
|
|
4947
5181
|
this._failures = 0;
|
|
4948
5182
|
} catch (err) {
|
|
4949
5183
|
if (err?.name === 'AbortError' || !this.active) return;
|
|
4950
5184
|
this._failures++;
|
|
4951
5185
|
logDebug(`AI Sub: cloud speech recognition failed (${err.message}${err.detail ? ': ' + err.detail : ''}).`, 'warn');
|
|
4952
|
-
if (err.status === 401 || err.status === 403 || this._failures >= 4) TRANSLATOR.cloudAsrFailed(err);
|
|
5186
|
+
if (err.status === 401 || err.status === 403 || err.code === 'helper' || this._failures >= 4) TRANSLATOR.cloudAsrFailed(err);
|
|
4953
5187
|
} finally {
|
|
4954
5188
|
this._inflight.delete(ctrl);
|
|
4955
5189
|
}
|
|
@@ -7854,8 +8088,65 @@
|
|
|
7854
8088
|
}));
|
|
7855
8089
|
const positionSelect = createSelect('stt-position', [{ value: 'video', label: t('posVideo') }, { value: 'screen', label: t('posScreen') }]);
|
|
7856
8090
|
const asrSelect = createSelect('stt-asr-provider', [
|
|
7857
|
-
{ value: 'browser', label: t('asrBrowser') },
|
|
8091
|
+
{ value: 'browser', label: t('asrBrowser') },
|
|
8092
|
+
...(LOCAL_WHISPER.available() ? [{ value: 'local', label: t('asrLocal') }] : []),
|
|
8093
|
+
{ value: 'openai', label: t('asrOpenAI') },
|
|
7858
8094
|
{ value: 'openai-hq', label: t('asrOpenAIHQ') }, { value: 'groq', label: t('asrGroq') }]);
|
|
8095
|
+
// Offline Whisper: pick a model, download it once (explicitly), remove it again.
|
|
8096
|
+
const whisperBox = createEl('div', 'whisper-box');
|
|
8097
|
+
const whisperModel = createSelect('stt-whisper-model', Object.keys(LOCAL_WHISPER.MODELS).map(id => ({ value: id, label: t('whisperModel_' + id, { mb: LOCAL_WHISPER.MODELS[id].mb }) })));
|
|
8098
|
+
whisperModel.value = LOCAL_WHISPER.model();
|
|
8099
|
+
const whisperBtn = createEl('button', 'btn subtle', '', { type: 'button', id: 'nxu-whisper-btn' });
|
|
8100
|
+
const whisperDel = createEl('button', 'btn subtle', '🗑️ ' + t('whisperRemove'), { type: 'button', id: 'nxu-whisper-del' });
|
|
8101
|
+
const whisperInfo = createEl('div', 'trans-help', '', { id: 'nxu-whisper-info' });
|
|
8102
|
+
const whisperRow = createEl('div', 'nx-btn-row');
|
|
8103
|
+
whisperRow.append(whisperBtn, whisperDel);
|
|
8104
|
+
whisperBox.append(whisperModel, whisperRow, whisperInfo);
|
|
8105
|
+
const paintWhisper = async () => {
|
|
8106
|
+
const id = whisperModel.value;
|
|
8107
|
+
whisperBox.style.display = asrSelect.value === 'local' ? '' : 'none';
|
|
8108
|
+
if (asrSelect.value !== 'local') return;
|
|
8109
|
+
whisperBtn.disabled = true; whisperDel.style.display = 'none';
|
|
8110
|
+
whisperBtn.textContent = '⏳ ' + t('whisperChecking');
|
|
8111
|
+
try {
|
|
8112
|
+
const st = await LOCAL_WHISPER.status(id);
|
|
8113
|
+
STORE.set('nxu_whisper_ready_' + id, !!st.cached);
|
|
8114
|
+
if (!LOCAL_WHISPER.canRun(id)) { whisperBtn.textContent = '⚠️ ' + t('whisperNeedsGpu'); whisperInfo.textContent = t('whisperGpuHelp'); return; }
|
|
8115
|
+
whisperBtn.disabled = !!st.cached;
|
|
8116
|
+
whisperBtn.textContent = st.cached ? '✓ ' + t('whisperReady') : '⬇️ ' + t('whisperDownload', { mb: LOCAL_WHISPER.MODELS[id].mb });
|
|
8117
|
+
whisperDel.style.display = st.cached ? '' : 'none';
|
|
8118
|
+
whisperInfo.textContent = t(st.cached ? 'whisperReadyHelp' : 'whisperHelp');
|
|
8119
|
+
} catch (err) {
|
|
8120
|
+
whisperBtn.textContent = '⚠️ ' + t('whisperBlocked');
|
|
8121
|
+
whisperInfo.textContent = t('whisperBlockedHelp');
|
|
8122
|
+
}
|
|
8123
|
+
};
|
|
8124
|
+
whisperModel.addEventListener('change', () => { STORE.set('nxu_whisper_model', whisperModel.value); paintWhisper(); if (AI.asrProvider() === 'local') TRANSLATOR.restart('whisper model changed'); });
|
|
8125
|
+
whisperBtn.onclick = async (ev) => {
|
|
8126
|
+
ev.stopPropagation();
|
|
8127
|
+
const id = whisperModel.value;
|
|
8128
|
+
whisperBtn.disabled = true;
|
|
8129
|
+
whisperBtn.textContent = '⬇️ 0%';
|
|
8130
|
+
whisperInfo.textContent = t('whisperDownloading');
|
|
8131
|
+
try {
|
|
8132
|
+
await LOCAL_WHISPER.load(id, (f) => { whisperBtn.textContent = '⬇️ ' + Math.round(f * 100) + '%'; });
|
|
8133
|
+
STORE.set('nxu_whisper_ready_' + id, true);
|
|
8134
|
+
showToast('✓ ' + t('whisperDone'));
|
|
8135
|
+
logDebug('Offline Whisper (' + id + ') downloaded and ready.', 'success');
|
|
8136
|
+
if (TRANSLATOR.active) TRANSLATOR.restart('whisper ready');
|
|
8137
|
+
} catch (err) {
|
|
8138
|
+
logDebug('Offline Whisper download failed: ' + err.message, 'error');
|
|
8139
|
+
showToast('⚠️ ' + t('whisperFailed'));
|
|
8140
|
+
}
|
|
8141
|
+
paintWhisper();
|
|
8142
|
+
};
|
|
8143
|
+
whisperDel.onclick = async (ev) => {
|
|
8144
|
+
ev.stopPropagation();
|
|
8145
|
+
try { await LOCAL_WHISPER.remove(whisperModel.value); } catch (_) { }
|
|
8146
|
+
STORE.set('nxu_whisper_ready_' + whisperModel.value, false);
|
|
8147
|
+
if (AI.asrProvider() !== 'local' && TRANSLATOR.active) TRANSLATOR.restart('whisper removed');
|
|
8148
|
+
paintWhisper();
|
|
8149
|
+
};
|
|
7859
8150
|
const providerSelect = createSelect('stt-translation-provider', [
|
|
7860
8151
|
{ value: 'auto', label: t('providerAuto') }, { value: 'anthropic', label: t('providerClaude') }, { value: 'openai', label: t('providerGPT') },
|
|
7861
8152
|
{ value: 'deepl', label: t('providerDeepL') }, { value: 'device', label: t('providerDevice') }, { value: 'google', label: t('providerGoogle') }, { value: 'browser', label: t('providerBrowser') }]);
|
|
@@ -7940,7 +8231,7 @@
|
|
|
7940
8231
|
const offlineBtn = createEl('button', 'btn subtle', '⬇️ ' + t('offlineDownload'));
|
|
7941
8232
|
offlineBtn.onclick = () => TRANSLATOR.downloadOfflineModels();
|
|
7942
8233
|
advanced.append(label(t('translationEngine')), providerSelect, engineHint,
|
|
7943
|
-
label(t('asrEngine')), asrSelect,
|
|
8234
|
+
label(t('asrEngine')), asrSelect, whisperBox,
|
|
7944
8235
|
label(t('subPosition')), positionSelect,
|
|
7945
8236
|
label(t('glossary')), glossaryInput, help(t('glossaryHelp')), label(t('aiKeys')), keyRows, help(t('aiKeysHelp')), modelRow('anthropic', 'claude-haiku-4-5'), modelRow('openai', 'gpt-4.1-mini'),
|
|
7946
8237
|
help(t('modelHelp')), localRow, help(t('localFirstHelp')), offlineBtn, help(t('offlineHelp')));
|
|
@@ -7964,6 +8255,8 @@
|
|
|
7964
8255
|
positionSelect.value = STORE.get('nxu_sub_position', 'video');
|
|
7965
8256
|
providerSelect.value = STORE.get('nxu_translation_provider', 'auto');
|
|
7966
8257
|
asrSelect.value = STORE.get('nxu_asr_provider', 'browser');
|
|
8258
|
+
if (!asrSelect.value) asrSelect.value = 'browser';
|
|
8259
|
+
paintWhisper();
|
|
7967
8260
|
refreshEngineHint();
|
|
7968
8261
|
localCheck.checked = STORE.get('nxu_stt_local_first', true) !== false;
|
|
7969
8262
|
sizeSlider.value = SUB_PREFS.size; sizeVal.textContent = SUB_PREFS.size + 'px';
|
|
@@ -7978,7 +8271,7 @@
|
|
|
7978
8271
|
});
|
|
7979
8272
|
positionSelect.addEventListener('change', () => { STORE.set('nxu_sub_position', positionSelect.value); SUB_LAYOUT.schedule(); });
|
|
7980
8273
|
providerSelect.addEventListener('change', () => { STORE.set('nxu_translation_provider', providerSelect.value); TRANSLATOR._cache.clear(); TRANSLATOR._llmHistory = []; refreshEngineHint(); });
|
|
7981
|
-
asrSelect.addEventListener('change', () => { STORE.set('nxu_asr_provider', asrSelect.value); refreshEngineHint(); TRANSLATOR.restart('recognition engine changed'); });
|
|
8274
|
+
asrSelect.addEventListener('change', () => { STORE.set('nxu_asr_provider', asrSelect.value); refreshEngineHint(); paintWhisper(); TRANSLATOR.restart('recognition engine changed'); });
|
|
7982
8275
|
localCheck.addEventListener('change', () => STORE.set('nxu_stt_local_first', !!localCheck.checked));
|
|
7983
8276
|
sizeSlider.addEventListener('input', () => {
|
|
7984
8277
|
STORE.set('nxu_sub_size', +sizeSlider.value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kangsicj/nexussync",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
4
4
|
"description": "Watch-together userscript: media sync, cinema mode, live AI subtitles, chat bubbles and quick ink for Violentmonkey, Tampermonkey and iOS Userscripts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"userscript",
|