Skip to content

fix(audio): keep built-in mic capture alive on Apple Silicon - #912

Open
Defake wants to merge 2 commits into
altic-dev:mainfrom
Defake:852-built-in-mic-fix
Open

Defake wants to merge 2 commits into
altic-dev:mainfrom
Defake:852-built-in-mic-fix

Conversation

@Defake

@Defake Defake commented Aug 28, 2026 •

Copy link
Copy Markdown

Description

On Apple Silicon, direct Core Audio capture from the built-in microphone can become silent after about 3.5 seconds and truncate dictation. Keep the built-in output hardware active during capture with AudioDeviceStart(outputDeviceID, nil), then release it with AudioDeviceStop(outputDeviceID, nil).

Output candidates are discovered during idle input preparation and refreshed when topology changes rebuild the input, avoiding a device scan before each recording. Cleanup retries once immediately, clears the saved device only after success, and logs failures while retaining it for a later stop or teardown. Output failures remain best effort and do not block microphone capture.

Type of Change

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

Related Issue or Discussion

Closes #852

Testing

  • Tested on Intel Mac
  • Tested on Apple Silicon Mac
  • Tested on macOS version: 26.7.1 (arm64 MacBook Pro)
  • Ran strict SwiftLint on both changed files
  • Ran SwiftFormat lint on both changed files, with the pre-existing wrapPropertyBodies and wrapIfStatementBodies violations excluded
  • Ran 76 focused tests after rebasing; zero failures or skipped tests

The arm64 Debug test build succeeded on 1.6.10-beta.8 (build 27). The test host used the existing FLUIDVOICE_MIC_PHASE1=pr912-tests opt-in in its xctestrun environment to bypass onboarding and model downloads. Test selection:

  • DirectAudioReliabilityTests: 58 passed, including output preparation, start fallback, transient/permanent stop failures, and later cleanup.
  • AudioHardwareRecoveryTests: 15 passed.
  • MonitorTopologyRecoveryTests: the two prepared-input topology refresh tests passed.
  • NormalAudioCaptureCompatibilityTests: the 50-cycle prepared start/stop test passed.

Manual playback check on the PR build (1.6.10-beta.7, before the rebase): select the built-in microphone, disable Pause Media During Transcription, play music, and repeatedly start and stop dictation, including recordings beyond the original cutoff. Music kept playing normally. Logs show nine completed recordings, no dropped audio packets, and no keep-alive cleanup warnings. The capture implementation was preserved unchanged by the rebase.

Intel runtime and the full repository test suite were not run for this update.

Screenshots / Video

  • No UI/visual changes; screenshots/video are not applicable.

Copyable local test output:

AudioHardwareRecoveryTests: Executed 15 tests, with 0 failures
DirectAudioReliabilityTests: Executed 58 tests, with 0 failures
MonitorTopologyRecoveryTests: Executed 2 tests, with 0 failures
NormalAudioCaptureCompatibilityTests: Executed 1 test, with 0 failures
Selected tests: Executed 76 tests, with 0 failures
** TEST EXECUTE SUCCEEDED **

Notes

A persistent output-stop failure can leave the output hardware active until a later cleanup succeeds or the process exits. It is logged and does not prevent dictation. The keep-alive remains limited to the Apple Silicon built-in microphone path.

Codex assisted with implementation and automated verification. The author approved the approach and performed the manual playback check.

@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: b79d729a95

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

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

greptile-apps Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium impact] Adds a workaround to keep audio output alive during microphone capture on Apple Silicon.

The PR does not appear safe to merge while the previously reported selected-microphone binding defect remains outstanding.

Summary

This PR keeps built-in microphone capture active on Apple Silicon by starting an available built-in output device during direct Core Audio capture and balancing it during stop or teardown.

  • Adds architecture- and device-aware output keep-alive preparation.
  • Adds bounded cleanup retries and retains failed cleanup state for later attempts.
  • Adds reliability tests for platform/input filtering, output fallback, and cleanup behavior.

Reviews (7) · Last reviewed commit: "fix(audio): prepare keep-alive devices a..." · Reviewed by Greptile

