Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

voice: English by default, ElevenLabs voices, real emails in Apple Mail

Claude96b68e306b3e
diff --git a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
index c92e9e6e..67891a6c 100644
--- a/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
+++ b/NotchBuddy/NotchBuddy.xcodeproj/project.pbxproj
@@ -71,6 +71,8 @@
326971DDA23F331116E5A628 /* VoiceBrain.swift in Sources */ = {isa = PBXBuildFile; fileRef = C563E55884A7750B40EC9A01 /* VoiceBrain.swift */; };
3451DB0668FAEEF09503D808 /* WakePhrase.swift in Sources */ = {isa = PBXBuildFile; fileRef = A12EC8F605BBC37F8223D7AA /* WakePhrase.swift */; };
36EBFB9A047DEBAC43E5D0CC /* VoiceCaptionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8FB03801C49690C3789EFD /* VoiceCaptionManager.swift */; };
+ 6D21DDD51A255B1E3061D81F /* ElevenLabsTTS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE24076E9F3476A814C87964 /* ElevenLabsTTS.swift */; };
+ 34B22D329FA5D24C00A6EF91 /* ElevenLabsTTS.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE24076E9F3476A814C87964 /* ElevenLabsTTS.swift */; };
D08B378612B4CB0C8811925B /* VoiceDataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2C300BDBDD5FB8403291892 /* VoiceDataSources.swift */; };
A51E53A7BF9F23535F3A8B15 /* VoiceDataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = F2C300BDBDD5FB8403291892 /* VoiceDataSources.swift */; };
968932802E8017E2C23FF473 /* VoiceQuery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62762B5BCD2B2209EAF89A7A /* VoiceQuery.swift */; };
@@ -387,6 +389,7 @@
38BEAB5F20A13E5806A42EC9 /* ApprovalCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApprovalCard.swift; sourceTree = "<group>"; };
3A27178AA6007F7B56901750 /* SessionDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionDetailView.swift; sourceTree = "<group>"; };
3A8FB03801C49690C3789EFD /* VoiceCaptionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceCaptionManager.swift; sourceTree = "<group>"; };
+ DE24076E9F3476A814C87964 /* ElevenLabsTTS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElevenLabsTTS.swift; sourceTree = "<group>"; };
F2C300BDBDD5FB8403291892 /* VoiceDataSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceDataSources.swift; sourceTree = "<group>"; };
62762B5BCD2B2209EAF89A7A /* VoiceQuery.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VoiceQuery.swift; sourceTree = "<group>"; };
3B238F6E7B20EFDED5CD3E8E /* ClaudeSettingsFile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClaudeSettingsFile.swift; sourceTree = "<group>"; };
@@ -737,6 +740,7 @@
A87F39805C78722F614295B4 /* VoiceAudio.swift */,
C563E55884A7750B40EC9A01 /* VoiceBrain.swift */,
3A8FB03801C49690C3789EFD /* VoiceCaptionManager.swift */,
+ DE24076E9F3476A814C87964 /* ElevenLabsTTS.swift */,
F2C300BDBDD5FB8403291892 /* VoiceDataSources.swift */,
62762B5BCD2B2209EAF89A7A /* VoiceQuery.swift */,
B328028D18F590D6680B8A2B /* VoiceEngine.swift */,
@@ -1050,6 +1054,7 @@
88A8F2E4E754FAFABF6B1960 /* VoiceAudio.swift in Sources */,
326971DDA23F331116E5A628 /* VoiceBrain.swift in Sources */,
525FB188F09F68D26A9D587D /* VoiceCaptionManager.swift in Sources */,
+ 6D21DDD51A255B1E3061D81F /* ElevenLabsTTS.swift in Sources */,
D08B378612B4CB0C8811925B /* VoiceDataSources.swift in Sources */,
968932802E8017E2C23FF473 /* VoiceQuery.swift in Sources */,
BDEFF4223DA949E2B8AB85A7 /* VoiceEngine.swift in Sources */,
@@ -1239,6 +1244,7 @@
64FE8055CCAD30B44FE398E7 /* VoiceAudio.swift in Sources */,
273B404F55739D661D9489D8 /* VoiceBrain.swift in Sources */,
36EBFB9A047DEBAC43E5D0CC /* VoiceCaptionManager.swift in Sources */,
+ 34B22D329FA5D24C00A6EF91 /* ElevenLabsTTS.swift in Sources */,
A51E53A7BF9F23535F3A8B15 /* VoiceDataSources.swift in Sources */,
EEDE0A39D216069D77F097C8 /* VoiceQuery.swift in Sources */,
80B0B3C777A9DC8C82952FD2 /* VoiceEngine.swift in Sources */,
diff --git a/NotchBuddy/Resources/Localizable.xcstrings b/NotchBuddy/Resources/Localizable.xcstrings
index 57b3b551..6ae6b38b 100644
--- a/NotchBuddy/Resources/Localizable.xcstrings
+++ b/NotchBuddy/Resources/Localizable.xcstrings
@@ -24971,6 +24971,591 @@
}
}
}
+ },
+ "voice.language": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "لغة الصوت"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "কণ্ঠের ভাষা"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voice language"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Idioma de la voz"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Langue de la voix"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "आवाज़ की भाषा"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Bahasa suara"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Idioma da voz"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Язык голоса"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "语音语言"
+ }
+ }
+ }
+ },
+ "voice.tts-engine": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "الصوت"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "কণ্ঠ"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voice"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voz"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voix"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "आवाज़"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Suara"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voz"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Голос"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "声音"
+ }
+ }
+ }
+ },
+ "voice.tts-system": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "صوت الماك"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mac-এর কণ্ঠ"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mac voice"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voz del Mac"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voix du Mac"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mac की आवाज़"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Suara Mac"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voz do Mac"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Голос Mac"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mac 语音"
+ }
+ }
+ }
+ },
+ "voice.tts-key": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "مفتاح ElevenLabs API"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ElevenLabs API কী"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ElevenLabs API key"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Clave API de ElevenLabs"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Clé API ElevenLabs"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ElevenLabs API कुंजी"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Kunci API ElevenLabs"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Chave de API ElevenLabs"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "API-ключ ElevenLabs"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "ElevenLabs API 密钥"
+ }
+ }
+ }
+ },
+ "voice.tts-key-saved": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "المفتاح محفوظ في سلسلة المفاتيح"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "কী কিচেইনে সংরক্ষিত"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Key saved in Keychain"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Clave guardada en el llavero"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Clé enregistrée dans le Trousseau"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "कुंजी कीचेन में सहेजी गई"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Kunci tersimpan di Keychain"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Chave salva nas Chaves"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Ключ сохранён в Связке ключей"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "密钥已存入钥匙串"
+ }
+ }
+ }
+ },
+ "voice.tts-gender": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "نوع الصوت"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "কণ্ঠের ধরন"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Voice type"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tipo de voz"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Type de voix"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "आवाज़ का प्रकार"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Jenis suara"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tipo de voz"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Тип голоса"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "声音类型"
+ }
+ }
+ }
+ },
+ "voice.tts-female": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "امرأة"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "নারী"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Woman"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mujer"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Femme"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "महिला"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Wanita"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Mulher"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Женский"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "女声"
+ }
+ }
+ }
+ },
+ "voice.tts-male": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "رجل"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "পুরুষ"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Man"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Hombre"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Homme"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "पुरुष"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Pria"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Homem"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Мужской"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "男声"
+ }
+ }
+ }
+ },
+ "voice.tts-test": {
+ "extractionState": "manual",
+ "localizations": {
+ "ar": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "جرّب الصوت"
+ }
+ },
+ "bn": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "কণ্ঠ পরীক্ষা"
+ }
+ },
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Test the voice"
+ }
+ },
+ "es": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Probar la voz"
+ }
+ },
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Tester la voix"
+ }
+ },
+ "hi": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "आवाज़ आज़माएँ"
+ }
+ },
+ "id": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Coba suara"
+ }
+ },
+ "pt-BR": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Testar a voz"
+ }
+ },
+ "ru": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Проверить голос"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "试听声音"
+ }
+ }
+ }
}
},
"version": "1.0"
diff --git a/NotchBuddy/Sources/App/ClaudeService.swift b/NotchBuddy/Sources/App/ClaudeService.swift
index 6eb6905b..ebedc0f9 100644
--- a/NotchBuddy/Sources/App/ClaudeService.swift
+++ b/NotchBuddy/Sources/App/ClaudeService.swift
@@ -71,6 +71,7 @@ final class KeychainStore: @unchecked Sendable {
"stripe-api-key",
"calcom-api-key",
"notion-api-key",
+ "elevenlabs-api-key",
]
private init() {
diff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swift
index f24f5829..544444ed 100644
--- a/NotchBuddy/Sources/App/SettingsView.swift
+++ b/NotchBuddy/Sources/App/SettingsView.swift
@@ -1262,6 +1262,11 @@ struct SettingsView: View {
@AppStorage("voiceCaptionEnabled") private var captionEnabled: Bool = true
@AppStorage("voiceWeatherEnabled") private var weatherEnabled: Bool = false
@AppStorage("voiceWeatherCity") private var weatherCity: String = ""
+ @AppStorage("voiceLanguage") private var voiceLanguage: String = "en"
+ @AppStorage("voiceTTSEngine") private var ttsEngine: String = "system"
+ @AppStorage("voiceElevenGender") private var elevenGender: String = "female"
+ @State private var elevenKeyDraft: String = ""
+ @State private var elevenKeySaved: Bool = KeychainStore.shared.get(ElevenLabsTTS.keyName) != nil
@ViewBuilder private var voiceSection: some View {
GroupBox(String(localized: "«\u{202F}OK Coucou\u{202F}» — voice wake word")) {
@@ -1269,8 +1274,55 @@ struct SettingsView: View {
Toggle(String(localized: "Enable voice command"), isOn: $voiceEngine.isEnabled)
.disabled(!voicePermissionsGranted && !voiceEngine.isEnabled)
+ Picker(String(localized: "voice.language"), selection: $voiceLanguage) {
+ Text(verbatim: "English").tag("en")
+ Text(verbatim: "Français").tag("fr")
+ }
+ .frame(maxWidth: 260)
+ .onChange(of: voiceLanguage) { _, _ in VoiceEngine.shared.reloadLanguage() }
+
Toggle(String(localized: "voice.setting-speak"), isOn: $speakEnabled)
+ if speakEnabled {
+ Picker(String(localized: "voice.tts-engine"), selection: $ttsEngine) {
+ Text(String(localized: "voice.tts-system")).tag("system")
+ Text(verbatim: "ElevenLabs").tag("elevenlabs")
+ }
+ .frame(maxWidth: 260)
+
+ if ttsEngine == "elevenlabs" {
+ HStack(spacing: 6) {
+ SecureField(elevenKeySaved ? String(localized: "voice.tts-key-saved")
+ : String(localized: "voice.tts-key"),
+ text: $elevenKeyDraft)
+ .textFieldStyle(.roundedBorder)
+ .frame(maxWidth: 220)
+ Button(String(localized: "Save")) {
+ let k = elevenKeyDraft.trimmingCharacters(in: .whitespacesAndNewlines)
+ if k.isEmpty { KeychainStore.shared.remove(ElevenLabsTTS.keyName) }
+ else { KeychainStore.shared.set(ElevenLabsTTS.keyName, value: k) }
+ elevenKeyDraft = ""
+ elevenKeySaved = !k.isEmpty
+ ElevenLabsTTS.shared.reset()
+ }
+ }
+ Picker(String(localized: "voice.tts-gender"), selection: $elevenGender) {
+ Text(String(localized: "voice.tts-female")).tag("female")
+ Text(String(localized: "voice.tts-male")).tag("male")
+ }
+ .pickerStyle(.segmented)
+ .frame(maxWidth: 220)
+ .onChange(of: elevenGender) { _, _ in ElevenLabsTTS.shared.reset() }
+ }
+
+ Button(String(localized: "voice.tts-test")) {
+ let en = voiceLanguage != "fr"
+ VoiceSpeaker.shared.speak(en ? "Hi, I'm Coucou. Say OK Coucou whenever you need me."
+ : "Salut, c'est Coucou. Dis OK Coucou quand tu as besoin de moi.",
+ locale: Locale(identifier: en ? "en-US" : "fr-FR"))
+ }
+ }
+
Toggle(String(localized: "voice.setting-captions"), isOn: $captionEnabled)
Toggle(String(localized: "voice.setting-weather"), isOn: $weatherEnabled)
diff --git a/NotchBuddy/Sources/App/Voice/ElevenLabsTTS.swift b/NotchBuddy/Sources/App/Voice/ElevenLabsTTS.swift
new file mode 100644
index 00000000..6f11467b
--- /dev/null
+++ b/NotchBuddy/Sources/App/Voice/ElevenLabsTTS.swift
@@ -0,0 +1,89 @@
+#if !APPSTORE
+import Foundation
+
+// MARK: - ElevenLabsTTS
+//
+// Optional voice for Coucou's answers (Settings → Voice → ElevenLabs), with the user's
+// own API key stored in the Keychain ("elevenlabs-api-key"). Network only to
+// api.elevenlabs.io, only while Coucou speaks.
+//
+// No voice ID is hard-coded: ElevenLabs' old default voices expire on 31 Dec 2026 and
+// newer accounts don't have them. Coucou lists the voices of the user's account and
+// picks the first English one of the chosen gender (female by default), then caches it.
+
+@MainActor
+final class ElevenLabsTTS {
+ static let shared = ElevenLabsTTS()
+
+ static let keyName = "elevenlabs-api-key"
+ private static let model = "eleven_flash_v2_5" // low-latency model
+
+ static var isActive: Bool {
+ VoiceSettings.ttsEngine == "elevenlabs" && KeychainStore.shared.get(keyName) != nil
+ }
+
+ struct Voice: Equatable { let id: String; let name: String }
+ private var chosen: (gender: String, voice: Voice)?
+
+ /// Name of the voice in use, for Settings ("Rachel", "Talia – Warm Soft Guide"…).
+ var currentVoiceName: String? { chosen?.voice.name }
+
+ /// Forget the cached voice (gender or key changed).
+ func reset() { chosen = nil }
+
+ /// MP3 for one sentence, or nil (no key, network error, quota…) → Mac voice instead.
+ func audio(for text: String) async -> Data? {
+ guard let key = KeychainStore.shared.get(Self.keyName),
+ let voice = await voice(key: key) else { return nil }
+ var comps = URLComponents(string: "https://api.elevenlabs.io/v1/text-to-speech/\(voice.id)")!
+ comps.queryItems = [URLQueryItem(name: "output_format", value: "mp3_44100_128")]
+ guard let url = comps.url else { return nil }
+ var req = URLRequest(url: url, timeoutInterval: 8)
+ req.httpMethod = "POST"
+ req.setValue(key, forHTTPHeaderField: "xi-api-key")
+ req.setValue("application/json", forHTTPHeaderField: "Content-Type")
+ req.setValue("audio/mpeg", forHTTPHeaderField: "Accept")
+ req.httpBody = try? JSONSerialization.data(withJSONObject: ["text": text, "model_id": Self.model])
+ guard let (data, resp) = try? await URLSession.shared.data(for: req),
+ (resp as? HTTPURLResponse)?.statusCode == 200, !data.isEmpty else {
+ appendAppLog("nb.log", "[Voice] ElevenLabs request failed, Mac voice used")
+ return nil
+ }
+ return data
+ }
+
+ /// The voice for the chosen gender, looked up once in the user's account.
+ func voice(key: String) async -> Voice? {
+ let gender = VoiceSettings.elevenGender
+ if let c = chosen, c.gender == gender { return c.voice }
+ var req = URLRequest(url: URL(string: "https://api.elevenlabs.io/v1/voices")!, timeoutInterval: 8)
+ req.setValue(key, forHTTPHeaderField: "xi-api-key")
+ guard let (data, resp) = try? await URLSession.shared.data(for: req),
+ (resp as? HTTPURLResponse)?.statusCode == 200,
+ let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
+ let voices = json["voices"] as? [[String: Any]] else {
+ appendAppLog("nb.log", "[Voice] ElevenLabs voice list unavailable")
+ return nil
+ }
+ guard let v = Self.pick(voices, gender: gender) else { return nil }
+ chosen = (gender, v)
+ return v
+ }
+
+ /// First English voice of the gender; else any voice of the gender; else the first one.
+ nonisolated static func pick(_ voices: [[String: Any]], gender: String) -> Voice? {
+ func labels(_ v: [String: Any]) -> [String: String] { v["labels"] as? [String: String] ?? [:] }
+ func isEnglish(_ v: [String: Any]) -> Bool {
+ let l = labels(v)
+ if let lang = l["language"] { return lang.lowercased().hasPrefix("en") }
+ let accent = (l["accent"] ?? "").lowercased()
+ return accent.isEmpty || ["american", "british", "australian", "irish", "english", "us", "uk"]
+ .contains { accent.contains($0) }
+ }
+ let ofGender = voices.filter { labels($0)["gender"]?.lowercased() == gender }
+ let v = ofGender.first(where: isEnglish) ?? ofGender.first ?? voices.first
+ guard let v, let id = v["voice_id"] as? String else { return nil }
+ return Voice(id: id, name: v["name"] as? String ?? id)
+ }
+}
+#endif
diff --git a/NotchBuddy/Sources/App/Voice/EntityResolver.swift b/NotchBuddy/Sources/App/Voice/EntityResolver.swift
index 55f3bb85..952855aa 100644
--- a/NotchBuddy/Sources/App/Voice/EntityResolver.swift
+++ b/NotchBuddy/Sources/App/Voice/EntityResolver.swift
@@ -16,6 +16,16 @@ enum EntityResolver {
// VS Code pill is the Claude Code integration
"claude": "integration_claude",
"claude code": "integration_claude",
+ // How speech recognition writes "VS Code" (FR and EN)
+ "vs code": "integration_claude",
+ "vscode": "integration_claude",
+ "v s code": "integration_claude",
+ "visual studio code": "integration_claude",
+ "visual studio": "integration_claude",
+ "ves code": "integration_claude",
+ "vee s code": "integration_claude",
+ "vi s code": "integration_claude",
+ "vsco": "integration_claude",
// Agents
"gemini": "agent_gemini",
"copilot": "agent_copilot",
diff --git a/NotchBuddy/Sources/App/Voice/IntentParser.swift b/NotchBuddy/Sources/App/Voice/IntentParser.swift
index cd34f44b..6d72cb99 100644
--- a/NotchBuddy/Sources/App/Voice/IntentParser.swift
+++ b/NotchBuddy/Sources/App/Voice/IntentParser.swift
@@ -163,10 +163,26 @@ enum IntentParser {
// "lance ma playlist" with no name: the runner asks which one.
return .musicPlayPlaylist(name: "")
}
- // "tu peux lancer ma playlist" (the trigger needs a name after it): ask which one.
+ // "tu peux lancer ma playlist" / "play my Focus playlist" (English puts the name
+ // before the word): take what sits between the verb and "playlist", or ask.
if fwords.last == "playlist" || fwords.last == "playlists",
- fwords.contains(where: { ["lance", "mets", "met", "joue", "balance", "play", "start"].contains($0) }) {
- return .musicPlayPlaylist(name: "")
+ let v = fwords.firstIndex(where: { ["lance", "mets", "met", "joue", "balance", "play", "start"].contains($0) }) {
+ let fillers: Set<String> = ["my", "the", "a", "la", "le", "les", "ma", "mon", "une", "un"]
+ let between = (v + 1)..<(fwords.count - 1)
+ let name = between.filter { !fillers.contains(fwords[$0]) }
+ .map { $0 < frawWords.count ? frawWords[$0] : fwords[$0] }
+ .joined(separator: " ")
+ return .musicPlayPlaylist(name: name)
+ }
+
+ // "make Cursor my main pill", "set Cursor as main pill", "switch the main pill to Cursor"
+ if fwords.contains("main") && (fwords.contains("pill") || fwords.contains("pilule")) {
+ let noise: Set<String> = ["make", "set", "as", "my", "the", "main", "pill", "to", "switch", "change",
+ "use", "put", "is", "be", "should", "please", "now"]
+ let rest = fwords.filter { !noise.contains($0) }.joined(separator: " ")
+ if !rest.isEmpty, let id = EntityResolver.resolve(rest, from: pills, category: .workspace) {
+ return .pillSetMain(id: id)
+ }
}
// ── 8. pillMain triggers (setMain-only verbs) ────────────────────────
diff --git a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
index 1b10f0d1..5b9d81e2 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceBrain.swift
@@ -108,6 +108,54 @@ final class VoiceBrain {
return .notMacOS26
}
+ /// Instructions in the language Coucou speaks (Settings → Voice, English by default).
+ static func instructions() -> String {
+ if VoiceSettings.language == "fr" {
+ return """
+ Tu es Coucou, un assistant dans le notch du MacBook. Réponds toujours en français.
+ Réponds avec 1 à 2 phrases maximum. Sois direct et concis.
+ Ne pose une question que si tu as vraiment besoin d'une précision pour agir : une seule, courte, qui finit par « ? ». Sinon, ne finis jamais par une question.
+ Utilise les outils pour les pilules et la musique.
+ Pour toute question sur Stripe, GitHub, Vercel, Resend, n8n, Notion, Cal.com, les agents (Claude Code, Codex…), le plan Claude ou Codex, la musique ou la météo, appelle d'abord l'outil service et réponds avec ses données, sans rien inventer.
+ Pour un mail, appelle l'outil mail : il prépare le mail dans Mail, c'est l'utilisateur qui clique sur Envoyer. Si on te demande de l'écrire, rédige toi-même le texte.
+ Pour les noms de pilules, utilise le nom exact fourni par l'utilisateur.
+ """
+ }
+ return """
+ You are Coucou, an assistant living in the MacBook notch. Always answer in English.
+ Answer in one or two short sentences. Be direct.
+ Only ask a question when you truly need a detail to act: one short question ending with "?". Otherwise never end with a question.
+ Use the tools for pills and music.
+ For any question about Stripe, GitHub, Vercel, Resend, n8n, Notion, Cal.com, agents (Claude Code, Codex…), the Claude or Codex plan, music or the weather, call the service tool first and answer from its data, never invent.
+ For an email, call the mail tool: it prepares the email in Mail and the user clicks Send. When asked to write it, write the text yourself.
+ For pill names, use the exact name the user said.
+ """
+ }
+
+ /// A short email body written by the on-device model from an instruction
+ /// ("thanking her for yesterday"). nil when the model is unavailable.
+ static func draftMail(to recipient: String, about instruction: String) async -> String? {
+ #if canImport(FoundationModels)
+ if #available(macOS 26, *) {
+ guard SystemLanguageModel.default.availability == .available else { return nil }
+ let fr = VoiceSettings.language == "fr"
+ let session = LanguageModelSession(instructions: fr
+ ? "Tu écris des mails courts et naturels, sans objet ni signature, 2 à 4 phrases."
+ : "You write short, natural emails without a subject line or signature, 2 to 4 sentences.")
+ let prompt = fr ? "Écris le mail à \(recipient) : \(instruction)"
+ : "Write the email to \(recipient): \(instruction)"
+ // Boxed like the conversation session: the timeout closure must be Sendable.
+ let box = SessionContainer(session: session, collector: IntentCollector())
+ do {
+ return try await withBrainTimeout(seconds: 8) {
+ try await box.session.respond(to: prompt).content
+ }
+ } catch { return nil }
+ }
+ #endif
+ return nil
+ }
+
static func _makeSession() -> AnyObject? {
#if canImport(FoundationModels)
if #available(macOS 26, *) {
@@ -117,16 +165,9 @@ final class VoiceBrain {
tools: [PillTool(collector: collector),
MusicTool(collector: collector),
StatusTool(collector: collector),
- ServiceTool()],
- instructions: """
- Tu es Coucou, un assistant dans le notch du MacBook.
- Réponds toujours dans la langue de l'utilisateur.
- Réponds avec 1 à 2 phrases maximum. Sois direct et concis.
- Ne pose une question que si tu as vraiment besoin d'une précision pour agir : une seule, courte, qui finit par « ? ». Sinon, ne finis jamais par une question.
- Utilise les outils disponibles pour exécuter des commandes sur les pills et la musique.
- Pour toute question sur Stripe, GitHub, Vercel, Resend, n8n, Notion, Cal.com, les agents (Claude Code, Codex…), le plan Claude ou Codex, la musique ou la météo, appelle d'abord l'outil service et réponds avec ses données, sans rien inventer.
- Pour les noms de pilules, utilise le nom exact fourni par l'utilisateur.
- """
+ ServiceTool(),
+ MailTool(collector: collector)],
+ instructions: VoiceBrain.instructions()
)
let container = SessionContainer(session: session, collector: collector)
// Prewarm in background — warms the attention cache without blocking the caller.
@@ -366,6 +407,34 @@ struct MusicTool: Tool, @unchecked Sendable {
// MARK: StatusTool
+@available(macOS 26, *)
+struct MailTool: Tool, @unchecked Sendable {
+ let name = "mail"
+ let description = "Prepare an email in Apple Mail (the user clicks Send). Recipient is a contact name or an email address; file is an optional file name to attach (searched in Downloads, Desktop, Documents, Pictures)."
+
+ @Generable
+ struct Arguments {
+ @Guide(description: "Contact name or email address")
+ var recipient: String
+ @Guide(description: "File name to attach, or empty")
+ var file: String
+ @Guide(description: "Subject line, or empty")
+ var subject: String
+ @Guide(description: "Full email body written for the user, or empty")
+ var body: String
+ }
+
+ let collector: IntentCollector
+
+ func call(arguments: Arguments) async throws -> String {
+ func opt(_ s: String) -> String? { s.trimmingCharacters(in: .whitespaces).isEmpty ? nil : s }
+ let recipient = VoiceQuery.spokenEmail(arguments.recipient) ?? arguments.recipient
+ collector.append(.mail(VoiceQuery.MailRequest(recipient: recipient, file: opt(arguments.file), folder: nil,
+ subject: opt(arguments.subject), body: opt(arguments.body))))
+ return "mail prepared for \(recipient)"
+ }
+}
+
@available(macOS 26, *)
struct ServiceTool: Tool, @unchecked Sendable {
let name = "service"
@@ -381,7 +450,7 @@ struct ServiceTool: Tool, @unchecked Sendable {
guard let topic = VoiceTopic(rawValue: arguments.topic) else {
return "unknown topic: \(arguments.topic)"
}
- return await LiveVoiceInfo.shared.answer(topic, locale: nil)
+ return await LiveVoiceInfo.shared.answer(topic, locale: Locale(identifier: VoiceSettings.language == "fr" ? "fr-FR" : "en-US"))
}
}
diff --git a/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift b/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift
index 91127900..c13eeeb8 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceCaptionManager.swift
@@ -204,7 +204,10 @@ struct VoiceCaptionView: View {
/// While the mic is open: what I am saying, live. Afterwards: what I said + the answer.
private var heard: String {
guard state.isListening else { return state.userLine }
- return state.liveLine.isEmpty ? String(localized: "voice.caption-listening") : state.liveLine
+ // In the language Coucou speaks, not the interface language.
+ return state.liveLine.isEmpty
+ ? VoiceActionRunner.localizedString("voice.caption-listening", locale: VoiceEngine.shared.speechLocale)
+ : state.liveLine
}
private var answer: String { state.isListening ? "" : state.responseLine }
diff --git a/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift b/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift
index e65e9f7e..b8a87cf2 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceDataSources.swift
@@ -184,21 +184,35 @@ final class LiveVoiceInfo: VoiceInfoProviding {
}
}
- if let fileURL, let service = NSSharingService(named: .composeEmail) {
- service.recipients = [address]
- service.subject = fileURL.deletingPathExtension().lastPathComponent
- service.perform(withItems: [fileURL])
- return .init(outcome: .success,
- message: t("Mail prêt pour \(request.recipient) avec \(fileURL.lastPathComponent). Tu n'as plus qu'à cliquer sur Envoyer.",
- "Email to \(request.recipient) with \(fileURL.lastPathComponent) is ready. Just click Send."))
+ // Body: dictated, or written by Coucou from what the mail should say.
+ var body = request.body
+ if body == nil, let what = request.instruction {
+ body = await VoiceBrain.draftMail(to: request.recipient, about: what) ?? what
}
- guard let url = URL(string: "mailto:\(address)") else {
- return .init(outcome: .failure, message: t("Je n'arrive pas à ouvrir Mail.", "I can't open Mail."))
+ let subject = request.subject ?? fileURL?.deletingPathExtension().lastPathComponent ?? ""
+
+ var items: [Any] = []
+ if let body { items.append(body) }
+ if let fileURL { items.append(fileURL) }
+ if !items.isEmpty, let service = NSSharingService(named: .composeEmail) {
+ service.recipients = [address]
+ service.subject = subject
+ service.perform(withItems: items)
+ } else {
+ var comps = URLComponents()
+ comps.scheme = "mailto"
+ comps.path = address
+ comps.queryItems = [URLQueryItem(name: "subject", value: subject),
+ URLQueryItem(name: "body", value: body ?? "")]
+ guard let url = comps.url else {
+ return .init(outcome: .failure, message: t("Je n'arrive pas à ouvrir Mail.", "I can't open Mail."))
+ }
+ NSWorkspace.shared.open(url)
}
- NSWorkspace.shared.open(url)
+ let what = fileURL.map { t(" avec \($0.lastPathComponent)", " with \($0.lastPathComponent)") } ?? ""
return .init(outcome: .success,
- message: t("Mail prêt pour \(request.recipient). Écris ton message et clique sur Envoyer.",
- "Email to \(request.recipient) is ready. Write it and click Send."))
+ message: t("Le mail pour \(request.recipient)\(what) est prêt dans Mail. Relis-le et clique sur Envoyer.",
+ "The email to \(request.recipient)\(what) is ready in Mail. Check it and click Send."))
}
// MARK: Apps
@@ -341,7 +355,8 @@ enum FileLookup {
case .downloads: dirs = [.downloadsDirectory]
case .desktop: dirs = [.desktopDirectory]
case .documents: dirs = [.documentDirectory]
- case nil: dirs = [.downloadsDirectory, .desktopDirectory, .documentDirectory]
+ case .pictures: dirs = [.picturesDirectory]
+ case nil: dirs = [.downloadsDirectory, .desktopDirectory, .documentDirectory, .picturesDirectory]
}
let wanted = IntentParser.normalise(query).split(separator: " ").map(String.init)
guard !wanted.isEmpty else { return nil }
@@ -353,7 +368,8 @@ enum FileLookup {
for case let url as URL in e {
if e.level > 2 { e.skipDescendants(); continue }
guard (try? url.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile) == true else { continue }
- let name = IntentParser.normalise(url.deletingPathExtension().lastPathComponent)
+ // "Goku.png" normalises to "gokupng": compare with the full file name too.
+ let name = IntentParser.normalise(url.lastPathComponent)
let ext = url.pathExtension.lowercased()
let ok = wanted.allSatisfy { w in name.contains(w) || ext == w }
guard ok else { continue }
diff --git a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
index 6f00db4b..86d5b302 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceEngine.swift
@@ -126,6 +126,14 @@ final class VoiceEngine: ObservableObject {
func cancelListening() { endCommand(postFinished: false) }
+ /// Settings → Voice language changed: restart recognition in the new language.
+ func reloadLanguage() {
+ guard audio != nil else { return }
+ stopAudioPipeline()
+ if isEnabled && !isPaused { startAudioPipeline() }
+ VoiceBrain.shared.endConversation() // next session gets instructions in the new language
+ }
+
/// Start the next conversation turn (re-listen for 8 s without wake phrase).
/// Called by IslandWindowController after showing a command result.
func startConversationTurn() {
@@ -656,8 +664,13 @@ final class VoiceEngine: ObservableObject {
// MARK: - Helpers
private func suitableLocale() -> Locale? {
- var candidates = MacDictation.automaticLocales()
- candidates += [Locale(identifier: "fr-FR"), Locale(identifier: "en-US")]
+ // The language chosen in Settings → Voice first (English by default), then the
+ // dictation languages, then the usual fallbacks.
+ var candidates: [Locale] = VoiceSettings.language == "fr"
+ ? [Locale(identifier: "fr-FR"), Locale(identifier: "fr-CA")]
+ : [Locale(identifier: "en-US"), Locale(identifier: "en-GB"), Locale(identifier: "en-AU")]
+ candidates += MacDictation.automaticLocales()
+ candidates += [Locale(identifier: "en-US"), Locale(identifier: "fr-FR")]
for locale in candidates {
if let r = SFSpeechRecognizer(locale: locale),
r.supportsOnDeviceRecognition, r.isAvailable {
diff --git a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift b/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
index 3cf3b4a3..268d4053 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceQuery.swift
@@ -58,7 +58,8 @@ enum VoiceQuery {
if hasAny(["quota", "limite", "limites", "forfait", "usage", "plan"]) {
return has("codex") ? .codexPlan : .claudePlan
}
- if hasAny(["claude", "codex", "cursor", "gemini", "copilot", "agent", "agents",
+ if hasAny(["claude", "codex", "cursor", "gemini", "copilot", "vs code", "vscode", "visual studio",
+ "agent", "agents",
"session", "sessions", "qu est ce qui se passe", "ou en est", "il fait quoi",
"what s happening", "whats happening"]) { return .agents }
// Generic words.
@@ -68,7 +69,11 @@ enum VoiceQuery {
if hasAny(["etoile", "etoiles", "star", "stars", "pull request", "pull requests", "pr", "prs",
"repo", "repos", "ci"]) { return .github }
if hasAny(["deploiement", "deploiements", "deploy", "deploye", "deployment", "push", "pousse"]) { return .vercel }
- if hasAny(["mail", "mails", "email", "emails"]) { return .resend }
+ // Generic "mails" means Resend stats only when asking about sent mail.
+ if hasAny(["mail", "mails", "email", "emails"]),
+ hasAny(["combien", "how many", "derniers", "dernier", "last", "envoyes", "envoye", "sent", "delivres", "delivered"]) {
+ return .resend
+ }
if hasAny(["chanson", "musique", "titre", "morceau", "song", "track", "playing", "ecoute"]) { return .music }
if hasAny(["pilule", "pilules", "pill", "pills"]) { return .pills }
return nil
@@ -85,52 +90,178 @@ enum VoiceQuery {
"ajoute", "ajouter", "ajoutes", "rajoute", "enleve", "enlever", "enleves", "retire", "retirer",
"supprime", "supprimer", "mets", "mettre", "met", "lance", "lancer", "joue", "jouer",
"remplace", "remplacer", "active", "activer", "desactive", "vire", "virer",
- "envoie", "envoyer", "ouvre", "ouvrir", "add", "remove", "play", "open", "send",
+ "envoie", "envoyer", "envoies", "ecris", "ecrire", "redige", "rediger", "ouvre", "ouvrir",
+ "add", "remove", "play", "open", "send", "write", "compose", "draft", "email",
]
- // MARK: Email: "envoie un mail à Tana", "envoie le fichier facture des téléchargements à Tana"
+ // MARK: Email
+ //
+ // "envoie un mail à Tana"
+ // "envoie le fichier facture octobre des téléchargements à Tana"
+ // "il y a une image qui s'appelle Goku.png, envoie-la par mail à [email protected].
+ // En objet, tu écris : Voilà votre image. En description : Image en 1980 × 1080."
+ // "email the image called Goku.png to [email protected], subject Here you go, body …"
+ // "write an email to Tana thanking her for yesterday" (instruction → Coucou drafts)
struct MailRequest: Equatable {
var recipient: String
var file: String?
var folder: Folder?
- enum Folder: String, Equatable { case downloads, desktop, documents }
+ var subject: String? = nil
+ var body: String? = nil
+ /// What the mail should say when no body was dictated ("thanking her…"):
+ /// Coucou drafts the body from it.
+ var instruction: String? = nil
+ enum Folder: String, Equatable { case downloads, desktop, documents, pictures }
}
+ private static let sendVerbs: Set<String> = [
+ "envoie", "envoyer", "envoies", "envoyes", "ecris", "ecrire", "ecrit", "redige", "rediger",
+ "send", "email", "mail", "write", "compose", "draft",
+ ]
+ private static let mailWords: Set<String> = ["mail", "email", "mel", "courriel", "emails", "mails"]
+ private static let fileWords: Set<String> = ["fichier", "image", "photo", "document", "pdf", "file",
+ "picture", "screenshot", "capture", "video"]
+ private static let subjectMarkers = ["en objet", "comme objet", "avec l'objet", "avec pour objet", "objet",
+ "en titre", "sujet", "with the subject", "subject", "titled"]
+ private static let bodyMarkers = ["en description", "description", "corps du mail", "en texte", "avec le texte",
+ "pour lui dire que", "pour lui dire", "pour dire que", "en disant que",
+ "en disant", "qui dit", "with the text", "body", "saying that", "saying",
+ "that says", "to say that", "to say", "telling"]
+
static func mail(of raw: String) -> MailRequest? {
- let norm = IntentParser.normalise(raw)
- let n = norm.split(separator: " ").map(String.init)
- let r = rawWords(raw)
- guard n.count == r.count, !n.isEmpty else { return nil }
- let sendVerbs: Set<String> = ["envoie", "envoyer", "envoies", "ecris", "ecrire", "send", "email", "mail"]
- guard let v = n.firstIndex(where: { sendVerbs.contains($0) }) else { return nil }
- let rest = Array(n[(v + 1)...])
- let isMail = rest.contains(where: { ["mail", "email", "mel", "courriel", "fichier", "file", "document", "pdf"].contains($0) })
- || ["email", "mail"].contains(n[v])
- guard isMail else { return nil }
- // Recipient: after the last "à" / "to".
+ // 1. Subject and body are free text: cut them out of the raw string first.
+ let subj = firstMarker(subjectMarkers, in: raw)
+ let body = firstMarker(bodyMarkers, in: raw)
+ let cut = [subj?.range.lowerBound, body?.range.lowerBound].compactMap { $0 }.min() ?? raw.endIndex
+ let head = String(raw[..<cut])
+ func segment(_ m: (range: Range<String.Index>, marker: String)?, other: (range: Range<String.Index>, marker: String)?) -> String? {
+ guard let m else { return nil }
+ var end = raw.endIndex
+ if let o = other, o.range.lowerBound > m.range.lowerBound { end = o.range.lowerBound }
+ return cleanFreeText(String(raw[m.range.upperBound..<end]))
+ }
+ let subject = segment(subj, other: body)
+ let bodyText = segment(body, other: subj)
+
+ // 2. Verb, recipient, file and folder from the head.
+ let n = IntentParser.normalise(head).split(separator: " ").map(String.init)
+ let r = rawWords(head)
+ guard n.count == r.count, !n.isEmpty,
+ let v = n.firstIndex(where: { sendVerbs.contains($0) }) else { return nil }
+ let isMail = n.contains(where: { mailWords.contains($0) }) || ["email", "mail"].contains(n[v])
+ guard isMail || n.contains(where: { fileWords.contains($0) }) else { return nil }
+
guard let to = n.lastIndex(where: { $0 == "a" || $0 == "to" }), to > v, to + 1 < n.count else { return nil }
- let recipient = r[(to + 1)...].joined(separator: " ")
+ let after = Array(r[(to + 1)...])
+ var recipientWords: [String] = []
+ var rest: [String] = []
+ if let first = after.first, first.contains("@") || isSpelledEmail(after) {
+ let joined = after.joined(separator: " ")
+ recipientWords = [joined]
+ } else {
+ // A contact name: the capitalised words right after "à" (or just the first one).
+ for (i, w) in after.enumerated() {
+ if i == 0 || (w.first?.isUppercase == true && rest.isEmpty) { recipientWords.append(w) }
+ else { rest = Array(after[i...]); break }
+ }
+ }
+ var recipient = recipientWords.joined(separator: " ")
.trimmingCharacters(in: .punctuationCharacters.union(.whitespaces))
+ if let email = spokenEmail(recipient) { recipient = email }
guard !recipient.isEmpty else { return nil }
- // Optional file: after "fichier"/"file"/"document", up to the folder words or "à".
- var file: String? = nil
var folder: MailRequest.Folder? = nil
- let middle = Array(n[(v + 1)..<to])
- if middle.contains(where: { ["telechargements", "telechargement", "downloads"].contains($0) }) { folder = .downloads }
- else if middle.contains(where: { ["bureau", "desktop"].contains($0) }) { folder = .desktop }
- else if middle.contains(where: { ["documents"].contains($0) }) { folder = .documents }
- if let f = n[(v + 1)..<to].firstIndex(where: { ["fichier", "file", "document", "pdf"].contains($0) }) {
- let stop: Set<String> = ["des", "du", "de", "dans", "from", "in", "telechargements", "telechargement",
- "downloads", "bureau", "desktop", "documents", "mes", "my", "par", "en"]
- var end = f + 1
- while end < to && !(stop.contains(n[end]) && end > f + 1) { end += 1 }
- let name = r[(f + 1)..<end].joined(separator: " ")
- if !name.isEmpty { file = name }
- if n[f] == "pdf", file == nil { file = "pdf" }
+ if n.contains(where: { ["telechargements", "telechargement", "downloads"].contains($0) }) { folder = .downloads }
+ else if n.contains(where: { ["bureau", "desktop"].contains($0) }) { folder = .desktop }
+ else if n.contains(where: { ["documents"].contains($0) }) { folder = .documents }
+ else if n.contains(where: { ["photos", "images", "pictures"].contains($0) }) { folder = .pictures }
+
+ var file: String? = nil
+ if let f = n.firstIndex(where: { fileWords.contains($0) }) {
+ let skip: Set<String> = ["qui", "s", "appelle", "appellent", "appelee", "appele", "nommee", "nomme",
+ "called", "named", "la", "le", "l", "the", "mon", "ma", "my", "intitule", "intitulee"]
+ let stop: Set<String> = ["des", "du", "de", "dans", "from", "in", "par", "en", "a", "to", "et", "and",
+ "pour", "que", "qu", "j", "je", "sur", "on", "mes", "my", "telechargements",
+ "telechargement", "downloads", "bureau", "desktop", "documents", "photos", "pictures"]
+ var i = f + 1
+ while i < n.count, skip.contains(n[i]) { i += 1 }
+ var parts: [String] = []
+ while i < n.count, !(stop.contains(n[i]) && !parts.isEmpty) {
+ if ["point", "dot"].contains(n[i]), i + 1 < n.count, ["png", "jpg", "jpeg", "pdf", "heic", "gif", "mov", "mp4", "docx", "zip", "txt"].contains(n[i + 1]) {
+ if let last = parts.popLast() { parts.append(last + "." + n[i + 1]) }
+ i += 2; continue
+ }
+ if stop.contains(n[i]) { break }
+ parts.append(r[i].trimmingCharacters(in: CharacterSet(charactersIn: ".,;:!?")))
+ i += 1
+ }
+ let name = parts.joined(separator: " ")
+ if !name.isEmpty { file = name } else if n[f] == "pdf" { file = "pdf" }
+ }
+
+ var instruction: String? = nil
+ if bodyText == nil {
+ let extra = rest.joined(separator: " ").trimmingCharacters(in: .punctuationCharacters.union(.whitespaces))
+ if !extra.isEmpty { instruction = extra }
+ }
+ return MailRequest(recipient: recipient, file: file, folder: folder,
+ subject: subject, body: bodyText, instruction: instruction)
+ }
+
+ /// "tana arobase gmail point com" / "tana at gmail dot com" / "[email protected]." → "[email protected]".
+ static func spokenEmail(_ s: String) -> String? {
+ var t = " " + s.lowercased() + " "
+ for (a, b) in [(" arobase ", "@"), (" at ", "@"), (" point ", "."), (" dot ", "."), (" tiret ", "-"),
+ (" underscore ", "_"), (" dash ", "-")] {
+ t = t.replacingOccurrences(of: a, with: b)
+ }
+ t = t.replacingOccurrences(of: " ", with: "").trimmingCharacters(in: CharacterSet(charactersIn: ".,;:!?"))
+ let ok = t.range(of: #"^[A-Za-z0-9._%+\-]+@[A-Za-z0-9.\-]+\.[A-Za-z]{2,}$"#, options: .regularExpression) != nil
+ return ok ? t : nil
+ }
+
+ private static func isSpelledEmail(_ words: [String]) -> Bool {
+ let n = words.map { IntentParser.normalise($0) }
+ return n.contains("arobase") || (n.contains("at") && (n.contains("dot") || n.contains("point")))
+ }
+
+ private static func firstMarker(_ markers: [String], in raw: String) -> (range: Range<String.Index>, marker: String)? {
+ var best: (range: Range<String.Index>, marker: String)? = nil
+ for m in markers {
+ var from = raw.startIndex
+ while let r = raw.range(of: m, options: [.caseInsensitive, .diacriticInsensitive], range: from..<raw.endIndex) {
+ // Whole words only.
+ let beforeOK = r.lowerBound == raw.startIndex || !raw[raw.index(before: r.lowerBound)].isLetter
+ let afterOK = r.upperBound == raw.endIndex || !raw[r.upperBound].isLetter
+ if beforeOK && afterOK {
+ if best == nil || r.lowerBound < best!.range.lowerBound
+ || (r.lowerBound == best!.range.lowerBound && r.upperBound > best!.range.upperBound) {
+ best = (r, m)
+ }
+ break
+ }
+ from = r.upperBound
+ }
+ }
+ return best
+ }
+
+ /// ": tu écris : Voilà votre image." → "Voilà votre image"
+ private static func cleanFreeText(_ s: String) -> String? {
+ var t = s.trimmingCharacters(in: .whitespacesAndNewlines)
+ let lead = ["tu écris", "tu ecris", "tu mets", "écris", "ecris", "mets", "write", "put", "it's", "is", "c'est", "ce sera"]
+ var changed = true
+ while changed {
+ changed = false
+ t = t.trimmingCharacters(in: CharacterSet(charactersIn: " :,;-–—\"«»“”").union(.whitespaces))
+ for l in lead where t.lowercased().hasPrefix(l + " ") || t.lowercased().hasPrefix(l + ":") || t.lowercased() == l {
+ t = String(t.dropFirst(l.count)); changed = true; break
+ }
}
- return MailRequest(recipient: recipient, file: file, folder: folder)
+ t = t.trimmingCharacters(in: CharacterSet(charactersIn: " .,;\"«»“”").union(.whitespacesAndNewlines))
+ for tail in [" et", " and", " puis"] where t.lowercased().hasSuffix(tail) { t = String(t.dropLast(tail.count)) }
+ return t.isEmpty ? nil : t
}
// MARK: Open an app: "ouvre Figma", "open Safari"
diff --git a/NotchBuddy/Sources/App/Voice/VoiceSettings.swift b/NotchBuddy/Sources/App/Voice/VoiceSettings.swift
index 60fe0748..f31ccea4 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceSettings.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceSettings.swift
@@ -35,6 +35,23 @@ enum VoiceSettings {
set { UserDefaults.standard.set(newValue, forKey: captionEnabledKey) }
}
+ /// Language Coucou listens and answers in: "en" (default) or "fr".
+ static var language: String {
+ get { UserDefaults.standard.string(forKey: "voiceLanguage") ?? "en" }
+ set { UserDefaults.standard.set(newValue, forKey: "voiceLanguage") }
+ }
+
+ /// Voice used to answer: "system" (macOS voices) or "elevenlabs" (user's API key).
+ static var ttsEngine: String {
+ get { UserDefaults.standard.string(forKey: "voiceTTSEngine") ?? "system" }
+ set { UserDefaults.standard.set(newValue, forKey: "voiceTTSEngine") }
+ }
+ /// ElevenLabs voice: "female" (default) or "male".
+ static var elevenGender: String {
+ get { UserDefaults.standard.string(forKey: "voiceElevenGender") ?? "female" }
+ set { UserDefaults.standard.set(newValue, forKey: "voiceElevenGender") }
+ }
+
/// Weather by voice (Open-Meteo, no key). Off by default: network only when the user
/// turned it on and set a city.
static var weatherEnabled: Bool {
diff --git a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
index d8136288..a91739e8 100644
--- a/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
+++ b/NotchBuddy/Sources/App/Voice/VoiceSpeaker.swift
@@ -3,21 +3,33 @@ import AVFoundation
// MARK: - VoiceSpeaker
//
-// Gives Mochi a voice: wraps AVSpeechSynthesizer with a sentence queue.
-// Sentence queue: enqueue(text:locale:) adds to queue, playback starts automatically
-// and continues through the queue. onDidFinish fires when the queue drains.
-//
-// All methods: @MainActor.
+// Gives Coucou a voice, sentence by sentence:
+// • macOS voices (AVSpeechSynthesizer), best installed voice for the language;
+// • ElevenLabs (Settings → Voice, the user's own API key), female or male.
+// Each queued sentence starts downloading right away, so the next one is usually
+// ready when the previous one ends. Any ElevenLabs failure falls back to the Mac
+// voice for that sentence: Coucou never goes silent.
+// onDidFinish fires ~150 ms after the queue drains. All methods: @MainActor.
@MainActor
-final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Sendable {
+final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, AVAudioPlayerDelegate, @unchecked Sendable {
static let shared = VoiceSpeaker()
private let synth = AVSpeechSynthesizer()
+ private var player: AVAudioPlayer?
private(set) var isSpeaking = false
private var currentUtterance: AVSpeechUtterance? = nil
- private var queue: [(text: String, locale: Locale?)] = []
+ private var waitingForAudio = false
+
+ private struct Item {
+ let text: String
+ let locale: Locale?
+ let audio: Task<Data?, Never>? // ElevenLabs download, started at enqueue time
+ }
+ private var queue: [Item] = []
+ /// Bumped by stop()/speak(): late callbacks from an older utterance are ignored.
+ private var generation = 0
- /// Called ~150 ms after the last queued utterance finishes.
+ /// Called ~150 ms after the last queued sentence finishes.
var onDidFinish: (() -> Void)?
override init() {
@@ -27,55 +39,93 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
// MARK: - Public API
- /// Clears the queue, stops current speech, and speaks text immediately.
+ /// Clears the queue, stops current speech, and speaks text now.
func speak(_ text: String, locale: Locale?) {
guard VoiceSettings.speakEnabled else { return }
- queue.removeAll()
- synth.stopSpeaking(at: .immediate)
- isSpeaking = false
- currentUtterance = nil
- _enqueueAndPlay(text: text, locale: locale)
+ stopPlayback()
+ enqueue(text, locale: locale)
}
- /// Adds text to the end of the playback queue. Starts playing if not already.
+ /// Adds a sentence to the queue. Starts playing if nothing is playing.
func enqueue(_ text: String, locale: Locale?) {
guard VoiceSettings.speakEnabled else { return }
- if isSpeaking {
- queue.append((text, locale))
- } else {
- _enqueueAndPlay(text: text, locale: locale)
- }
+ let audio: Task<Data?, Never>? = ElevenLabsTTS.isActive
+ ? Task { await ElevenLabsTTS.shared.audio(for: text) }
+ : nil
+ queue.append(Item(text: text, locale: locale, audio: audio))
+ if !isSpeaking { playNext() }
}
- func stop() {
+ func stop() { stopPlayback() }
+
+ /// What the mic gate uses: what is actually playing or about to play, never a flag
+ /// alone, so a missed callback cannot leave Coucou deaf.
+ var isBusy: Bool {
+ synth.isSpeaking || (player?.isPlaying ?? false) || waitingForAudio || !queue.isEmpty
+ }
+
+ // MARK: - Playback
+
+ private func stopPlayback() {
+ generation += 1
+ for item in queue { item.audio?.cancel() }
queue.removeAll()
- // Reset now: if the synthesizer never reports the cancel (stopped before the
- // utterance really started), isSpeaking would stay true and the mic would
- // ignore everything until relaunch.
currentUtterance = nil
+ waitingForAudio = false
isSpeaking = false
+ player?.stop()
+ player = nil
synth.stopSpeaking(at: .immediate)
}
- /// What the mic gate should use: the synthesizer's own state (or sentences still
- /// queued), never our flag alone, so a missed delegate callback cannot leave
- /// Coucou deaf.
- var isBusy: Bool { synth.isSpeaking || !queue.isEmpty }
-
- // MARK: - Private
+ private func playNext() {
+ guard !queue.isEmpty else { finished(); return }
+ let item = queue.removeFirst()
+ isSpeaking = true
+ guard let audio = item.audio else { speakSystem(item.text, locale: item.locale); return }
+ let gen = generation
+ waitingForAudio = true
+ Task { @MainActor in
+ let data = await audio.value
+ guard gen == self.generation else { return }
+ self.waitingForAudio = false
+ if let data, let p = try? AVAudioPlayer(data: data) {
+ p.delegate = self
+ self.player = p
+ if p.play() { return }
+ self.player = nil
+ }
+ self.speakSystem(item.text, locale: item.locale) // fallback: Mac voice
+ }
+ }
- private func _enqueueAndPlay(text: String, locale: Locale?) {
+ private func speakSystem(_ text: String, locale: Locale?) {
let utt = AVSpeechUtterance(string: text)
utt.pitchMultiplier = 1.15
utt.rate = AVSpeechUtteranceDefaultSpeechRate * 1.1
utt.voice = _bestVoice(for: locale)
currentUtterance = utt
- isSpeaking = true
synth.speak(utt)
}
+ private func itemDone() {
+ currentUtterance = nil
+ player = nil
+ playNext()
+ }
+
+ private func finished() {
+ isSpeaking = false
+ let gen = generation
+ Task { @MainActor in
+ try? await Task.sleep(nanoseconds: 150_000_000) // 150 ms gap
+ guard gen == self.generation, !self.isSpeaking else { return }
+ self.onDidFinish?()
+ }
+ }
+
/// Picks the best installed voice for the spoken locale: same region first
- /// (fr-FR before fr-CA), then quality (.premium > .enhanced > default).
+ /// (en-US before en-GB), then quality (.premium > .enhanced > default).
/// Novelty voices and the user's Personal Voice are never used.
private func _bestVoice(for locale: Locale?) -> AVSpeechSynthesisVoice? {
guard let loc = locale else { return nil }
@@ -104,26 +154,30 @@ final class VoiceSpeaker: NSObject, AVSpeechSynthesizerDelegate, @unchecked Send
let id = ObjectIdentifier(utterance)
Task { @MainActor in
guard let curr = self.currentUtterance, ObjectIdentifier(curr) == id else { return }
- self.currentUtterance = nil
- if self.queue.isEmpty {
- self.isSpeaking = false
- try? await Task.sleep(nanoseconds: 150_000_000) // 150 ms gap
- self.onDidFinish?()
- } else {
- let next = self.queue.removeFirst()
- self._enqueueAndPlay(text: next.text, locale: next.locale)
- }
+ self.itemDone()
}
}
nonisolated func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer,
didCancel utterance: AVSpeechUtterance) {
- let id = ObjectIdentifier(utterance)
+ // stopPlayback() already reset everything; nothing to do for older utterances.
+ }
+
+ // MARK: - AVAudioPlayerDelegate
+
+ nonisolated func audioPlayerDidFinishPlaying(_ p: AVAudioPlayer, successfully flag: Bool) {
+ let id = ObjectIdentifier(p)
Task { @MainActor in
- guard let curr = self.currentUtterance, ObjectIdentifier(curr) == id else { return }
- self.isSpeaking = false
- self.currentUtterance = nil
- self.queue.removeAll()
+ guard let curr = self.player, ObjectIdentifier(curr) == id else { return }
+ self.itemDone()
+ }
+ }
+
+ nonisolated func audioPlayerDecodeErrorDidOccur(_ p: AVAudioPlayer, error: Error?) {
+ let id = ObjectIdentifier(p)
+ Task { @MainActor in
+ guard let curr = self.player, ObjectIdentifier(curr) == id else { return }
+ self.itemDone()
}
}
}
diff --git a/tests/IntentParserTests.swift b/tests/IntentParserTests.swift
index 63be1574..e0f43054 100644
--- a/tests/IntentParserTests.swift
+++ b/tests/IntentParserTests.swift
@@ -310,6 +310,10 @@ enum IntentParserTests {
parse("OK tu peux démarrer Apple Music j'ai envie d'écouter du Drake", pills: pills), "drake")
check("j'ai envie d'écouter de la musique",
parse("j'ai envie d'écouter de la musique", pills: pills), .musicPlay(target: nil))
+ check("make Cursor my main pill",
+ parse("make Cursor my main pill", pills: pills), .pillSetMain(id: "agent_cursor"))
+ checkPlaylist("play my Focus playlist", parse("play my Focus playlist", pills: pills), "focus")
+ check("add Gemini (EN)", parse("add Gemini", pills: pills), .pillAdd(id: "agent_gemini"))
check("tu peux lancer ma playlist",
parse("tu peux lancer ma playlist", pills: pills), .musicPlayPlaylist(name: ""))
checkMultiAction("Enlève la pilule GT et mets Stripe à la place",
diff --git a/tests/VoiceQueryTests.swift b/tests/VoiceQueryTests.swift
index 8eb15a77..a2e05f2b 100644
--- a/tests/VoiceQueryTests.swift
+++ b/tests/VoiceQueryTests.swift
@@ -59,6 +59,24 @@ struct VoiceQueryTests {
check("send an email to", VoiceQuery.mail(of: "send an email to Tana"),
VoiceQuery.MailRequest(recipient: "Tana", file: nil, folder: nil))
check("not a mail", VoiceQuery.mail(of: "envoie la musique"), nil)
+ // Louis's example, as dictated
+ check("Goku mail", VoiceQuery.mail(of: "Il y a une image qui s'appelle Goku.png. J'aimerais que tu la prennes et que tu l'envoies par mail à [email protected]. En objet, tu écris : Voilà votre image. En description, tu écris : Image en 1980 × 1080."),
+ VoiceQuery.MailRequest(recipient: "[email protected]", file: "Goku.png", folder: nil,
+ subject: "Voilà votre image", body: "Image en 1980 × 1080"))
+ check("Goku mail EN", VoiceQuery.mail(of: "email the image called Goku.png to [email protected], subject Here is your image, body Image in 1980 by 1080"),
+ VoiceQuery.MailRequest(recipient: "[email protected]", file: "Goku.png", folder: nil,
+ subject: "Here is your image", body: "Image in 1980 by 1080"))
+ check("spoken address", VoiceQuery.mail(of: "envoie un mail à tana arobase gmail point com"),
+ VoiceQuery.MailRequest(recipient: "[email protected]", file: nil, folder: nil))
+ check("spoken address EN", VoiceQuery.spokenEmail("tana at gmail dot com"), "[email protected]")
+ check("file point png", VoiceQuery.mail(of: "envoie l'image goku point png à Tana")?.file, "goku.png")
+ check("draft instruction", VoiceQuery.mail(of: "write an email to Tana thanking her for yesterday"),
+ VoiceQuery.MailRequest(recipient: "Tana", file: nil, folder: nil, instruction: "thanking her for yesterday"))
+ check("écris un mail = command", VoiceQuery.topic(of: "tu peux écrire un mail à Tana"), nil)
+ check("parse écris un mail", IntentParser.parse("tu peux écrire un mail à Tana", pills: pills),
+ .mail(VoiceQuery.MailRequest(recipient: "Tana", file: nil, folder: nil)))
+ check("resend stats still work", VoiceQuery.topic(of: "combien de mails j'ai envoyé ?"), .resend)
+ check("VS Code question", VoiceQuery.topic(of: "qu'est-ce qui se passe sur VS Code ?"), .agents)
check("parse mail", IntentParser.parse("Envoie un mail à Intel", pills: pills),
.mail(VoiceQuery.MailRequest(recipient: "Intel", file: nil, folder: nil)))