1

I am trying to implement Speech-to-text feature for watchkit app. I referred this question which has sample code.

Following is the code I tried:

self.presentTextInputControllerWithSuggestions(["Start it", "Stop it"], allowedInputMode: .Plain, completion: { (selectedAnswers) -> Void in
    if selectedAnswers.count > 0 {
        if let spokenReply = selectedAnswers[0] as? String {
            self.label.setText("\(spokenReply)")
        }
    }
})

label is a label to display text I speak. When I run it, it shows the screen where you are supposed to speak (Siri kind of screen) and you have two options on top: ‘Cancel', and ‘Done'. Once I am done speaking, I tap on ‘Done’ but screen doesn’t go away or shows me initial screen, I always have to tap on ‘Cancel’ to go back, and I don’t get any speech data in form of text. I checked it and seems like selectedAnswers is always an empty array, unless I tap on the "Start it"/"Stop it" options.

Can anyone help me with this? I want to show the spoken message on label. I have code inside awakeWithContext method in InterfaceController.swift file, am I supposed to put it somewhere else?

I am using iPhone with iOS 9 beta 2 and watchOS 2 beta on AppleWatch.

Thanks!

Community
  • 1
  • 1
user2312896
  • 389
  • 3
  • 14

1 Answers1

1

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 answers && answers.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.

Your approach is correct but something is wrong with your SIRI , try changing the language.

It should work like these.

Community
  • 1
  • 1
  • So what is `reply` in your code? How do you get it and where should it be defined? (I thought it is supposed to be `answers` and not `reply`) – user2312896 Jul 02 '15 at 17:27
  • There was some problem with Siri on my iPhone because of which it wasn't converting speech to text, now it's working fine, thanks! – user2312896 Jul 02 '15 at 17:37
  • happy.to hear.that.!! enjoy coding :) –  Jul 03 '15 at 05:42