WatchKit: Speech to text conversion in WatchKit Apps

自闭症网瘾萝莉.ら 提交于 2019-11-28 08:13:05

问题


Can any one help me with a sample code for adding Speech to Text conversion feature in Apple Watchkit apps.


回答1:


Yes, it's possible. Here is the documentation: https://developer.apple.com/library/prerelease/ios/documentation/WatchKit/Reference/WKInterfaceController_class/index.html#//apple_ref/occ/instm/WKInterfaceController/presentTextInputControllerWithSuggestions:allowedInputMode:completion:

The code look like this. You provide a suggestions array with words (or emoji too) and you set the allowed input mode that can accept animated emoji, emoji or plan text only.

[self presentTextInputControllerWithSuggestions:@[@"hello", @"world"] allowedInputMode:WKTextInputModePlain completion:^(NSArray *results) {
    NSLog(@"results: %@", results);
}];

The result is this:




回答2:


You can ask for user input and give him suggestion (see Swift example bellow).

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

If suggestion is nil it goes directly to dictation. It is not working on the simulator but it is on real watch.




回答3:


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


来源:https://stackoverflow.com/questions/28984678/watchkit-speech-to-text-conversion-in-watchkit-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!