ios - SFSpeechRecognizer init 不接受区域设置

标签 ios swift xcode8

我正在尝试初始化 SFSpeechRecognizer 的实例,但出现以下错误 无法将类型“Locale”的值转换为预期的参数类型“Locale”对我来说没有任何意义。下面是我的初始化代码。

let speech = SFSpeechRecognizer(locale: Locale().initWithLanguageCode(languageCode: "en-US") as! Locale)

最佳答案

应该是:

if let speech = SFSpeechRecognizer(locale: Locale(identifier: "en-US")) {
     // ...
}

使用init(localeIdentifier:)用于初始化。

let locale = Locale()

这会导致:

enter image description here

请注意,语音是可选的。

另外: here您可以检查 iOS 区域设置标识符。

希望这有帮助。

关于ios - SFSpeechRecognizer init 不接受区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257479/

相关文章:

ios - 动态 TableView (就像android中的不可滚动 ListView )

ios - 使用 ABPersonCopyImageData 获取 iOS 联系人图像

ios - 使用高级 where 限制 Swift 协议(protocol)

xcode - Chartboost 与 XCode 6.1 的集成问题

ios - XCode 8:缺少“自动管理签名”选项

swift - swift 3 "nearly match optional requirement"中的所有 6 个应用程序委托(delegate)函数 - 这是什么?怎么修?

ios - 在 Swift 的手势识别器中获取触摸窗口坐标?

ios - 当用户触摸警报周围时,如何防止我的 SDCAlertview 关闭?

objective-c - 使用 Objective-c typedef 快速关闭的可变参数

swift - XCUI测试: Is it possible to tap on element not using static texts present but identifier?