【问题标题】:WatchKit: Speech to text conversion in WatchKit AppsWatchKit:WatchKit 应用程序中的语音到文本转换
【发布时间】:2015-03-11 10:53:04
【问题描述】:

谁能帮我提供在 Apple Watchkit 应用程序中添加语音到文本转换功能的示例代码。

【问题讨论】:

标签: iphone ios8 watchkit siri


【解决方案1】:

是的,这是可能的。这是文档: 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 还没有,无论如何要测试这个?
  • 你不能在模拟器中测试它,我怀疑它很快就会可用。它可能需要一个真实的设备来测试它。
  • @TejaKumarBethina 如果此答案有帮助,请将其标记为 :)
【解决方案2】:

您可以要求用户输入并给他建议(参见下面的 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")
        }
    }
})

如果 suggestionnil,则它直接进入听写。它在模拟器上不起作用,但在真实手表上。

【讨论】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多