WatchKit:在WatchKit应用中进行语音转文本转换

7

有没有人能帮我提供一段示例代码,用于在Apple Watchkit应用程序中添加语音转文本功能。


2
请查看以下网址并转到文本输入部分:https://developer.apple.com/library/ios/samplecode/WKInterfaceCatalog/Introduction/Intro.html - sheraza
3个回答

13
是的,这是可能的。以下是文档链接: 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);
}];

结果如下:

这就是结果:

在此输入图片描述


你知道模拟口述的方法吗?我知道模拟器不支持它,而且Apple Watch还没有推出,有什么办法可以测试这个功能吗? - prawn
1
你无法在模拟器中测试它,我怀疑它不会很快提供。它可能需要一个真实的设备来测试。 - BalestraPatrick
如果这个答案有帮助,请标记一下 :) - BalestraPatrick

7
你可以请求用户输入并为其提供建议(请参见下面的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")
        }
    }
})

如果建议的,它会直接转到听写。它在模拟器上不起作用,但在真正的手表上起作用。

0
self.presentTextInputControllerWithSuggestions(["Y","N"], allowedInputMode: WKTextInputMode.Plain,
    completion:{(results) -> Void in
        let aResult = results?[0] as? String
        print(aResult)
})

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接