Skip to content

Improve core audio resiliency - #732

Merged
grohith327 merged 3 commits into
mainfrom
rohith/709-enable-core-audio
Jul 31, 2026
Merged

grohith327 merged 3 commits into
mainfrom
rohith/709-enable-core-audio

Conversation

@grohith327

Copy link
Copy Markdown
Collaborator

Description

So this is a huge PR, it touches upon a few things but the core problem this PR attempts to solve is to improve the resiliency of the core audio transcription pipeline. AVAudioEngine has been very problematic and CoreAudio is currently experimental, not well tested out but much faster. The changes part of this PR are highlighted below including the reasoning

  • Enables the core audio ASR processing flow as the default one - AVAudioEngine has been causing a lot of headaches - [BUG] FluidVoice 1.6.5 hangs when switching between a preferred microphone and AirPods #709, [BUG] recent update stopped it working #680 etc. CoreAudio is also the one we want to move to eventually
  • Remove the duration mismatch fallback - this logic itself was flawed in a sense that it starts the timer when the hotkey is pressed, there has been cases where the MacOS is binding the new bluetooth input device (300-400 ms) and such cases we have no control. So the mismatch logic incorrectly assumes that the audio speed up happened and toggles it back to AVAudioEngine
  • Now, the fallback itself was added because the audio was sped up certain times. I could not reproduce this but it should be fixed, what was likely happening was that the when CoreAudio was sharing the channels and sample rate, when we resampled to 16 kHZ we did not respect those values. E.g. Audio starts at 48 kHz and switches to 24 for some reason, this will come through from CA but when we downsample - we didn't respect it. Resulting in the audio "sped up"
  • AVAudioEngine fallback is exercised only if the core audio setup fails, so the toggle is the source of truth
  • Core audio lifecycle is managed off main thread, therefore during binding/draining you don't see a beach ball on the app
  • Hardened the Core audio integration to be more resilient to faster device switches, or drop in device etc.

Type of Change

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

Related Issue or Discussion

#709, #680

Testing

  • Tested on Apple Silicon Mac
  • Tested on macOS version: 27
  • Ran linter locally: swiftlint --strict --config .swiftlint.yml Sources

Test cases

Tested out a few different use-cases across different audio input devices, constant changes, removal/additions of devices (mainly bluetooth) in order ensure that the transcription works

Screenshots / Video

CleanShot 2026-07-28 at 21 08 12@2x

Notes

Add reviewer context, rollout notes, or known tradeoffs here.

Comment thread Sources/Fluid/Services/ASRService.swift Resolved
@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR makes Direct Core Audio the default capture path and hardens its startup, readiness, device-change, and teardown lifecycle.

  • Adds first-PCM readiness gating and bounded same-backend startup retries.
  • Detects Core Audio format changes and serializes route recovery off the main thread.
  • Updates packet publication, resampling, device observation, shutdown, and diagnostic logging.
  • Preserves AVAudioEngine as the explicitly selected path when faster recording is disabled.
  • Adds integration coverage for capture readiness, lifecycle serialization, teardown failures, and persisted preferences.

Confidence Score: 5/5

The PR appears safe to merge with no eligible or outstanding failure identified.

No blocking failure remains; the previously reported absence of an automatic AVAudioEngine fallback matches the maintainer-confirmed intent to retry the primary Core Audio pipeline.

Reviews (2): Last reviewed commit: "big update" | 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: 250f8bfbbe

ℹ️ 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 thread Sources/Fluid/Services/ASRService.swift Resolved
Comment on lines +462 to 465
// Close publication before synchronizing with the IOProc. The consumer
// still drains every packet already committed to the ring.
atomic_store_explicit(&capture->packetGateOpen, false, memory_order_release);
OSStatus status = AudioDeviceStop(capture->deviceID, capture->ioProcID);

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 Keep accepting timestamped packets until the IOProc stops

When stop races the next hardware callback, closing packetGateOpen before AudioDeviceStop causes that callback to return without publishing even if its timestamped buffer contains frames acquired before the stop boundary. ASRService.stop() explicitly marks a host-time boundary and expects the synchronously drained final packet to be trimmed to it, so this can cut the last hardware buffer—and potentially the final phoneme—from recordings. Keep publication open until AudioDeviceStop has synchronized with the IOProc, then let the pipeline discard frames after the recorded boundary.

Useful? React with 👍 / 👎.

@github-actions

Copy link
Copy Markdown

FluidVoice PR build ready

Download FluidVoice-PR-732-250f8bfbbecc

