AVSpeechSynthesizer不能在iOS10上运行

我的AVSpeechSynthesizer代码不能在设备上运行(iOS 10),但是它在iOS 9.x上运行,现在在模拟器中运行。

let str = self.audioOutput //just some string here, this string exists, and it's in english let synth = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: str) utterance.rate = AVSpeechUtteranceDefaultSpeechRate let lang = "en-US" utterance.voice = AVSpeechSynthesisVoice(language: lang) synth.speakUtterance(utterance) 

我得到这个错误:

 MobileAssetError:1] Unable to copy asset attributes Could not get attribute 'LocalURL': Error Domain=MobileAssetError Code=1 "Unable to copy asset attributes" UserInfo={NSDescription=Unable to copy asset attributes} 0x1741495e0 Copy assets attributes reply: XPC_TYPE_DICTIONARY <dictionary: 0x1741495e0> { count = 1, transaction: 0, voucher = 0x0, contents = "Result" => <int64: 0x1744203a0>: 1} 

在此之前有这样的错误信息:

 Unable to copy asset information from https://mesu.apple.com/assets/ for asset type 

有谁知道如何解决这个问题? 我知道有一些解决方法(用户必须去设置 – >常规,并切换说话select,例如),但我不认为这是一个真正的解决scheme在这里。

更新:我创build了一个新的项目(XCode8 / Swift3 /没有其他豆荚/框架等)。 它在模拟器中工作,但它给我在我的设备上相同的错误。

更新2:它在设备上工作。 我有类似的错误信息(无法复制资产属性等),但它现在工作。 我不知道是什么

closures静音模式(物理开关)。 它适用于我的情况。

我刚刚在iPad Mini 4上遇到同样的问题。这个版本没有物理交换机。 但是,如果你打开控制中心(向上滑动),则有一个静音button。 closures此问题并解决问题本身。

在这里输入图像说明

在我的项目中,尽pipe在初始化之后我无法合成出第一个话语,但是我可以通过重新编排代码来解决这个问题。 但是,当AVSpeechSynthesizer初始化时,以及第一个话语产生时,我仍然有几十行垃圾正在喷向控制台。 这是一个小样本:

 2016-12-27 06:45:08.579510 SpeechBug1226[2155:859123] [MobileAssetError:1] Unable to copy asset attributes 2016-12-27 06:45:08.580248 SpeechBug1226[2155:859123] Could not get attribute 'LocalURL': Error Domain=MobileAssetError Code=1 "Unable to copy asset attributes" UserInfo={NSDescription=Unable to copy asset attributes} 2016-12-27 06:45:08.585959 SpeechBug1226[2155:859123] 0x174157fa0 Copy matching assets reply: XPC_TYPE_DICTIONARY <dictionary: 0x174157fa0> { count = 2, transaction: 0, voucher = 0x0, contents = "Assets" => <data: 0x17426c700>: { length = 1237 bytes, contents = 0x62706c6973743030d4010203040506636458247665727369... } "Result" => <int64: 0x174220180>: 0 

我在一个小型的演示项目中转载了这个,并且找不到解决方法。 可悲的是,我担心这个问题的正确答案是提交一个错误 , 我刚刚做了 🙁

我只用一个变化就可以尝试你的代码。 试试这一次

  synth.speak(utterance) 

我的整个代码就像

 **`import AVFoundation`** let str = "once" //just some string here, this string exists, and it's in english let synth = AVSpeechSynthesizer() let utterance = AVSpeechUtterance(string: str) utterance.rate = AVSpeechUtteranceDefaultSpeechRate let lang = "en-US" utterance.voice = AVSpeechSynthesisVoice(language: lang) synth.speak(utterance) 

在我的情况下,我可以通过在iPhone中启用Internet连接来解决这个问题。

语音识别器只识别一种语言。 当您使用默认初始化程序时,如果该区域设置支持识别程序,则会为设备的当前语言环境获取语音识别程序。 请注意,支持的语音识别器与可用的语音识别器不同。 例如,某些语言环境的识别器可能需要Internet连接。 您可以使用supportedLocales()方法获取受支持的语言环境列表以及isAvailable属性,以确定特定语言环境的识别程序是否可用。

资源