Repository navigation
feat(desktop): speak proactive notifications aloud (off-by-default Advanced setting) + unified voice speed - #11528
Conversation
There was a problem hiding this comment.
4 issues found across 10 files
Confidence score: 3/5
- In
desktop/macos/Desktop/Sources/ProactiveAssistants/Services/NotificationSpeech.swift, queueing capturesNotificationSpeech.isEnabled()too early, sonotificationWasPresented()can still callspeak(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,hasSpokenis flipped beforespeak(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 — sethasSpokenonly 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 ofDefaultsKey.speakNotificationsAloud.rawValueintroduces 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 exercisesNotificationSpeech.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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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>
| @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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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>
1fa4b95 to
4c6bf0d
Compare
…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.
79a0aca to
315276a
Compare
|
Triage of the Static & Test Contracts failure (suites: AgentPillLifecycleTests, ChatCitationTests, ChatTimelineContinuityTests, ContextBucketPromptAssemblerTests, MarkdownNestedScrollTests):
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. |
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 (respectFrequencymarker; 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 inNotificationService, 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 byShortcutSettings.voicePlaybackSpeed(default 1.4×) exactly like the OpenAI audio path applies it viaAVAudioPlayer.rate, clamped toAVSpeechUtterance's legal range — one Voice Speed setting drives both output paths.Product invariants
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.FloatingBarVoicePlaybackService.swift). Voice-turn lifecycle ownership unchanged: speech goes through the existingspeakOneShot, which already acquires/validates PTT leases viaVoiceTurnCoordinator; the rate fix only changesAVSpeechUtterance.ratearithmetic.Failure-Class: none
Verification
xcrun swift test --filter "NotificationSpeechTests|FloatingBarVoiceResponseSettingsTests"— NotificationSpeechTests 7/7 (default-off contract, proactive gate, once-guard dedup, functional-notice silence) +testSystemSpeechRateScalesWithVoiceSpeed(scaling + clamping).omi-ankara(this branch on top of main, real signed-in account):probe_suggestion_nudgedelivered a nudge with no voice activity (no speech logs,floatingBarVoiceResponseActive=false)..cross-review-verify.png) → repeated real deliveries spoke: app logSuggestion: delivering [95%] "TikTok is fine — but you said you'd send the investor update tonight."→NotificationSpeech: speaking delivered notification (69 chars)4 ms later,floatingBarVoiceResponseActivetrue ~5 s while audio played; heard live by Nik during the demo (user-requested triggers at 19:07, 19:09, 19:12).