macOS应用CFBundleSpokenName使用场景及语音播报名称修正问询
关于macOS应用名称VoiceOver发音修正的问题解答
1. CFBundleSpokenName的实际使用场景
CFBundleSpokenName字段的生效范围比文档描述更有限,主要在以下场景被系统语音合成调用:
- Siri播报应用名称时(比如询问“Siri,打开XX应用”,Siri会优先使用该字段的发音)
- 系统“朗读内容”功能(选中文本后右键选择“朗读”,若文本包含应用名称,会调用该字段)
- Spotlight搜索结果的语音播报(让系统朗读Spotlight内的应用条目时)
而你关注的通知播报、关机阻止提示、应用内弹窗这些场景,系统语音逻辑直接绑定应用的显示名称(CFBundleDisplayName或CFBundleName),不会读取CFBundleSpokenName,这是当前macOS的设计逻辑。
2. 实现VoiceOver发音修正的方案
针对你关注的两个场景,可分别处理:
场景一:应用阻止系统关机时的提示
该提示由系统生成,需通过全局语音自定义词汇覆盖发音:
- 在应用首次启动时,通过代码向系统注册自定义发音规则:
import Foundation func setupCustomAppPronunciation() { guard let appDisplayName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String else { return } let targetSpokenName = "你的应用名称发音文本(比如拼音或易读名称)" let defaults = UserDefaults.standard var customPronunciations = defaults.array(forKey: "NSSpeechCustomPronunciations") as? [[String: Any]] ?? [] // 避免重复添加规则 if !customPronunciations.contains(where: { ($0["string"] as? String) == appDisplayName }) { let newRule: [String: Any] = [ "string": appDisplayName, "phonemes": targetSpokenName, "language": "zh-CN" // 根据应用语言调整,比如en-US ] customPronunciations.append(newRule) defaults.set(customPronunciations, forKey: "NSSpeechCustomPronunciations") } }
调用该方法后,系统所有语音合成(包括VoiceOver)遇到你的应用显示名称时,会优先使用你设置的发音文本。
场景二:应用内弹窗(如退出保存提示)
这类弹窗由应用自主控制,直接给弹窗内容设置VoiceOver专属语音标签即可:
- SwiftUI 弹窗:
Alert( title: Text("保存提示"), message: Text("请先保存工作再退出"), primaryButton: .default(Text("保存")), secondaryButton: .cancel(Text("取消")) ) .accessibilitySpeech("请先保存工作再退出[你的应用名称发音]")
- AppKit NSAlert:
import AppKit let alert = NSAlert() alert.messageText = "请先保存工作再退出" alert.informativeText = "来自你的应用显示名称" // 直接设置VoiceOver播报文本,覆盖默认内容 alert.accessibilityLabel = "请先保存工作再退出来自[你的应用名称发音]"
另外,也可给应用全局设置语音属性,让VoiceOver播报应用相关内容时优先使用:
import AppKit NSApplication.shared.accessibilitySpeechAttribute = "你的应用名称发音"
内容的提问来源于stack exchange,提问作者JDGross
相关产品推荐
相关产品推荐

