Skip to content

Add optional speaker labeling (diarization) to file transcription - #378

Merged
altic-dev merged 10 commits into
altic-dev:mainfrom
postoso:feat/file-transcription-speaker-labels
Aug 5, 2026
Merged

altic-dev merged 10 commits into
altic-dev:mainfrom
postoso:feat/file-transcription-speaker-labels

Conversation

@postoso

@postoso postoso commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds optional offline speaker labeling to file transcription, following the accepted direction in #18.

  • Adds a "Label speakers" toggle and optional expected speaker count.
  • Uses FluidAudio diarization, then transcribes each speaker turn with the active provider.
  • Carries speaker labels and timestamps through results, history, copy, and text/JSON export.
  • Keeps existing history and settings backups backward compatible.
  • Uses the shared stereo downmixer so speech on the right channel is not discarded.
  • Falls back to the normal transcript with a visible notice if labeling fails.
  • Disables speaker labeling for video containers, which the diarizer cannot read directly.

Type of Change

  • 🐞 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 🧹 Chore
  • 📝 Documentation update

Related Issue or Discussion

Addresses #18.

Testing

  • Tested on Intel Mac
  • Tested on Apple Silicon Mac
  • Tested on macOS version: 15.7.7
  • Ran linter locally: swiftlint --strict --config .swiftlint.yml Sources
  • Ran formatter locally: swiftformat --config .swiftformat Sources
  • Ran tests locally: 15 focused downmix/resampling, speaker-turn, and timestamp-formatting tests pass. The CI-equivalent suite completed 162 tests successfully; 11 unrelated automatic-dictionary and microphone-coordinator tests aborted in the local app host.

Screenshots / Video

Speaker-label controls

File transcription speaker-label controls

Speaker-labeled result

Speaker-labeled transcription result

Progress state

Speaker identification progress

Notes

Speaker diarization runs locally and downloads its FluidAudio models on first use. Live dictation diarization remains out of scope.

