代码之家  ›  专栏  ›  技术社区  ›  Teja Kumar Bethina

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

  •  7
  • Teja Kumar Bethina  · 技术社区  · 11 年前

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

    3 回复  |  直到 11 年前
        1
  •  13
  •   BalestraPatrick    11 年前

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

    结果是:

    enter image description here

        2
  •  7
  •   jfgrang    11 年前

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

    如果 建议 直接进行听写 。它没有在模拟器上运行,但正在实时监视。

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