WatchKit: Speech to text conversion in WatchKit Apps
Asked Answered
W

3

7

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

Wowser answered 11/3, 2015 at 10:53 Comment(1)
developer.apple.com/library/ios/samplecode/WKInterfaceCatalog/… , see text inputCart
C
13

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:

enter image description here

Cartouche answered 11/3, 2015 at 17:26 Comment(2)
Do you know of anyway to simulate the dictation? I know the simulator does not support it, and apple watch isn't out there yet, anyway to test this?Dayan
You can't test it in Simulator and I doubt it will be available anytime soon. It'll probably require a real device to test it.Cartouche
A
7

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.

Axiology answered 15/3, 2015 at 15:34 Comment(0)
F
0
self.presentTextInputControllerWithSuggestions(["Y","N"], allowedInputMode: WKTextInputMode.Plain,
    completion:{(results) -> Void in
        let aResult = results?[0] as? String
        print(aResult)
})
Felsite answered 27/10, 2015 at 23:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.