Comment thread Sources/Fluid/Services/ASRService.swift Resolved
@Defake
Defake marked this pull request as draft August 28, 2026 15:28
@Defake
Defake marked this pull request as ready for review August 28, 2026 15:42
Comment thread Sources/Fluid/Services/ASRService.swift Resolved

@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: 02aa44437f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Sources/Fluid/Services/ASRService.swift Resolved
@altic-dev

Copy link
Copy Markdown
Owner

Hi, what is this PR supposed to do again? You have an issue?

Microphone is a very sensitive area and the issues that come up are very large. So I'd be very careful before merging this. But if you want to have a discussion on this, we are happy to take a look at it.

@grohith327 for viz

@Defake

Defake commented Aug 29, 2026

Copy link
Copy Markdown
Author

@altic-dev yes, FluidVoice is not usable for me since 1.6.7.

The issue I had created: #852

This PR fixes that built-in microphone stops capturing input after 3 seconds of dictation on Apple M1.

It switches built-in microphone capture to AVAudioEngine instead of using direct Core Audio. Only switches if both selected and default microphone are built-in and it's Apple Silicon.

@altic-dev

Copy link
Copy Markdown
Owner

@altic-dev yes, FluidVoice is not usable for me since 1.6.7.

The issue I had created: #852

This PR fixes that built-in microphone stops capturing input after 3 seconds of dictation on Apple M1.

It switches built-in microphone capture to AVAudioEngine instead of using direct Core Audio. Only switches if both selected and default microphone are built-in and it's Apple Silicon.

We're trying to move away from AvAudio and w e need to find a bette way for this. @grohith327 wdyt?

Not sure how to fix this in a bette way

@grohith327

Copy link
Copy Markdown
Collaborator

@Defake The AVAudioEngine flow that exists right now will simply be removed in future commits as we have fully committed to the CoreAudio flow.

The equivalent fix for this in CoreAudio flow is there in this commit - 6fe6143

Can you try building this and let us know if it works. Thank you for trying really hard to get FV work!

@Defake

Defake commented Aug 30, 2026

Copy link
Copy Markdown
Author

@grohith327 thanks, I tried it 2 weeks ago, it didn't fix the issue: #852 (comment)

The problem is not zero-PCM. Capture starts normally and works for 3.5 seconds. Then corespeechd mutes the built-in microphone.

@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: 95b08c30a4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Defake

Defake commented Aug 30, 2026

Copy link
Copy Markdown
Author

I reworked this PR so it works with Core Audio now.
On my Mac, direct Core Audio capture starts normally, but corespeechd mutes the built-in microphone after 3.5 seconds when no output stream is active. The PR now runs a silent Core Audio output callback on the built-in output while dictation is active.
@altic-dev @grohith327 please take a look.

@altic-dev

Copy link
Copy Markdown
Owner

Could you try a simpler Core Audio approach first? Start the built-in output with AudioDeviceStart(outputDeviceID, nil) and stop it with AudioDeviceStop(outputDeviceID, nil). This might keep the hardware active without needing a separate silent IOProc.

The keep alive should also be best effort. If it fails, it shouldn’t delay or stop microphone capture.

The current version you have could cause dictation fails in a lot of devices if it fails.

@Defake
Defake force-pushed the 852-built-in-mic-fix branch from 95b08c3 to 5aef500 Compare September 3, 2026 06:38

@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: 5aef50044f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

