watchOS 3 是否支持 SpeechKit 框架?
Is SpeechKit framework supported in watchOS 3?
我尝试为 watchOS 导入 SpeechKit 框架,但收到错误消息。有没有办法将它与手表一起使用?导入 Speechkit 框架时出现错误 "no such module Speech"
import WatchKit
import Foundation
import Speech
class SpeechInterfaceController: WKInterfaceController, SFSpeechRecognizerDelegate {
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
SpeechKit 框架不适用于 watchOS 3。
要在手表应用中获得语音识别功能,您可以改用:
presentTextInputController(withSuggestions: nil, allowedInputMode: .plain) { (results) in
if let results = results?.first as? String {
self.label.setText(results)
}
}
语音框架不在 watchOS SDK 中(至少从 watchOS 3.0-3.1 开始)。你可以看到这个 in the framework docs:
(如果它支持 watchOS、tvOS 或 macOS,它们将在该页面的 SDK 下列出。)
您还可以在 Xcode SDK 中查看可用框架集:查看 Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS3.1.sdk/System/Library/Frameworks/
,或者查看 Xcode 编辑器窗格顶部的跳转栏watchOS 系统头文件的 ObjC 版本,或当您手动添加到项目的 WatchKit 扩展目标的链接框架和库时的可用选项列表。
我尝试为 watchOS 导入 SpeechKit 框架,但收到错误消息。有没有办法将它与手表一起使用?导入 Speechkit 框架时出现错误 "no such module Speech"
import WatchKit
import Foundation
import Speech
class SpeechInterfaceController: WKInterfaceController, SFSpeechRecognizerDelegate {
override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
SpeechKit 框架不适用于 watchOS 3。
要在手表应用中获得语音识别功能,您可以改用:
presentTextInputController(withSuggestions: nil, allowedInputMode: .plain) { (results) in
if let results = results?.first as? String {
self.label.setText(results)
}
}
语音框架不在 watchOS SDK 中(至少从 watchOS 3.0-3.1 开始)。你可以看到这个 in the framework docs:
(如果它支持 watchOS、tvOS 或 macOS,它们将在该页面的 SDK 下列出。)
您还可以在 Xcode SDK 中查看可用框架集:查看 Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS3.1.sdk/System/Library/Frameworks/
,或者查看 Xcode 编辑器窗格顶部的跳转栏watchOS 系统头文件的 ObjC 版本,或当您手动添加到项目的 WatchKit 扩展目标的链接框架和库时的可用选项列表。