Add Pinokio launcher for Teams meeting report pipeline

Pipeline code copied into app/; llama.py now uses launcher-local
llama.cpp (app/bin) and Qwen GGUF (app/models) instead of LM Studio.
install.js fetches ffmpeg, 7zip, llama.cpp CUDA 13, sherpa-onnx
diarization models, bge-m3 and Qwen3.6-35B-A3B, then pre-builds the
uv script environments. start.js serves the GUI on fixed port 18765
(hardcoded in the browser extension). reset.js keeps app/out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pinokio
2026-10-30 21:29:33 +01:00
co-authored by Claude Opus 5.5
commit 4ff3e6fe14
31 changed files with 2366 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
{
"manifest_version": 3,
"name": "Teams Whisper Recorder",
"version": "1.1",
"description": "Record Teams tab audio+video (+mic) and transcribe with local whisper server",
"permissions": ["tabCapture", "offscreen", "activeTab", "tabs"],
"host_permissions": ["http://127.0.0.1:18765/*"],
"content_scripts": [{ "matches": ["https://teams.cloud.microsoft/*", "https://teams.microsoft.com/*"], "js": ["teams.js"], "run_at": "document_idle" }],
"action": { "default_popup": "popup.html" }
}
+2
View File
@@ -0,0 +1,2 @@
<body>Allow the microphone, then close this tab.
<script src="mic.js"></script>
+3
View File
@@ -0,0 +1,3 @@
navigator.mediaDevices.getUserMedia({ audio: true })
.then(s => { s.getTracks().forEach(t => t.stop()); document.body.append(" granted."); })
.catch(e => document.body.append(" " + e));
+1
View File
@@ -0,0 +1 @@
<script src="offscreen.js"></script>
+57
View File
@@ -0,0 +1,57 @@
const API = "http://127.0.0.1:18765";
let rec, ctx, tab, mic, q = Promise.resolve(), name;
// state: idle | recording | transcribing | done | error ; popup polls it
const S = { state: "idle", name: "", t0: 0, t1: 0, chunks: 0, mic: false, text: "" };
chrome.runtime.onMessage.addListener((m, _s, send) => {
if (m.to !== "off") return;
if (m.cmd === "status") send(S);
if (m.cmd === "start") start(m.id, m.tabId).then(() => send({ ok: true }), e => { S.state = "error"; S.text = String(e); send({ err: String(e) }); });
if (m.cmd === "events") { for (const e of m.events) if (e.ts >= S.t0) S.ev.push({ t: (e.ts - S.t0) / 1000, kind: e.kind, who_key: e.who_key, who: e.who, text: e.text }); }
if (m.cmd === "stop") { rec.stop(); send({ ok: true }); }
return true;
});
async function flushEv() {
if (!S.ev.length) return;
const b = S.ev.splice(0);
try {
const r = await fetch(`${API}/events?name=${name}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(b) });
if (!r.ok) throw 0;
S.evSent += b.length;
} catch { S.failed++; }
}
async function start(id, tabId) {
name = "teams_" + new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
const src = { mandatory: { chromeMediaSource: "tab", chromeMediaSourceId: id } };
tab = await navigator.mediaDevices.getUserMedia({ audio: src, video: src });
ctx = new AudioContext();
const dest = ctx.createMediaStreamDestination();
const t = ctx.createMediaStreamSource(tab);
t.connect(dest);
t.connect(ctx.destination); // tabCapture mutes the tab; play it back
try { // needs one-time grant via mic.html
mic = await navigator.mediaDevices.getUserMedia({ audio: true });
ctx.createMediaStreamSource(mic).connect(dest);
} catch { mic = null; }
const out = new MediaStream([...tab.getVideoTracks(), ...dest.stream.getAudioTracks()]);
rec = new MediaRecorder(out, { mimeType: "video/webm;codecs=vp8,opus", videoBitsPerSecond: 1e6 });
rec.ondataavailable = e => {
q = q.then(() => fetch(`${API}/chunk?name=${name}`, { method: "POST", body: e.data })).then(() => S.chunks++, () => S.failed++).then(flushEv);
};
rec.onstop = async () => {
S.state = "transcribing"; S.t1 = Date.now();
try {
await q;
await flushEv();
[tab, mic].forEach(s => s && s.getTracks().forEach(t => t.stop()));
ctx.close();
const r = await fetch(`${API}/stop?name=${name}`, { method: "POST" });
S.text = await r.text(); S.state = r.ok ? "done" : "error";
} catch (e) { S.text = "server down or failed: " + e; S.state = "error"; }
rec = null;
};
Object.assign(S, { state: "recording", name, t0: Date.now(), chunks: 0, failed: 0, mic: !!mic, text: "", ev: [], evSent: 0, tabId });
rec.start(10000);
}
+5
View File
@@ -0,0 +1,5 @@
<body style="width:380px;font:13px sans-serif">
<button id="go">Start</button> <a href="mic.html" target="_blank">grant mic (once)</a>
<div id="st"></div>
<pre id="txt" style="white-space:pre-wrap;max-height:300px;overflow:auto"></pre>
<script src="popup.js"></script>
+46
View File
@@ -0,0 +1,46 @@
const $ = id => document.getElementById(id);
const off = msg => chrome.runtime.sendMessage({ to: "off", ...msg });
const mmss = ms => { const s = Math.floor(ms / 1000); return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`; };
let S = { state: "idle" }, lastErr = "";
function render() {
const go = $("go"), st = $("st");
go.disabled = S.state === "transcribing";
go.textContent = S.state === "recording" ? "Stop + transcribe" : "Start";
st.textContent = {
idle: "idle - open a Teams tab and press Start",
recording: `REC ${mmss(Date.now() - S.t0)} | ${S.chunks} chunks uploaded${S.failed ? ` | ${S.failed} FAILED (server down?)` : ""} | mic ${S.mic ? "on" : "OFF (grant it)"} | eventi call: ${S.evSent || 0}`,
transcribing: `invio alla pipeline...`,
done: `inviato alla pipeline — stato e report su http://127.0.0.1:18765/`,
error: "ERROR (see below)",
}[S.state];
if (S.text) $("txt").textContent = S.text;
}
async function poll() {
if (await chrome.offscreen.hasDocument()) S = (await off({ cmd: "status" })) || S; else S = lastErr ? { state: "error", text: lastErr } : { state: "idle" };
render();
}
$("go").onclick = async () => {
if (S.state === "recording") {
if (S.tabId != null) await chrome.tabs.sendMessage(S.tabId, { cmd: "cap-stop" }).catch(() => {});
await new Promise(r => setTimeout(r, 300));
await off({ cmd: "stop" }); return poll();
}
lastErr = "";
try {
const [t] = await chrome.tabs.query({ active: true, currentWindow: true });
if (t.url?.startsWith("chrome-extension:")) throw new Error("This is the extension's own page. Switch to the Teams tab, then click the icon.");
const id = await chrome.tabCapture.getMediaStreamId({ targetTabId: t.id });
if (!(await chrome.offscreen.hasDocument()))
await chrome.offscreen.createDocument({ url: "offscreen.html", reasons: ["USER_MEDIA"], justification: "record tab" });
const r = await off({ cmd: "start", id, tabId: t.id });
if (r?.err) throw new Error(r.err);
chrome.tabs.sendMessage(t.id, { cmd: "cap-start" }).catch(() => {});
} catch (e) { lastErr = String(e); }
render(); poll();
};
poll(); setInterval(poll, 1000);
+108
View File
@@ -0,0 +1,108 @@
// Content script on Teams web: logs active speaker, shares, captions, chat, hands, presence while recording.
// Events go via the offscreen document (it has host_permissions for 127.0.0.1). Never clicks or types in the call.
const SEL = {
duration: '[data-tid="call-duration"]',
nametag: '[data-tid="participant-info-nametag"]',
info: '[data-tid="participant-info"]',
speaking: '[data-tid="voice-level-stream-outline"][data-is-speaking="true"]',
self: '[data-tid="myself-video"]',
shareAria: /^(Contenuto condiviso da|Content shared by) (.+)$/,
caption: null, captionAuthor: null, captionText: null, // discovery step (see plan 3b)
chatMsg: null, chatAuthor: null, chatText: null, // discovery step
hand: null, // discovery step
};
let buf = [], timers = [], seenCap = new WeakSet(), seenChat = new WeakSet(), lastShare = "", raised = new Set(), lastTitle = null;
const norm = raw => {
raw = (raw || "").trim();
const m = raw.match(/^([^,]+),\s*([^(]+?)\s*(\(.*)?$/);
if (!m) return raw;
return `${m[2]} ${m[1]}`.split(/\s+/).map(w => (w.length > 1 && w === w.toUpperCase() ? w[0] + w.slice(1).toLowerCase() : w)).join(" ");
};
const tileOf = el => { while (el && !el.querySelector(SEL.nametag)) el = el.parentElement; return el; };
const keyOf = tile => {
for (let e = tile; e; e = e.parentElement) if ((e.dataset?.tid || "").includes("@")) return e.dataset.tid;
return tile.querySelector(SEL.nametag)?.textContent.trim() || "";
};
const nameOf = tile => norm(tile.querySelector(SEL.nametag)?.textContent);
const selfName = () => { const s = document.querySelector(SEL.self); return s ? nameOf(s) : ""; };
const emit = (kind, who_key = "", who = "", text = "") => buf.push({ ts: Date.now(), kind, who_key, who, text });
const guard = f => () => { try { f(); } catch { } };
const send = () => { if (buf.length) chrome.runtime.sendMessage({ to: "off", cmd: "events", events: buf.splice(0) }).catch(() => { }); };
const tiles = () => [...document.querySelectorAll(SEL.nametag)].map(tileOf).filter(Boolean);
function meta() {
const title = document.title.replace(/^[^|]*\|\s*/, "").replace(/\s*\|\s*Microsoft Teams$/, "");
if (title === lastTitle) return;
lastTitle = title;
emit("meta", "", "", JSON.stringify({ title, call_elapsed: document.querySelector(SEL.duration)?.textContent.trim() || "", url: location.href }));
}
function present() {
const seen = new Map();
for (const t of tiles()) seen.set(keyOf(t), { key: keyOf(t), who: t.closest(SEL.self) ? selfName() : nameOf(t) });
emit("present", "", "", JSON.stringify([...seen.values()]));
}
function active() {
for (const el of document.querySelectorAll(SEL.speaking)) {
const t = tileOf(el); if (!t) continue;
if (t.closest(SEL.self) || t.matches(SEL.self)) emit("active", "self", selfName());
else emit("active", keyOf(t), nameOf(t));
}
}
function share() {
const names = tiles().map(nameOf);
let cur = "";
for (const el of document.querySelectorAll("[aria-label]")) {
const m = el.getAttribute("aria-label").match(SEL.shareAria);
if (m) { cur = names.find(n => n && m[2].startsWith(n)) || m[2]; break; }
}
if (cur === lastShare) return;
if (lastShare) emit("share_stop", "", lastShare);
if (cur) emit("share_start", "", cur);
lastShare = cur;
}
function messages() {
if (SEL.caption) for (const el of document.querySelectorAll(SEL.caption)) {
if (seenCap.has(el)) continue; seenCap.add(el);
const text = el.querySelector(SEL.captionText)?.textContent.trim();
if (text) emit("caption", "", norm(el.querySelector(SEL.captionAuthor)?.textContent), text);
}
if (SEL.chatMsg) for (const el of document.querySelectorAll(SEL.chatMsg)) {
if (seenChat.has(el)) continue; seenChat.add(el);
const text = el.querySelector(SEL.chatText)?.textContent.trim();
if (text) emit("chat", "", norm(el.querySelector(SEL.chatAuthor)?.textContent), text);
}
if (SEL.hand) {
const now = new Set();
for (const el of document.querySelectorAll(SEL.hand)) {
const t = tileOf(el); if (!t) continue;
const k = keyOf(t); now.add(k);
if (!raised.has(k)) emit("hand", k, nameOf(t));
}
raised = now;
}
}
function stop() {
timers.forEach(clearInterval); timers = [];
send();
if (lastShare) { emit("share_stop", "", lastShare); lastShare = ""; }
send();
}
function start() {
stop();
buf = []; seenCap = new WeakSet(); seenChat = new WeakSet(); raised = new Set(); lastTitle = null; lastShare = "";
meta(); present();
timers = [
setInterval(guard(() => { meta(); active(); }), 500),
setInterval(guard(() => { share(); messages(); }), 1000),
setInterval(guard(present), 30000),
setInterval(guard(send), 5000),
];
}
chrome.runtime.onMessage.addListener(m => {
if (m.cmd === "cap-start") start();
if (m.cmd === "cap-stop") stop();
});