【发布时间】:2020-05-23 18:14:10
【问题描述】:
我希望能够测试哪些文本转语音可供我的 iOS 应用与 AVSpeechSynthesis 一起使用。生成已安装声音的列表很容易,但 Apple 将其中一些声音禁止应用程序使用,我想知道哪些声音。
例如,考虑以下测试代码(swift 5.1):
import AVFoundation
...
func voiceTest() {
let speechSynthesizer = AVSpeechSynthesizer()
let voices = AVSpeechSynthesisVoice.speechVoices()
for voice in voices where voice.language == "en-US" {
print("\(voice.language) - \(voice.name) - \(voice.quality.rawValue) [\(voice.identifier)]")
let phrase = "The voice you're now listening to is the one called \(voice.name)."
let utterance = AVSpeechUtterance(string: phrase)
utterance.voice = voice
speechSynthesizer.speak(utterance)
}
}
当我调用voiceTest() 时,控制台输出是这样的:
en-US - Nicky (Enhanced) - 2 [com.apple.ttsbundle.siri_female_en-US_premium]
en-US - Aaron - 1 [com.apple.ttsbundle.siri_male_en-US_compact]
en-US - Fred - 1 [com.apple.speech.synthesis.voice.Fred]
en-US - Nicky - 1 [com.apple.ttsbundle.siri_female_en-US_compact]
en-US - Samantha - 1 [com.apple.ttsbundle.Samantha-compact]
en-US - Alex - 2 [com.apple.speech.voice.Alex]
有些声音以他们的实际声音说话,而有些则以默认声音说话。在我的情况下,Nicky (com.apple.ttsbundle.siri_female_en-US_premium) 和 Alex (com.apple.speech.voice.Alex) 都被列为高质量,但在选择时听起来像低质量默认值 Samantha。
我知道 Apple 曾表示 Siri 语音不可用于第三方应用程序。当我通过设置在我的 iPhone 上手动加载 Samantha(高质量)时,它会出现在列表中,我可以使用它。也许 Alex 只是高品质的男性 Siri 声音,尽管 Aaron 似乎是基于其标识符 (com.apple.ttsbundle.siri_male_en-US_compact) 的低品质 Siri 声音?这就是为什么 Alex 和 Nicky 是仅有的两个不可用的?因此,如果我的应用程序专门排除了那些,它将生成可用声音的真实列表?最好能有一些清晰。
【问题讨论】:
标签: ios text-to-speech voice siri avspeechsynthesizer