iOS text to speech: What decides the default voice returned by [AVSpeechSynthesisVoice voiceWithLanguage]?

故事扮演 提交于 2019-12-03 16:04:18

[NO Solution yet] I met the same issue, too.

First, set different voice via

Accessibility -> Speech -> Voices
or 
Accessibility -> VoiceOver -> Speech -> Voices

Then

AVSpeechSynthesisVoice(language: language)

It won't affect AVSpeechSynthesizer in iOS 12.0.1 (it works on iOS 11.x & iOS 12.0.0)

I also found two other things on iOS 12.0.1

First, the Siri voice is no longer available when using

AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.siri_male_ja-JP_compact")

Second, if I don't set voice identifier, Female Siri in that locale will speak the text. It also doesn't affect by the speech settings in preference. BTW, I still cannot find anyway to make Male Siri Speak anything, yet... haha

... does the returned voice changed between iOS versions and even between different devices?

I discovered speech synthesis only in iOS 12 so I can't give you any information about the previous versions but I understood that the default voice is the built-in voice of the device supported language.

As you use only the BCP 47 code specifying language and locale for a voice when instantiating the AVSpeechSynthesisVoice class, your code takes the default voice of the device that may be customed for many users.

... for example English US, if you set voice "Fred" voiceWithLanguage will return "Fred", which is cool. But if you set voice to "Nicky", voiceWithLanguage returns something else other than "Nicky".

I made many tests (iOS 12.3.1, Swift 5.0, iPhone X, iPhone 7 Plus) including the one you mentioned and it always return the built-in voice of my device supported language when I change it.

I couldn't reproduce your problem.

... of course I can start to use voiceWithIdentifier instead.

That's exactly what I recommend and, if the specified voice with the identifier isn't installed, take the default one: it will reduce the possible different voices heard by many users.

To conclude, using the BCP 47 code ("en-US", "fr-FR"...) gives rise to the built-in voice of the device to be taken into account that could lead to different heard voices according to the customed settings: that decides the default voice returned by [AVSpeechSynthesisVoice voiceWithLanguage] (ObjC).

An introduction of choosing the right voice is available at this WWDC detailed summary if need be.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!