You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取/System/Library/Sounds中默认声音的本地化名称?

获取macOS系统声音的本地化名称

不需要手动为每种语言逐一翻译,系统自带的声音本地化名称已经存储在/System/Library/Sounds目录对应的bundle资源中,通过系统API就能直接读取:

实现代码(Swift)

import Foundation

func getLocalizedSoundName(soundFileName: String) -> String? {
    let soundsBundleURL = URL(fileURLWithPath: "/System/Library/Sounds")
    guard let soundsBundle = CFBundleCreate(kCFAllocatorDefault, soundsBundleURL as CFURL) else {
        return nil
    }
    // 传入不带后缀的声音文件名,比如"Purr"而非"Purr.aiff"
    return CFBundleCopyLocalizedString(soundsBundle, soundFileName as CFString, nil, nil) as String?
}

// 使用示例
if let localizedName = getLocalizedSoundName(soundFileName: "Purr") {
    print(localizedName) // 系统语言为中文时输出"咕噜声"
}

原理说明

/System/Library/Sounds是一个特殊的bundle目录,内部包含了各语言版本的本地化字符串文件,存储了每个系统声音的对应名称。通过CFBundle的本地化字符串获取接口,会自动根据当前系统的语言设置返回对应的本地化名称,无需手动维护多语言翻译资源。

注意事项

  • 传入的参数必须是声音文件的主文件名(不带.aiff等后缀)
  • 该方法仅适用于macOS系统自带的/System/Library/Sounds路径下的声音

内容的提问来源于stack exchange,提问作者Nickkk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 19:13:16