3

I wrote code to use dictation on my apple watch. I used presentTextInputControllerWithSuggestions without suggestions to directly start dictation.

But, I have two problem :

  • I want to start dictation when my app starts. For this, I call my function in the willActivate method but with this, just a waiting image appears in my screen, not my first page with dictation.
  • I want to stop dictation without press "Done" button. I don't know if it's possible and how can I make this.

There is my code :

func dictation(){
        self.presentTextInputControllerWithSuggestions([], allowedInputMode: WKTextInputMode.Plain, completion:{
            (results) -> Void in
                 //myCode
            })
    }
override func willActivate(){
   super.willActivate()
   dictation()
}

Do you have solutions ?

aBilal17
  • 2,974
  • 2
  • 17
  • 23
  • Related: http://stackoverflow.com/questions/35268552/how-to-stop-speech-recognition-dictation-in-apple-watch-when-the-user-stops-sp –  Jul 13 '16 at 13:10
  • What happens if you post the call to dictation after a short delay, or in didAppear? – Feldur Jul 13 '16 at 19:13
  • @Feldur I print log when I begin and finish a function. There are my logs : "start init end init start awakeWithContext end awakeWithContext start willactivate end willactivate start didAppear start dictation end didAppear" and I always have my waiting screen – Pierre Charpentier Jul 14 '16 at 06:11

1 Answers1

0

Thanks for your help @Feldur

I tried with delay and it seems to work

There is my code :

override init(){
    super.init()
    print("start init")
    let seconds = 1.0
    let delay = seconds * Double(NSEC_PER_SEC)  // nanoseconds per seconds
    let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
    dispatch_after(dispatchTime, dispatch_get_main_queue(), {
        self.dictation()
    })
    print("end init")
}

There are my logs :

start init
end init
start awakeWithContext
end awakeWithContext
start willactivate
end willactivate
start didAppear
end didAppear
start dictation

My screen appears and after, my dictation starts.

Do you have an idea for stop dictation when user stops speaking ?

  • You'll need to process the audio stream looking for silence (absence of energy) – Feldur Jul 14 '16 at 08:47
  • Thanks. Do you know if there is API or native component to do it ? – Pierre Charpentier Jul 14 '16 at 09:21
  • I don't. Maybe in AV? If you google on power spectra, you can find the math. – Feldur Jul 14 '16 at 12:58
  • Ok. I ill search more in this way. If somebody has another idea – Pierre Charpentier Jul 14 '16 at 13:35
  • I have been able to detect silences (to be exact: periods of time where volume is below the threshold) with a library called EZAudio (also allows you to make an animated graph of the voice waveform), unfortunately, it is now discontinued, but you can still use it. The problem is that I could only use it for iPhone apps, because WatchOS complains that EZAudio architecture is not supported, and I have now idea how to recompile it. – Josh Aug 02 '16 at 07:42