WatchKit:WatchKit应用程序中的语音到文本转换

Tej*_*ina 6 iphone siri ios8 watchkit

任何人都可以帮我提供一个示例代码,用于在Apple Watchkit应用程序中添加Speech to Text转换功能.

Bal*_*ick 12

是的,这是可能的.以下是文档: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);
}];
Run Code Online (Sandbox Code Playgroud)

结果是这样的:

在此输入图像描述


jfg*_*ang 6

您可以询问用户输入并给他建议(参见下面的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")
        }
    }
})
Run Code Online (Sandbox Code Playgroud)

如果建议直接进入听写.它不适用于模拟器,但它是真正的手表.