Watchkit:通过WKInterfaceController单击文本听写

时间:2015-05-26 13:29:27

标签: ios watchkit speech-to-text dictation

根据Apple的WKInterfaceController文档,您可以让用户以这种非常简单的方式指示预先设置新界面控制器的文本:

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")
    }
}

})

解释here

我已经看到Apple Watch的Apple App允许您通过直接点击搜索图标来搜索产品

enter image description here

所以你一步进入听写

enter image description here

通过WKInterfaceController方法,我们会得到不同的东西

enter image description here

哪个Apple的亚马逊应用程序API正在使用这种方式启用听写?

(UPDATE) 我刚刚发现,here

解释说它非常简单

所以我出来的最终解决方案就是这个

    - (void) table:(WKInterfaceTable *)table didSelectRowAtIndex:(NSInteger)rowIndex {
if (rowIndex==0) { // handle manual selection
    __weak MainInterfaceController *weakSelf = self;
    [self presentTextInputControllerWithSuggestions:nil allowedInputMode:WKTextInputModePlain completion:^(NSArray *results) {
       if(results && [results count]>0) {
           NSString *inputText=nil;
           for(NSString *input in results) {
               NSLog(@"Input %@", input);
               inputText=input;
               break;
           }
           if(inputText!=nil && [inputText length]>0) {
               [weakSelf pushControllerWithName:@"Search" context:
                [NSDictionary dictionaryWithObjectsAndKeys:
                 inputText, @"query", nil]
                ];
           }
       } else {
           NSLog(@"No input provided");
       }
   }];
}}

2 个答案:

答案 0 :(得分:2)

将模式设置为.Plain,并且不提供任何建议。

答案 1 :(得分:1)

如果删除建议的字符串数组,它将直接进入听写模式。

相关问题