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:
@@ -0,0 +1,49 @@
|
||||
"""Label who speaks (CPU, sherpa-onnx): run(name) -> out/<name>.spk.txt, diar_segments.json, DB lines."""
|
||||
import json, re, subprocess
|
||||
from pathlib import Path
|
||||
import numpy as np
|
||||
import db
|
||||
|
||||
M = Path(__file__).parent / "models"
|
||||
|
||||
|
||||
def run(name, speakers=5, threshold=0.85):
|
||||
import sherpa_onnx
|
||||
src = db.out_dir(name) / "audio.opus"
|
||||
raw = subprocess.run(["ffmpeg", "-v", "error", "-i", str(src), "-vn", "-ac", "1", "-ar", "16000", "-f", "f32le", "-"],
|
||||
capture_output=True, check=True).stdout
|
||||
audio = np.frombuffer(raw, np.float32)
|
||||
sd = sherpa_onnx.OfflineSpeakerDiarization(sherpa_onnx.OfflineSpeakerDiarizationConfig(
|
||||
segmentation=sherpa_onnx.OfflineSpeakerSegmentationModelConfig(
|
||||
pyannote=sherpa_onnx.OfflineSpeakerSegmentationPyannoteModelConfig(model=str(M / "sherpa-onnx-pyannote-segmentation-3-0/model.onnx"))),
|
||||
embedding=sherpa_onnx.SpeakerEmbeddingExtractorConfig(model=str(M / "emb.onnx")),
|
||||
clustering=sherpa_onnx.FastClusteringConfig(num_clusters=speakers, threshold=threshold),
|
||||
min_duration_on=0.3, min_duration_off=0.5))
|
||||
segs = [(s.start, s.end, s.speaker) for s in sd.process(audio).sort_by_start_time()]
|
||||
print(len(segs), "segments,", len({s[2] for s in segs}), "speakers", flush=True)
|
||||
|
||||
lines = []
|
||||
for l in (db.OUT / f"{name}.txt").read_text(encoding="utf-8").splitlines():
|
||||
m = re.match(r"\[(\d+):(\d+)\] (.*)", l)
|
||||
if m: lines.append((int(m[1]) * 60 + int(m[2]), m[3]))
|
||||
out, order = [], {}
|
||||
for i, (t, text) in enumerate(lines):
|
||||
t1 = lines[i + 1][0] if i + 1 < len(lines) else t + 5
|
||||
ov = {}
|
||||
for s, e, sp in segs:
|
||||
o = min(e, t1) - max(s, t)
|
||||
if o > 0: ov[sp] = ov.get(sp, 0) + o
|
||||
sp = max(ov, key=ov.get) if ov else None
|
||||
if sp is not None: order.setdefault(sp, len(order) + 1)
|
||||
if out and out[-1][1] == sp: out[-1][2] += " " + text # same speaker continues: one paragraph
|
||||
else: out.append([t, sp, text])
|
||||
# labels by first appearance in the text; clusters never seen in text get the following numbers
|
||||
for s in sorted(segs):
|
||||
order.setdefault(s[2], len(order) + 1)
|
||||
(db.OUT / f"{name}.spk.txt").write_text("\n".join(
|
||||
f"[{t//60:02d}:{t%60:02d}] " + (f"Speaker {order[sp]}: " if sp is not None else "") + text for t, sp, text in out), encoding="utf-8")
|
||||
(db.out_dir(name) / "diar_segments.json").write_text(json.dumps(
|
||||
[{"start": s, "end": e, "label": f"Speaker {order[sp]}"} for s, e, sp in segs]), encoding="utf-8")
|
||||
db.replace_lines(name, [(t, f"Speaker {order[sp]}" if sp is not None else None, text) for t, sp, text in out])
|
||||
db.upsert_recording(name, speakers=len({sp for _, sp, _ in out if sp is not None}))
|
||||
print("saved", db.OUT / f"{name}.spk.txt")
|
||||
Reference in New Issue
Block a user