The artifact contains the ad-hoc-signed app ZIP, Xcode archive, build manifest, and installation instructions. It expires 5 days after the build.

Install the app

  1. Extract the downloaded artifact, then extract FluidVoice-PR-732.app.zip.

  2. Move FluidVoice Improve core audio resiliency #732.app into the /Applications folder.

  3. Open Terminal and remove the download quarantine marker:

    xattr -dr com.apple.quarantine "/Applications/FluidVoice #732.app"
    
  4. In Applications, Control-click FluidVoice Improve core audio resiliency #732.app and choose Open.

  5. If macOS still blocks it, open System Settings → Privacy & Security, click Open Anyway, and confirm.

This build has its own app identity, so its permissions are separate from the release version of FluidVoice.

View workflow run

@grohith327

Copy link
Copy Markdown
Collaborator Author

@greptileai re-run review with my updated responses

@grohith327
grohith327 merged commit 25f3f22 into main Jul 31, 2026
6 checks passed
aguynamedryan added a commit to aguynamedryan/FluidVoice that referenced this pull request Aug 3, 2026
…ic-dev#732

Upstream altic-dev#732 turned direct Core Audio capture on by default, deleted the
duration-mismatch fallback, and reshaped the capture entry point
(startPreferredAudioCapture -> startConfiguredAudioCapture, device resolution
moved off-main into DirectCoreAudioLifecycleController).

Conflict resolutions:

- NotificationService: drop deliverAudioCaptureFallback along with the rest of
  the duration-mismatch machinery; keep deliverPreferredMicrophoneFallback.
- ASRService: take upstream's startConfiguredAudioCapture structure and
  lifecycle-controller resolution, keeping the FluidVoice-only fallback
  announcement at both backends. The AVAudioEngine branch is now reached only
  when direct capture is switched off, so its comment says so.
- handleDefaultInputChanged: keep the per-mode switch, adopt upstream's widened
  `isRunning || isStarting` guard.

Also fixes a defect the merge introduced silently. Upstream's new
directCoreAudioDeviceSelection() gates on `== .manual`, so it merged cleanly as
an addition while routing .fluidVoiceOnly to the system default -- capturing the
wrong microphone with no error, and with all 184 tests passing. Selection is now
exhaustive over the mode, and .fluidVoiceOnly maps to a new
.preferredUIDOrDefault case: resolveDevice now throws on an absent device rather
than falling back, which would have restored the refuse-to-record behaviour this
PR deliberately replaced with "prefer the pinned mic, else the default,
announced".

That routing rule is now a pure, nonisolated ASRService.directCaptureSelection
covered by three tests -- verified to fail against the broken mapping, which no
existing test caught.

Local: 187 tests, 0 failures; swiftlint --strict clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018jnjU9kcVVRBU33Gwp8tri
aguynamedryan added a commit to aguynamedryan/FluidVoice that referenced this pull request Aug 3, 2026
…iew gaps

Three findings from the review of 07c765c.

Stale notification (Greptile P1). The fallback banner says "recording through
<device> until your selected microphone is reconnected", but it was posted with
a fresh UUID each time, so it could never be retracted -- reconnecting the mic
left a notification asserting something no longer true, and repeated fallbacks
stacked up one banner per recording. The identifier is now stable, and the
announcer returns .doNothing / .announce / .withdraw so returning to the
preferred device removes the delivered notification. Withdrawal only fires when
something was actually announced, or every ordinary recording would emit a
pointless removal.

Unbindable preferred device (Codex P2). FluidVoice-only promises "prefer the
pinned mic, else the macOS default". Resolution already covered a *missing*
device, but one that is present and cannot be bound -- a multi-stream aggregate
the capture helper rejects, or a device that fails to start -- threw, so the
recording failed instead of degrading. It now retries once on the default and
announces the substitution. Deliberately scoped to .fluidVoiceOnly: .manual and
.system keep the fail-loud behaviour altic-dev#732 shipped. The shared start path is
factored into startDirectCapture(selection:reason:) so both take the same route.

Stale mode in Settings (Codex P2). Turning off Faster Recording Start makes the
store report .manual, but the settings window's bound mode is only refreshed at
launch -- so it kept saying "leaves the macOS input device unchanged" while the
next recording would move it. The toggle now re-reads the mode. The stored
preference is deliberately left alone, so re-enabling restores FluidVoice-only.

Mutation-checked: a version that never withdraws fails the sequence test.

Local: 204 tests, 0 failures; swiftlint --strict clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018jnjU9kcVVRBU33Gwp8tri
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