Skip to content

Ask by voice, and hear the answer - #2

Merged
djsincla merged 2 commits into
mainfrom
voice
Sep 27, 2026
Merged

djsincla merged 2 commits into
mainfrom
voice

Conversation

@djsincla

Copy link
Copy Markdown
Owner

What

  • Dictation: hold space in an empty Ask field, or click the new mic button, and the question is typed into the field as you speak. Press Return to send it, so a misheard word can be fixed first.
  • Read-back: answers to spoken questions are read aloud. Settings has a Voice section: read aloud Never / When asked by voice / Always, a voice picker, and the hold-space switch.
  • Clear button: a new ✕ in the Ask field. It also stops a dictation that's still running.

Everything runs on this Mac:

  • Speech recognition: SpeechAnalyzer with SpeechTranscriber, on macOS 26. The open notebook's source names are offered as vocabulary. Below macOS 26 the dictation controls don't appear.
  • Reading aloud: AVSpeechSynthesizer, with citations, markdown and web addresses stripped first. This works on every supported macOS.

Also in this PR

It includes 3696aaa ("Sign the bundle, so a permission can stick to it") from the unmerged sign-the-bundle branch. The microphone permission depends on it: the grant only sticks to a consistently signed bundle, and the new microphone entitlement goes into that same signing step.

Holding space

A press is held back until it's clear whether it's a tap or a hold (250 ms).

  • The microphone opens on the press itself, so no words are lost while that's decided. A tap throws away the fraction of a second it recorded, and is replayed as a normal space.
  • Keys that overlap during fast typing stay in order.
  • Esc while holding throws the recording away.
  • Switching away from the window mid-hold stops the recording, so the microphone isn't left open.
  • It only works in an empty Ask field, or where no text is being edited.

The rule lives in NotebookKit/HoldToTalk.swift as a plain type, so it's tested without a keyboard.

Latency

A timing line is written to the log for every dictation (subsystem com.dai.notebookmlx, category dictation).

  • Before: the first build missed a fast talker's first words. The log showed the microphone opening 1,943 ms after the press. Every press built the recognition analyzer from scratch, because the warm-up stopped whenever the framework asked for a model install, which it does on every launch even when the model is already installed.
  • Now: the analyzer and a prepared audio engine are ready before the press, and a failed warm-up is logged instead of ignored. Measured press-to-microphone is 75–96 ms.

Packaging

  • Info.plist gains NSMicrophoneUsageDescription and NSSpeechRecognitionUsageDescription.
  • New packaging/NotebookMLX.entitlements with com.apple.security.device.audio-input, applied to the app only. Without it, the hardened runtime blocks the microphone and shows no prompt.

Testing

  • swift test: all 121 tests in 21 suites pass. New tests cover the space tap/hold logic, the live transcript, and the read-aloud text cleanup.
  • By hand, on macOS 26.3 with a Developer ID build installed in /Applications: dictation by holding space and by the mic button, and answers read back.

🤖 Generated with Claude Code

https://claude.ai/code/session_013iVkaT35YkmM7itiMcNXAt

djsincla and others added 2 commits September 11, 2026 13:23
The app was never signed as a bundle. SwiftPM ad-hoc signs the binary, and
make-app.sh wrapped it without signing anything: `Sealed Resources=none`,
`Info.plist=not bound`, and a signing identifier derived from the binary
(`NotebookApp-5555...`) rather than the `com.dai.notebookmlx` in Info.plist.

TCC keys its grants on code signing identity, so an app in that state cannot
hold a Documents folder permission against its own bundle id - the identifier
it presents is not the identifier anybody grants, and `tccutil reset
com.dai.notebookmlx` matches nothing to reset.

The visible failure was a notebook shelf that was simply empty. The library
folder had five notebooks in it and the app could still write new ones, because
`reload()` does `(try? contentsOfDirectory(...)) ?? []` and a refused directory
read is indistinguishable from an empty folder by the time it reaches the
screen. It reads as "there are no notebooks" rather than "macOS would not let me
look", which is the wrong component to go and investigate.

Signed with Developer ID when one is in the keychain, ad-hoc otherwise and
saying so. The difference is not cosmetic: a Developer ID signature gives the
same designated requirement on every build, so the permission is answered once,
where ad-hoc hashes the binary and every rebuild is a new app that has to ask
again. Nested bundles are signed first, because signing the outer one fails
with "code object is not signed at all" while MLX's resource bundle - which
SwiftPM copies in unsigned - is still unsigned inside it.

Hardened runtime and a secure timestamp when a real certificate is used, both
required for notarisation, and no entitlements: dAI's agent signs the same MLX
stack this way and Apple notarises it. Metal shader loading out of the nested
bundle works under library validation because both are signed by the same team.

notarize.sh submits and staples. It checks the hardened runtime and the absence
of get-task-allow up front rather than letting Apple refuse minutes later with a
log URL naming the flag instead of the fix - and get-task-allow arrives by
accident, since SwiftPM puts it on everything it ad-hoc signs. It archives with
ditto rather than zip, because a plain zip drops the extended attributes the
signature lives in and Apple then reads the upload as unsigned. The ticket is
stapled to the .app and not to the archive, so the app does not need to reach
Apple to be checked - an unstapled build fails on a machine that is offline or
behind a filter, which is the worst kind of intermittent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0157siweEqdaNhvgsQXPenzW
Hold space in an empty Ask field, or click the microphone, and the question
is dictated into the field. Return sends it, so a misheard product name is
fixed before it reaches the fleet rather than answered. Answers to spoken
questions are read back.

All of it on this Mac. Recognition is SpeechAnalyzer with SpeechTranscriber
(macOS 26), chosen over the older recogniser, which is worse at exactly what a
notebook question is made of - product names, filenames, long sentences - and
over Whisper, which would mean a model to ship and manage and no live text.
The open notebook's source names are offered as vocabulary. Read-back is
AVSpeechSynthesizer with citations, markdown and addresses removed first, so
an answer is heard as prose and not as a filename and a page number. Dictation
is hidden below macOS 26; reading aloud works everywhere.

Space is also a character, so a press is held back until it is known to be a
hold. A tap is replayed as an ordinary space, keys that overlap it in fast
typing keep their order, Escape throws a recording away, and losing focus
mid-hold stops rather than leaving the microphone open. Only in an empty Ask
field, or where no text is being edited; anywhere else space is untouched.
That rule lives in NotebookKit as a pure type and is tested there.

Latency, measured rather than guessed. The first build missed a fast
talker's first words, and a timing line per dictation showed why: 1.7 s
building an analyzer on every press, because the warm-up treated the
framework's per-launch installation request as a download and stopped,
silently, every time. Now the analyzer and a tapped, prepared audio engine are
ready before the press, the microphone opens on the press rather than after
the quarter second spent deciding it is a hold, and a warm-up that fails says
so in the log. Press to microphone went from 1,943 ms to 75-96 ms.

Also a clear button in the Ask field, which stops a running dictation too so
it does not write the words back.

Packaging: NSMicrophoneUsageDescription and NSSpeechRecognitionUsageDescription
in Info.plist, and the audio-input entitlement on the app - the hardened
runtime denies the microphone without it, and silently.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013iVkaT35YkmM7itiMcNXAt
@djsincla
djsincla merged commit a31da90 into main Sep 27, 2026
1 check passed
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