The rebase, stereo fix, merge tests, and screenshots were contributed by @Erik5000. The original feature commits retain their original authorship.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f20929f1f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +531 to +535
samples = try self.readSamples(
from: audioFile,
startSeconds: turn.startSeconds,
endSeconds: turn.endSeconds,
minimumDurationSeconds: 1.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split overlong diarized turns before ASR

When a diarized turn spans a long monologue or single-speaker section, this path reads turn.startSeconds...turn.endSeconds into one sample array and sends it to provider.transcribe as a single request. The standard file path explicitly chunks at 20 minutes to avoid model/input and memory limits, but the diarized path only limits merging adjacent turns and never splits an individual long turn; if that ASR call fails, the segment is skipped and a partial transcript can still be returned. Split speaker turns into the same bounded chunks before reading/transcribing them.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f20929f1f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +531 to +535
samples = try self.readSamples(
from: audioFile,
startSeconds: turn.startSeconds,
endSeconds: turn.endSeconds,
minimumDurationSeconds: 1.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Split overlong diarized turns before ASR

When a diarized turn spans a long monologue or single-speaker section, this path reads turn.startSeconds...turn.endSeconds into one sample array and sends it to provider.transcribe as a single request. The standard file path explicitly chunks at 20 minutes to avoid model/input and memory limits, but the diarized path only limits merging adjacent turns and never splits an individual long turn; if that ASR call fails, the segment is skipped and a partial transcript can still be returned. Split speaker turns into the same bounded chunks before reading/transcribing them.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2f1b8b831

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +669 to +673
if end - start < minimumDurationSeconds {
let deficit = minimumDurationSeconds - (end - start)
start = max(0, start - deficit / 2)
end = min(fileDurationSeconds, start + minimumDurationSeconds)
start = max(0, end - minimumDurationSeconds)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid expanding short speaker turns into neighbors

When the diarizer emits a turn shorter than 1.1s adjacent to another speaker, this widens the audio window before/after the turn rather than padding with silence. The resulting samples can include neighboring speech, but the transcript is still stored under the original turn.speakerLabel, so short back-and-forth sections can duplicate words or attribute them to the wrong speaker even though the diarizer boundaries were correct.

Useful? React with 👍 / 👎.

@postoso
postoso force-pushed the feat/file-transcription-speaker-labels branch from 13ae2da to e49cdd9 Compare June 19, 2026 02:58

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e49cdd92da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@postoso

postoso commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 1.6.0. No conflicts, the diarization changes are unchanged. xcodebuild and swiftlint --strict both pass. Ready to pull.

postoso and others added 5 commits August 2, 2026 18:40
Adds a "Label speakers" toggle to File Transcription that attributes
the transcript to "Speaker 1", "Speaker 2", ... using the offline
diarizer already present in the FluidAudio dependency (no new deps).

- Diarize-first pipeline: identify speaker turns via the memory-mapped
  offline diarizer, then transcribe each turn's audio slice with the
  active provider - works with any TranscriptionProvider since it only
  needs transcribe(samples)
- Optional "Number of speakers" hint (Auto/2-8) feeds the diarizer's
  clustering constraints for better accuracy when the count is known
- Speaker-labeled segments with timestamps in the results view; labeled
  text flows to copy/history/text export; JSON export gains structured
  segments (backward-compatible decoding for existing history)
- Diarizer CoreML models auto-download on first use via FluidAudio's
  own download flow
- Any diarization failure falls back to the standard transcription
  paths, so baseline behavior is never at risk
- arch(arm64)-gated like FluidAudioProvider; the toggle is hidden on
  Intel where FluidAudio is unavailable

Addresses altic-dev#18 (file transcription scope; live dictation out of scope).

Co-Authored-By: Claude Fable 5 <[email protected]>
Addresses Codex review findings on the speaker-labeling path:

- Fall back to full-file transcription on any per-turn read/ASR
  failure instead of returning a transcript with silent gaps - a
  failed slice no longer leaves a hole while other slices succeed,
  preserving the "baseline behavior is never at risk" guarantee.
- Split overlong speaker turns into 20-minute chunks before ASR
  (mirrors the standard path), so a long single-speaker stretch
  never exceeds the model input limit.
- Persist speakerSegments in file transcription history so labeled
  transcripts keep their structured speaker/timestamp data across
  navigation and restart, and JSON export from history includes the
  segments (backward-compatible decoding for existing entries).
- Include the new speaker-labeling settings keys in the settings
  backup payload so Export/Import no longer drops them.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Addresses Codex review: widening a sub-minimum speaker turn's audio
window pulled in neighboring speech, so a short turn could absorb an
adjacent speaker's words (duplication / wrong attribution) even when
the diarizer boundaries were correct. Read only the turn's own audio
and pad with trailing silence to the ASR input minimum, keeping each
segment single-speaker.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The speaker-labeled path added a second, subtly different copy of the resampling
helper. It built its own AVAudioConverter and never set `downmix`, so a
multi-channel source was channel-mapped rather than mixed: only the left channel
reached the ASR and the right one was silently dropped.

The standard file-transcription path in this same file already calls
AudioBufferConverter.monoSamples, which sets `downmix` and has tests. The copy is
deleted and the call delegated there — 75 lines removed, no new behaviour.

Verified by feeding a stereo file with different speech on each channel: before
the fix the transcript held only the left channel, and swapping the channels
swapped the output. After it, both orderings produce identical output, which is
what mixing means. Stereo sources are common — in one real-world archive of 164
recordings, 72 were stereo.

Mixing is the right default over dropping half the content, but it does destroy an
exact separation when the channels genuinely hold different speakers. That case is
worth surfacing to the user later; silently transcribing half the file is not.

Also adds SpeakerTurnMergingTests, which pins down mergeAdjacentTurns: same-speaker
merging across short gaps, the gap boundary, the 20-minute cap, and the consequence
that matters — when clustering collapses to one label, the merge welds question and
answer into a single segment.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Only the lines this branch introduces: the SpeakerTranscriptSegment id property,
the speaker-count Picker range, and the two new files. The pre-existing violations
in these files are left alone so the diff stays about diarization.

swiftlint --strict reports no violations; swiftformat now flags exactly the 15
findings main already had.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Erik5000

Erik5000 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I've been running this branch against real recordings and wanted to share two things: a defect I found, and an offer.

The speaker-labeled path discards the right channel of stereo files

MeetingTranscriptionService gained its own resampleBuffer helper in this PR. It builds an AVAudioConverter but never sets converter.downmix, so a multi-channel source is channel-mapped rather than mixed — only the left channel reaches the ASR, and the right one is dropped silently.

What makes it easy to miss: the standard file-transcription path in the same file already calls AudioBufferConverter.monoSamples, which does set downmix and is covered by existing tests (testStereoDownmixIncludesRightChannel, testStereoDownmixAndResampleIncludesRightChannel). So only the "Label speakers" path is affected, which is why it doesn't show up in normal use.

I found it by feeding a stereo file with different speech on each channel: the transcript held only the left channel, and swapping the channels swapped the output. Stereo is common enough to matter — in my own archive, 72 of 164 recordings are stereo.

The fix is to delete the local copy and delegate to AudioBufferConverter.monoSamples. That removes 75 lines and adds no new behaviour.

One tradeoff worth stating: mixing is the right default over dropping half the content, but it destroys an exact separation when the channels genuinely hold different speakers. Surfacing that to the user is worth doing separately — silently transcribing half the file is not.

The offer

The branch has drifted: main is on 1.6.6 now and GitHub reports this PR as conflicting. I've already rebased your three commits onto current main with authorship preserved (one conflict, in MeetingTranscriptionService.swift, resolved toward main's current structure — no behavioural change), applied the stereo fix on top, and added tests for mergeAdjacentTurns.

Branch: https://github.com/Erik5000/FluidVoice/tree/diarization-rebased
Compare: main...Erik5000:FluidVoice:diarization-rebased

swiftlint --strict reports no violations and the full suite passes at 174 tests locally.

It's your PR, so it's your call. Happy to:

  • push the rebased branch to your fork, if you'd rather keep it here, or
  • open it as a separate PR crediting you as the author of the original commits, or
  • just hand you the patch and stay out of the way.

Whichever you prefer — I mainly want the feature to land.

@altic-dev this is anchored to #18 if it helps with triage.

Placed in .github/screenshots/ alongside the existing ones, so the PR body can
reference them by raw URL and they survive independently of a comment.

Captured against this branch with an 80-second public-domain excerpt from a
LibriVox dramatic reading — deliberately not a real recording, since a screenshot
publishes whatever words are on screen.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@postoso
postoso force-pushed the feat/file-transcription-speaker-labels branch from c1a7bf0 to b040f06 Compare August 3, 2026 22:30
@postoso

postoso commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @Erik5000. I updated this PR from your rebased branch, preserving the three original commits' authorship and your follow-up commits. The update keeps your stereo downmix fix, merge tests, formatting, and screenshots.

I also disabled speaker labeling for video containers, added a visible notice and progress reset when audio diarization falls back, preserved timestamps in copied/history/exported text, and made the shared audio converter explicitly nonisolated. For the provider-window review feedback, Cohere and Nemotron already split long input internally at energy-aware boundaries, so the outer 20-minute speaker-turn split remains a memory bound instead of adding hard model-window cuts.

Validated with strict SwiftLint and 15 focused downmix, resampling, speaker-turn, and timestamp-formatting tests. The PR is now rebased on current main, mergeable, and running the full GitHub checks.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

The PR adds optional offline speaker labeling to file transcription, preserving speaker metadata through history and export while falling back to ordinary transcription when labeling cannot produce a complete result.

  • Adds diarization settings and speaker-label controls.
  • Transcribes diarized speaker turns through the active provider.
  • Persists speaker segments with backward-compatible history and backup decoding.
  • Uses the shared stereo-aware audio conversion path.

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported empty-turn and empty-chunk paths now both abort labeled transcription and continue through the complete standard transcription path without saving partial speaker segments, so no blocking failure remains.

Reviews (4): Last reviewed commit: "feat: include timestamps in labeled text" | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a844cb9759

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

let labeledText = segments
.map { "\($0.speaker): \($0.text)" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include timestamps in labeled plain text

When a speaker-labeled result is copied, viewed from history, or exported as .txt, those paths consume result.text, but this mapping records only the speaker and transcript. Consequently, the timestamps shown in the result UI and retained in speakerSegments disappear from these outputs, so users cannot preserve the displayed chronology outside the app; include each segment's timestamp here or format speakerSegments in those output paths.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ea5941. Speaker segment formatting now owns a shared timestamp representation, labeled plain text includes that timestamp, and the result UI reuses the same formatter. Copy, history text, and text export therefore preserve the displayed chronology. Added focused minute and hour formatting tests.

@altic-dev altic-dev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diarization pipeline, provider chunking, audio slicing/downmix, fallback behavior, persistence/backward compatibility, export, and future meeting-transcription fit. This is a sound offline file-transcription foundation. All required checks are green.

@altic-dev
altic-dev merged commit 8d140fc into altic-dev:main Aug 5, 2026
7 checks passed
@postoso
postoso deleted the feat/file-transcription-speaker-labels branch October 5, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants