From 0a9d509784cb7de51190e19c3dfbff448c016980 Mon Sep 17 00:00:00 2001 From: Dwayne Sinclair <5835173+djsincla@users.noreply.github.com> Date: Sun, 27 Sep 2026 21:19:28 -0400 Subject: [PATCH] A speaker button that is always there, to mute and unmute The only way to silence read-back was a button that appeared while an answer was being read. So the moment to decide answers should be quiet was after one had started talking, and there was no way to say "not now" in advance. The button is permanent now, beside the Ask field. Muting stops whatever is being read and keeps later answers silent until it is unmuted; the state is kept across launches, because somebody who muted the app in a shared office wants it still muted tomorrow. It animates while an answer is being read. Settings keeps only when answers are read - when asked by voice, or always. "Never" was the same as being muted, and two switches for one thing is one too many. Anybody who had chosen it starts muted, which is what it meant. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_013iVkaT35YkmM7itiMcNXAt --- Sources/NotebookApp/ContentView.swift | 22 ++++++++++++------- Sources/NotebookApp/ReadAloud.swift | 9 ++++++++ Sources/NotebookApp/SettingsView.swift | 2 ++ Sources/NotebookApp/VoiceSettings.swift | 28 ++++++++++++++++++------- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/Sources/NotebookApp/ContentView.swift b/Sources/NotebookApp/ContentView.swift index 5fb17f2..e1071b6 100644 --- a/Sources/NotebookApp/ContentView.swift +++ b/Sources/NotebookApp/ContentView.swift @@ -1286,7 +1286,6 @@ struct AskBar: View { private func readBack(_ answered: NotebookModel.Answered?) { guard let answered, answered.generated else { return } switch VoiceSettings.readAloud { - case .never: return case .whenSpoken: guard askedByVoice else { return } case .always: break } @@ -1389,14 +1388,21 @@ struct AskBar: View { .buttonStyle(.plain) .help("Clear the question") } - if readAloud.speaking { - Button { readAloud.stop() } label: { - Image(systemName: "speaker.slash.fill").font(.title2) - .foregroundStyle(Palette.inkSecondary) - } - .buttonStyle(.plain) - .help("Stop reading the answer") + // Always here, not only while an answer is being read. It + // appeared only mid-answer, which meant the time to decide + // answers should be silent was after one had started talking. + Button { readAloud.muted.toggle() } label: { + Image(systemName: readAloud.muted ? "speaker.slash.fill" + : "speaker.wave.2.fill") + .font(.title2) + .foregroundStyle(readAloud.speaking ? Palette.accent + : Palette.inkSecondary) + .symbolEffect(.variableColor.iterative, isActive: readAloud.speaking) + .contentTransition(.symbolEffect(.replace)) } + .buttonStyle(.plain) + .help(readAloud.muted ? "Unmute: read answers aloud" + : readAloud.speaking ? "Stop reading and mute" : "Mute answers") // Present while a question is out, only disabled: taking it away // would drop the keyboard monitor with it and build a new one, // microphone state and all, every time a question was asked. diff --git a/Sources/NotebookApp/ReadAloud.swift b/Sources/NotebookApp/ReadAloud.swift index 1a09a16..b94991b 100644 --- a/Sources/NotebookApp/ReadAloud.swift +++ b/Sources/NotebookApp/ReadAloud.swift @@ -16,6 +16,14 @@ final class ReadAloud { private(set) var speaking = false + /// Muted means nothing is read, and whatever is being read stops. + var muted = VoiceSettings.muted { + didSet { + VoiceSettings.muted = muted + if muted { stop() } + } + } + @ObservationIgnored private let synthesizer = AVSpeechSynthesizer() @ObservationIgnored private let watcher = Watcher() @@ -28,6 +36,7 @@ final class ReadAloud { /// Read a turn's answer, citations and markdown removed. func speak(_ turn: NotebookPackage.Turn) { + guard !muted else { return } let text = SpeakableText.from(answer: turn.answer, citations: turn.citations.map(\.citation)) guard !text.isEmpty else { return } diff --git a/Sources/NotebookApp/SettingsView.swift b/Sources/NotebookApp/SettingsView.swift index f55d2b1..e93ec50 100644 --- a/Sources/NotebookApp/SettingsView.swift +++ b/Sources/NotebookApp/SettingsView.swift @@ -201,6 +201,8 @@ struct SettingsView: View { ForEach(VoiceSettings.ReadAloud.allCases) { Text($0.label).tag($0) } } .onChange(of: readAloud) { _, new in VoiceSettings.readAloud = new } + Text("The speaker button beside the Ask field mutes and unmutes.") + .font(.caption).foregroundStyle(.secondary) Picker("Voice", selection: $voiceID) { Text("System default").tag("") ForEach(ReadAloud.voices(), id: \.identifier) { v in diff --git a/Sources/NotebookApp/VoiceSettings.swift b/Sources/NotebookApp/VoiceSettings.swift index 376dd5a..5bcb0b6 100644 --- a/Sources/NotebookApp/VoiceSettings.swift +++ b/Sources/NotebookApp/VoiceSettings.swift @@ -4,18 +4,19 @@ import Foundation /// `GatewaySettings`. enum VoiceSettings { - /// When an answer is read aloud. + /// Which answers are read aloud, when not muted. /// - /// Three states rather than a switch, because the useful default is neither - /// on nor off. Somebody who spoke a question is usually not looking at the - /// screen and wants the answer spoken back; somebody who typed one is - /// reading already, and a voice starting up unasked is an interruption. + /// Somebody who spoke a question is usually not looking at the screen and + /// wants the answer spoken back; somebody who typed one is reading already, + /// and a voice starting up unasked is an interruption. Whether anything is + /// read at all is the speaker button's job, not this setting's: "Never" was + /// a third option here, and a mute somebody could only reach through + /// Settings was a mute nobody reached for mid-answer. enum ReadAloud: String, CaseIterable, Identifiable { - case never, whenSpoken, always + case whenSpoken, always var id: String { rawValue } var label: String { switch self { - case .never: "Never" case .whenSpoken: "When asked by voice" case .always: "Always" } @@ -30,6 +31,19 @@ enum VoiceSettings { set { UserDefaults.standard.set(newValue.rawValue, forKey: "voice.readAloud") } } + /// The speaker button in the Ask bar. Kept across launches: somebody who + /// muted the app in a shared office wants it still muted tomorrow. + /// + /// Anybody who had chosen "Never" before the button existed starts muted, + /// which is what that choice meant. + static var muted: Bool { + get { + if let set = UserDefaults.standard.object(forKey: "voice.muted") as? Bool { return set } + return UserDefaults.standard.string(forKey: "voice.readAloud") == "never" + } + set { UserDefaults.standard.set(newValue, forKey: "voice.muted") } + } + /// Whether holding space in an empty Ask field dictates. On by default: it /// only ever acts where a space would have done nothing useful. static var holdSpace: Bool {