private func stopOutputKeepAlive() {
guard let deviceID = self.outputKeepAliveDeviceID else { return }
self.outputKeepAliveDeviceID = nil
_ = AudioDeviceStop(deviceID, nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Stop only FluidVoice's keep-alive IOProc

When another application is playing through the built-in output during dictation, AudioDeviceStop(deviceID, nil) stops the device as a whole rather than a keep-alive operation owned by FluidVoice, so ending direct capture can interrupt or strand that application's playback. Register and retain a dedicated no-op output IOProc and pass its ID to both AudioDeviceStart and AudioDeviceStop instead of using the device-wide nil form.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This suggests to reintroduce the larger IOProc solution we decided to remove

@Defake

Defake commented Sep 3, 2026

Copy link
Copy Markdown
Author

@altic-dev thanks, it worked! I reworked the PR to use the simpler solution, please take a look

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

This pull request has been marked stale because it has had no activity for 5 days. It will be closed in 2 days if there is no further activity. Add the keep-open or pinned label to prevent automatic closure.

@github-actions github-actions Bot added the stale label Sep 9, 2026
@Defake
Defake force-pushed the 852-built-in-mic-fix branch from 5aef500 to 03f1c1c Compare September 9, 2026 06:34
@Defake

Defake commented Sep 10, 2026

Copy link
Copy Markdown
Author

Still actual.
@altic-dev @grohith327 could you please take a look at the simpler solution? I updated the PR.

@github-actions github-actions Bot removed the stale label Sep 11, 2026
@altic-dev

Copy link
Copy Markdown
Owner

Thanks! does it still work well? can merge this soon.

@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

FluidVoice PR build ready

Download FluidVoice-PR-912-9bd0810532dc

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-912.app.zip.

  2. Move FluidVoice fix(audio): keep built-in mic capture alive on Apple Silicon #912.app into the /Applications folder.

  3. Open Terminal and remove the download quarantine marker:

    xattr -dr com.apple.quarantine "/Applications/FluidVoice #912.app"
    
  4. In Applications, Control-click FluidVoice fix(audio): keep built-in mic capture alive on Apple Silicon #912.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

@Defake

Defake commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

@altic-dev yes, I tried the new build, it works 👍 Thank you.

@github-actions

Copy link
Copy Markdown

This pull request has been marked stale because it has had no activity for 5 days. It will be closed in 2 days if there is no further activity. Add the keep-open or pinned label to prevent automatic closure.

@github-actions github-actions Bot added the stale label Sep 22, 2026
@Defake
Defake force-pushed the 852-built-in-mic-fix branch from 03f1c1c to 9bd0810 Compare September 24, 2026 05:49
@Defake

Defake commented Sep 24, 2026

Copy link
Copy Markdown
Author

Rebased the PR

@github-actions github-actions Bot removed the stale label Sep 25, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

This pull request has been marked stale because it has had no activity for 5 days. It will be closed in 2 days if there is no further activity. Add the keep-open or pinned label to prevent automatic closure.

@github-actions github-actions Bot added the stale label Oct 3, 2026
@altic-dev

Copy link
Copy Markdown
Owner

Thanks for sticking with this and simplifying the fix. It keeps the current Core Audio approach, and your confirmation that it fixes the cutoff is helpful.

Before merging, I’d like to address two things:

  • We now scan all audio devices before every recording starts on Apple Silicon, even for external mics. Can we prepare that information earlier and avoid adding work before mic capture?
  • If AudioDeviceStop fails, we clear the saved output device and ignore the error. Can we handle that failure with bounded cleanup and add a test for it?

I also tested the concern about interrupting another app’s audio. Its callbacks continued through repeated start/stop cycles, so I couldn’t reproduce that locally. We should still check actual playback while starting and stopping dictation.
The fix looks useful; these changes would give me more confidence shipping it to other users.

@altic-dev altic-dev added keep-open and removed stale labels Oct 3, 2026
@Defake
Defake force-pushed the 852-built-in-mic-fix branch from 9bd0810 to 5fc09e7 Compare October 12, 2026 06:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T07:02:23.263040Z 5fc09e7 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 5fc09e7cf2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

self.packetHandler = packetHandler
// Discover output candidates during idle preparation, not on each Start.
// The lifecycle controller rebuilds this input after topology changes.
#if arch(arm64)

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 Detect Apple Silicon when running under Rosetta

When FluidVoice's universal release is launched using its x86_64 slice under Rosetta on an Apple Silicon Mac, this compile-time branch takes the #else and prepares no output IDs. The release is configured for standard architectures with ONLY_ACTIVE_ARCH = NO (Fluid.xcodeproj/project.pbxproj:970-1023), and Rosetta does not change the underlying Core Audio hardware, so direct built-in-microphone capture again lacks the keep-alive and can go silent or truncate. Detect the physical host/translation state at runtime and pass that result to the policy instead of using the process architecture.

Useful? React with 👍 / 👎.

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.

[BUG] Dictation stops detecting microphone input after 3 seconds

3 participants