ios - AVSpeech合成器: AVSpeechSynthesisIPANotationAttribute seems like does not support Chinese

标签 ios localization text-to-speech

测试AVSpeechSynthesizer时,AVSpeechSynthesisIPANotationAttribute好像不支持中文?

en-GB 可以:

let dst = NSMutableAttributedString(string: "It's pronounced 'tomato'")
let pronunciationKey = NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute)
let range = NSString(string: "It's pronounced 'tomato'").range(of: "tomato")
// just test a joke
dst.setAttributes([pronunciationKey: "tə.do͡ʊ.ˈme͡ɪ"], range: range)
let result = dst.copy() as! NSAttributedString
utterance = AVSpeechUtterance(attributedString: result)
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
synthesizer.speak(utterance)

zh-CN 不行

let dst = NSMutableAttributedString(string: "行人")
let pronunciationKey = NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute)
let range = NSString(string: "行人").range(of: "行")
dst.setAttributes([pronunciationKey: "ˈme͡ɪ"], range: range)
//  I also tried "a"
//  dst.setAttributes([pronunciationKey: "a"], range: range)
let result = dst.copy() as! NSAttributedString
utterance = AVSpeechUtterance(attributedString: result)
utterance.voice = AVSpeechSynthesisVoice(language: "zh-CN")
synthesizer.speak(utterance)

zh-HK、zh-TW 都不是。

也许有一些低级解决方案。

最佳答案

根据 WWDC 2018 session “AVSpeechSynthesizer:让 iOS 说话”, 国际音标表示法仅适用于以下语言:

en-US、en-AU、en-GB、de-DE、es-ES、es-MX、fr-CA、fr-FR、it-IT、ja-JP

我找不到任何更新的引用资料,也找不到 Apple 提供的有关 AVSpeechSynthesisIPANotationAttribute 的任何其他官方文档。

来源:
https://developer.apple.com/videos/play/wwdc2018/236/?time=424 https://nshipster.com/avspeechsynthesizer/

关于ios - AVSpeech合成器: AVSpeechSynthesisIPANotationAttribute seems like does not support Chinese,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58225479/

相关文章:

javascript - 客户端本地化

ios - 如何在 Xcode 12(.5) 中设置基本本地化和开发语言?

objective-c - 适用于非英语语言的 iPhone 应用程序

html5-audio - 如何下载使用语音合成将文本转换为语音的音频结果?

android - Espeak 读取单独的字母而不是单词

python - 如何在 PYTTS (Python) 中设置属性 : age, 性别或语言

ios - 将文本字段内容发布到 Firebase 数据库

ios - 自定义 BarButtonItem 项目 : Add red dot on top right corner, Swift 4 IOS

ios - ScrollView 仅显示 1 张图像

ios - 正确设置 XCode iOS 项目?