作者:木木三623 | 来源:互联网 | 2023-05-18 15:08
任何人都可以帮我提供一个示例代码,用于在Apple Watchkit应用程序中添加Speech to Text转换功能.
1> BalestraPatr..:
是的,这是可能的.以下是文档:https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/occ/instm/WKInterfaceController/presentTextInputControllerWithSuggestions : allowedInputMode:
completion:
代码看起来像这样.您提供带有单词的建议数组(或表情符号),并设置允许输入模式,该模式只能接受动画表情符号,表情符号或计划文本.
[self presentTextInputControllerWithSuggestions:@[@"hello", @"world"] allowedInputMode:WKTextInputModePlain completion:^(NSArray *results) {
NSLog(@"results: %@", results);
}];
结果是这样的:
2> jfgrang..:
您可以询问用户输入并给他建议(参见下面的Swift示例).
self.presentTextInputControllerWithSuggestions(["suggestion 1", "suggestion 2"] allowedInputMode: .Plain, completion: { (answers) -> Void in
if reply && reply.count > 0 {
if let answer = answers[0] as? String {
println("\answer")
}
}
})
如果建议是零它直接进入听写.它不适用于模拟器,但它是真正的手表.