Skip to content

feat(desktop): speak proactive notifications aloud (off-by-default Advanced setting) + unified voice speed - #11528

Merged
kodjima33 merged 3 commits into
mainfrom
kodjima33/spoken-notifications
Aug 14, 2026
Merged

kodjima33 merged 3 commits into
mainfrom
kodjima33/spoken-notifications

Conversation

@kodjima33

@kodjima33 kodjima33 commented Aug 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

Demo feature: Speak Notifications Aloud — an off-by-default toggle in Advanced settings → Preferences. When enabled, proactive notifications (suggestions, insights, tasks, context-director) are read out loud through the existing floating-bar voice pipeline (user's chat voice, system-voice fallback) at the moment a surface actually presents them. Plus a voice-speed parity fix the demo surfaced: the system-voice path ignored the Voice Speed setting.

  • NotificationSpeech: pure policy — speaks only when the user opted in, only for proactive notifications (respectFrequency marker; functional notices like the onboarding test and screen-repair prompts never speak), only non-empty messages.
  • NotificationSpeechOnDelivery: once-per-notification speaker hooked into the shared presentation callbacks in NotificationService, so bar-immediate, bar-queued, and system-banner deliveries each speak exactly once and a muted-preview dual delivery cannot speak twice.
  • FloatingBarVoicePlaybackService.systemSpeechRate: system voice scales its utterance rate by ShortcutSettings.voicePlaybackSpeed (default 1.4×) exactly like the OpenAI audio path applies it via AVAudioPlayer.rate, clamped to AVSpeechUtterance's legal range — one Voice Speed setting drives both output paths.

Product invariants

  • INV-CHAT-1 — path-matched (NotificationService.swift). No transcript behavior change: delivery surfaces, chat journaling, and notification persistence are untouched; the change only adds a speech side-effect at the existing presentation callbacks.
  • INV-VOICE-1 — path-matched (FloatingBarVoicePlaybackService.swift). Voice-turn lifecycle ownership unchanged: speech goes through the existing speakOneShot, which already acquires/validates PTT leases via VoiceTurnCoordinator; the rate fix only changes AVSpeechUtterance.rate arithmetic.

Failure-Class: none

Verification

  • Focused suites green: xcrun swift test --filter "NotificationSpeechTests|FloatingBarVoiceResponseSettingsTests" — NotificationSpeechTests 7/7 (default-off contract, proactive gate, once-guard dedup, functional-notice silence) + testSystemSpeechRateScalesWithVoiceSpeed (scaling + clamping).
  • Live on omi-ankara (this branch on top of main, real signed-in account):
    • Default off → probe_suggestion_nudge delivered a nudge with no voice activity (no speech logs, floatingBarVoiceResponseActive=false).
    • Toggle ON (Advanced → Preferences card, screenshot in .cross-review-verify.png) → repeated real deliveries spoke: app log Suggestion: delivering [95%] "TikTok is fine — but you said you'd send the investor update tonight." → NotificationSpeech: speaking delivered notification (69 chars) 4 ms later, floatingBarVoiceResponseActive true ~5 s while audio played; heard live by Nik during the demo (user-requested triggers at 19:07, 19:09, 19:12).
    • Speed fix exercised on the rebuilt bundle: the 19:12 utterance played at the unified 1.4× pace.

Review in cubic

@cubic-dev-ai cubic-dev-ai 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.

4 issues found across 10 files

Confidence score: 3/5

  • In desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift, queueing captures NotificationSpeech.isEnabled() too early, so notificationWasPresented() can still call speak(text) after the user disables the setting; that creates a clear user-facing settings violation — re-check the current enabled state at presentation/speak time instead of relying on the initializer snapshot.
  • In desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift, hasSpoken is flipped before speak(text) succeeds, and the one-shot path can drop utterances during an active voice turn; this can mark notifications as spoken when nothing was heard, preventing retries — set hasSpoken only after successful enqueue/playback (or reset it on drop/failure).
  • In desktop/macos/Desktop/Sources/MainWindow/Pages/SettingsPage.swift, using the raw string "speakNotificationsAloud" instead of DefaultsKey.speakNotificationsAloud.rawValue introduces key-drift risk if the shared key changes, which can desync UI state from behavior — switch to the typed key constant.
  • In desktop/macos/e2e/flows/notifications-settings.yaml, the flow updates/snapshots settings but never exercises NotificationSpeech.swift, so the speech-toggle and drop-path regressions above are unlikely to be caught automatically — extend the flow to assert actual speak/no-speak behavior under setting changes and active-turn conditions.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/macos/Desktop/Sources/MainWindow/Pages/SettingsPage.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/MainWindow/Pages/SettingsPage.swift:365">
P3: This new @AppStorage uses the raw string literal "speakNotificationsAloud" instead of the typed key DefaultsKey.speakNotificationsAloud.rawValue, even though the key is already defined in DefaultsKey.swift and the consumer reads it through DefaultsKey.speakNotificationsAloud.rawValue (NotificationSpeech.enabledDefaultsKey). Inline literals reintroduce the silent-typo failure the DefaultsKey enum exists to prevent: if the two strings ever diverge, the setting is read as nil and the toggle silently has no effect. Use DefaultsKey.speakNotificationsAloud.rawValue here.</violation>
</file>

<file name="desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift">

<violation number="1" location="desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift:59">
P2: When a notification is queued, this initializer snapshots `NotificationSpeech.isEnabled()` before presentation. If the user turns the setting off while it waits, `notificationWasPresented()` still calls `speak(text)`; evaluate the opt-in at presentation time.</violation>

<violation number="2" location="desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift:67">
P3: `hasSpoken` is set before `speak(text)` runs, but the default spoke goes through `speakOneShot`, which synchronously drops the utterance when a voice turn is active (`activeTurnID != nil` and the PTT lease cannot be acquired) in FloatingBarVoicePlaybackService. A notification arriving mid-turn is marked spoken and never retried, so the opted-in user silently misses it. Set `hasSpoken = true` only when the utterance will actually play, or otherwise let a dropped one-shot be retried, so the once-guard prevents double-speak without swallowing a dropped delivery.</violation>
</file>

<file name="desktop/macos/e2e/flows/notifications-settings.yaml">

<violation number="1" location="desktop/macos/e2e/flows/notifications-settings.yaml:14">
P3: The `notifications-settings` flow never exercises `NotificationSpeech.swift`: its steps only call `settings_notifications_snapshot` and `set_notification_settings`, which read/update frequency and permission state and never trigger speech. The speak-aloud toggle lives in `SettingsContentView+Assistants.swift` (under the Assistants/Preferences section), which is already covered by `ai-chat-settings.yaml`, not this flow. Per the coverage rule, list a file under `covers:` only when the flow actually exercises its path; move `NotificationSpeech.swift` to the flow that exercises it rather than claiming this flow covers it.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


convenience init(message: String, isProactive: Bool) {
self.init(
text: NotificationSpeech.utterance(

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: When a notification is queued, this initializer snapshots NotificationSpeech.isEnabled() before presentation. If the user turns the setting off while it waits, notificationWasPresented() still calls speak(text); evaluate the opt-in at presentation time.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift, line 59:

<comment>When a notification is queued, this initializer snapshots `NotificationSpeech.isEnabled()` before presentation. If the user turns the setting off while it waits, `notificationWasPresented()` still calls `speak(text)`; evaluate the opt-in at presentation time.</comment>

<file context>
@@ -0,0 +1,69 @@
+
+  convenience init(message: String, isProactive: Bool) {
+    self.init(
+      text: NotificationSpeech.utterance(
+        message: message, isEnabled: NotificationSpeech.isEnabled(), isProactive: isProactive))
+  }
</file context>

@AppStorage("multiChatEnabled") var multiChatEnabled = false
@AppStorage("conversationsCompactView") var conversationsCompactView = true
@AppStorage("useLegacyHomeDesign") var useLegacyHomeDesign = false
@AppStorage("speakNotificationsAloud") var speakNotificationsAloud = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: This new @AppStorage uses the raw string literal "speakNotificationsAloud" instead of the typed key DefaultsKey.speakNotificationsAloud.rawValue, even though the key is already defined in DefaultsKey.swift and the consumer reads it through DefaultsKey.speakNotificationsAloud.rawValue (NotificationSpeech.enabledDefaultsKey). Inline literals reintroduce the silent-typo failure the DefaultsKey enum exists to prevent: if the two strings ever diverge, the setting is read as nil and the toggle silently has no effect. Use DefaultsKey.speakNotificationsAloud.rawValue here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/MainWindow/Pages/SettingsPage.swift, line 365:

<comment>This new @AppStorage uses the raw string literal "speakNotificationsAloud" instead of the typed key DefaultsKey.speakNotificationsAloud.rawValue, even though the key is already defined in DefaultsKey.swift and the consumer reads it through DefaultsKey.speakNotificationsAloud.rawValue (NotificationSpeech.enabledDefaultsKey). Inline literals reintroduce the silent-typo failure the DefaultsKey enum exists to prevent: if the two strings ever diverge, the setting is read as nil and the toggle silently has no effect. Use DefaultsKey.speakNotificationsAloud.rawValue here.</comment>

<file context>
@@ -362,6 +362,7 @@ struct SettingsContentView: View {
   @AppStorage("multiChatEnabled") var multiChatEnabled = false
   @AppStorage("conversationsCompactView") var conversationsCompactView = true
   @AppStorage("useLegacyHomeDesign") var useLegacyHomeDesign = false
+  @AppStorage("speakNotificationsAloud") var speakNotificationsAloud = false
 
   // AI Chat settings
</file context>
Suggested change
@AppStorage("speakNotificationsAloud") var speakNotificationsAloud = false
@AppStorage(DefaultsKey.speakNotificationsAloud.rawValue) var speakNotificationsAloud = false

- desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Insight/InsightAssistantTelemetry.swift
- desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistantTelemetry.swift
- desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationService.swift
- desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The notifications-settings flow never exercises NotificationSpeech.swift: its steps only call settings_notifications_snapshot and set_notification_settings, which read/update frequency and permission state and never trigger speech. The speak-aloud toggle lives in SettingsContentView+Assistants.swift (under the Assistants/Preferences section), which is already covered by ai-chat-settings.yaml, not this flow. Per the coverage rule, list a file under covers: only when the flow actually exercises its path; move NotificationSpeech.swift to the flow that exercises it rather than claiming this flow covers it.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/e2e/flows/notifications-settings.yaml, line 14:

<comment>The `notifications-settings` flow never exercises `NotificationSpeech.swift`: its steps only call `settings_notifications_snapshot` and `set_notification_settings`, which read/update frequency and permission state and never trigger speech. The speak-aloud toggle lives in `SettingsContentView+Assistants.swift` (under the Assistants/Preferences section), which is already covered by `ai-chat-settings.yaml`, not this flow. Per the coverage rule, list a file under `covers:` only when the flow actually exercises its path; move `NotificationSpeech.swift` to the flow that exercises it rather than claiming this flow covers it.</comment>

<file context>
@@ -11,6 +11,7 @@ covers:
   - desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Insight/InsightAssistantTelemetry.swift
   - desktop/macos/Desktop/Sources/ProactiveAssistants/Assistants/Suggestions/SuggestionAssistantTelemetry.swift
   - desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationService.swift
+  - desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift
   - desktop/macos/Desktop/Sources/ProactiveAssistants/Services/FloatingBarNotificationPreviewPolicy.swift
   - desktop/macos/Desktop/Sources/AnalyticsManager.swift
</file context>

guard let text, !hasSpoken else { return }
hasSpoken = true
log("NotificationSpeech: speaking delivered notification (\(text.count) chars)")
speak(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.

P3: hasSpoken is set before speak(text) runs, but the default spoke goes through speakOneShot, which synchronously drops the utterance when a voice turn is active (activeTurnID != nil and the PTT lease cannot be acquired) in FloatingBarVoicePlaybackService. A notification arriving mid-turn is marked spoken and never retried, so the opted-in user silently misses it. Set hasSpoken = true only when the utterance will actually play, or otherwise let a dropped one-shot be retried, so the once-guard prevents double-speak without swallowing a dropped delivery.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift, line 67:

<comment>`hasSpoken` is set before `speak(text)` runs, but the default spoke goes through `speakOneShot`, which synchronously drops the utterance when a voice turn is active (`activeTurnID != nil` and the PTT lease cannot be acquired) in FloatingBarVoicePlaybackService. A notification arriving mid-turn is marked spoken and never retried, so the opted-in user silently misses it. Set `hasSpoken = true` only when the utterance will actually play, or otherwise let a dropped one-shot be retried, so the once-guard prevents double-speak without swallowing a dropped delivery.</comment>

<file context>
@@ -0,0 +1,69 @@
+    guard let text, !hasSpoken else { return }
+    hasSpoken = true
+    log("NotificationSpeech: speaking delivered notification (\(text.count) chars)")
+    speak(text)
+  }
+}
</file context>

@kodjima33
kodjima33 force-pushed the kodjima33/spoken-notifications branch from 1fa4b95 to 4c6bf0d Compare August 14, 2026 02:28
…efault Advanced setting

Adds a Speak Notifications Aloud toggle (Advanced settings → Preferences,
off by default). When enabled, proactive notifications (suggestions,
insights, tasks, context-director) are read out loud through the existing
floating-bar voice pipeline (user's chat voice, system-voice fallback) at
the moment a surface actually presents them.

- NotificationSpeech: pure policy (enabled + proactive + non-empty) plus
  NotificationSpeechOnDelivery, a once-per-notification speaker hooked into
  the shared presentation callbacks, so bar-immediate, bar-queued and
  system-banner deliveries all speak exactly once and a muted-preview dual
  delivery cannot speak twice.
- Functional notices (respectFrequency: false — onboarding test, screen
  repair, support replies) never speak.
- Off by default: fresh-install contract asserted in tests.

Verification: focused suite 'NotificationSpeechTests' 7/7 green; live on
omi-ankara (main + this change, real account): default-off probe delivered
with no voice activity; after enabling, probe_suggestion_nudge delivered
'TikTok is fine — but you said you'd call dad tonight' with app log
'NotificationSpeech: speaking delivered notification (52 chars)' and
floatingBarVoiceResponseActive true for ~5s while the utterance played.
…enAI audio path

The system-voice path hardcoded utterance rate 0.47 (~1x) while the OpenAI
audio path applied ShortcutSettings.voicePlaybackSpeed (default 1.4x) via
AVAudioPlayer.rate — the same reply sounded fast from push-to-talk and slow
from spoken notifications / TTS fallbacks. systemSpeechRate scales the
conversational base by the user's multiplier, clamped to AVSpeechUtterance's
legal range, so one Voice Speed setting now drives both output paths.

Verified live on omi-ankara: spoken notification delivered at 19:12 played
at the unified 1.4x pace (NotificationSpeech: speaking delivered
notification (69 chars)); focused test
testSystemSpeechRateScalesWithVoiceSpeed covers scaling and clamping.
@kodjima33
kodjima33 force-pushed the kodjima33/spoken-notifications branch from 79a0aca to 315276a Compare August 14, 2026 04:27
@kodjima33

Copy link
Copy Markdown
Collaborator Author

Triage of the Static & Test Contracts failure (suites: AgentPillLifecycleTests, ChatCitationTests, ChatTimelineContinuityTests, ContextBucketPromptAssemblerTests, MarkdownNestedScrollTests):

  • None of these suites' subjects are touched by this PR's diff (spoken-notification policy/service, voice playback rate, settings card, e2e cover entry).
  • All five pass locally on pristine main (xcrun swift test --filter ... → every suite 'passed', 0 failures; log: five-suites-main.log on Nik's machine).
  • The CI job runs suites 'in isolation with 2 workers, 300s per-suite budget' — the failure pattern (5 unrelated chat/agent suites dying together on a loaded runner) matches an isolation-mode timeout flake, not a regression.

Rerun is in flight; if it greens, merge normally. If this recurs across PRs it's a runner-capacity/per-suite-budget problem, not a code one.

@kodjima33
kodjima33 merged commit d20f891 into main Aug 14, 2026
29 of 32 checks passed
@kodjima33
kodjima33 deleted the kodjima33/spoken-notifications branch August 14, 2026 06:31
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