Skip to content

feat(memos): speaker sampling and per-label embeddings - #1562

Merged
hrustalq merged 2 commits into
devfrom
feat/1561-speaker-sampling
Dec 3, 2026
Merged

hrustalq merged 2 commits into
devfrom
feat/1561-speaker-sampling

Conversation

@hrustalq

@hrustalq hrustalq commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Closes #1561
Refs #1404
Refs #1400

What

The first half of phase 3's matching, shipped dark: a diarized label's cleanest turns become one 192-d embedding. No comparison, no speaker_matches write, no route, no processor change — 3.2 injects the sampler and 3.3 owns the precedence.

Why a library and not a pipeline. The issue cuts phase 3 into four sessions: 3.1 samples and embeds, 3.2 compares and writes, 3.3 makes resolveSpeakers read the matches, 3.4 adds usage and cross-workspace tests. Wiring the sampler into memos.processor.ts now would ship a worker that computes vectors nobody reads, so this PR ships the two pieces 3.2 needs and proves them alone: planSpeakerSamples (pure) and SpeakerSamplingService.sample (cut + embed), provided and exported by VoiceEmbeddingModule, the module a worker-side matching service will import.

The floor and the caps, with their sources. SPEAKER_MIN_SECONDS defaults to 3: the doc names the key but deliberately fixes no value ("the least voiced audio a label needs before it may be compared at all — not a decision line"), and 3 s matches the 3–10 s turns its real-call paragraph describes; phase 5 re-measures real recordings and may move it, which is why the key is env. The sample cap is SPEAKER_SAMPLE_SECONDS = 20 — every probe clip the model was measured on is 20.000 s (§ Chosen model) — and SPEAKER_SAMPLE_MAX_TURNS = 8 bounds the ffmpeg calls. Both are constants, not env: another value would silently change what the model sees.

Range cuts, not a whole-file decode. A memo may be MEMO_MAX_MINUTES (120 min); decoding it would hold ~460 MB of float32 and time out the worker. The sampler cuts each planned range with its own ffmpeg -ss … -t … into a throwaway f32le file at 16 kHz mono, joins the label's ranges in time order, and removes every temp directory on every path. The plan bounds the work at 20 s and eight cuts per label.

A skip is not a failure; a missing model is. A cut that fails, or comes back shorter than the transcript claimed (concatenated PCM under minSeconds × 16000), leaves that label out of the result — it stays unknown, which is the doc's fallback — and one bad label never costs the others. But a missing artifact (available() false) or a failing graph throws: a zero vector would count as a match, and a wrong name is worse than "Speaker 2". voicedSeconds is the planned total (what 3.4 bills and the floor was checked against), never the decoded sample count.

The env group. SPEAKER_ files under memos in the env report beside VOICE_, and the spec pins it: the console's "no key under other" assertion fails otherwise. It is the same feature's knob — a talk about voices in recordings is a memo.

The gated cosines. The real case runs only where ~/.hermes/artifacts/voice-1557/ exists (CI has no artifact). Locally, three 20 s clips each planned as two "Speaker 1" turns gave one 192-d unit vector each, and:

pair cosine
ru_milena_a × ru_milena_b (same speaker) 0.9638
ru_milena_a × ru_chulsky_a (different) 0.1152
ru_milena_b × ru_chulsky_a (different) 0.1021

CI's skip line: the artifact directory is absent on the runner, so describe.skipIf reports the gated case as skipped there and the pure and fake-cut cases carry the gate; locally it ran and printed the cosines above.

Acceptance criteria (3.1)

criterion status evidence
Two labels above the floor plan, the short one absent met planSpeakerSamples (#1561) > plans every label above the floor and leaves a short one out
Each plan takes longest turns up to 20 s, no overlapping or out-of-range cuts met takes the longest turns up to the cap and returns them in time order, trims the turn that reaches the cap, never plans two ranges over the same second
On the probe artifacts each label yields one 192-d unit vector, and one speaker is closer than another met locally; skipped on CI gated the real artifact (#1561); cosines above
A label whose audio cannot be decoded is skipped, not fatal; no matching or writes in this session met skips a label whose decoded audio is under the floor, skips the label whose cut fails; diff touches no processor, schema, route or speaker_matches
make verify met exit 0; 356 passed (356) files, `5544 passed

What 3.2 inherits

  • SpeakerSamplingService.sample(file, segments): Promise<SpeakerSample[]> — one { label, embedding, voicedSeconds } per surviving label, in first-speech order.
  • SpeakerSample and the pure planSpeakerSamples, both exported from speaker-sampling.ts.
  • SPEAKER_MIN_SECONDS (env, default 3), read by the service; no caller exists until 3.2 wires it.
  • The skip/throw split 3.2 must keep: a skipped label has no sample, so the matcher must not invent a match for it.

No schema, migration, enum, route, graph call, processor change, resolveSpeakers change or UI.

Review

Independent review before opening this PR (spec + work, fresh context): three slices over the committed range, then two spec slices over the test file, then one delta review over the fix.

  • Fixed: the first-speech-order case used two turns starting at 0, so it could not tell time order from input order → da9c488d orders labels by their earliest start and lists a later turn first.
  • Rejected: none.
  • Deferred: none.

Mutation checks (each flip restores the file to the same SHA): shortest-first choice reddens takes the longest turns up to the cap; floor-by-span reddens measures the floor by the sum; removing the short-PCM skip reddens skips a label whose decoded audio is under the floor; removing the time-order sort reddens joins a label's cuts in time order; label order by input reddens keeps labels in the order they first speak.

The planner and service phase 3.2 consumes: plan each diarized label's cleanest turns, cut only those ranges with ffmpeg, and embed one 192-d vector per label. Shipped dark: no comparison, no speaker_matches write, no route.

SPEAKER_MIN_SECONDS (default 3) is the sampling floor; no caller reads it until 3.2.

Refs #1561
…rder

The review found the first-speech case used equal starts, so it could not tell time order from input order. Labels are now sorted by their earliest start, and the case lists a later turn first so input order would answer the wrong label.

Refs #1561
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant