繁体   English   中英

如何在Apple Watch中按下按钮开始和停止听写

[英]How to start and stop dictation in Apple Watch witout pressing button

我编写代码在我的苹果手表上使用听写。 我使用presentTextInputControllerWithSuggestions而没有建议直接开始听写。

但是,我有两个问题:

  • 我想在我的应用程序启动时开始听写。 为此,我在willActivate方法中调用我的函数,但是这样,我的屏幕上只显示一个等待的图像,而不是我的第一页带有听写。
  • 我想在不按“完成”按钮的情况下停止听写。 我不知道是否可能,我怎么能做到这一点。

有我的代码:

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

你有解决方案吗?

谢谢你的帮助@Feldur

我试着延迟,似乎工作

有我的代码:

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

有我的日志:

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

我的屏幕出现之后,我的听写开始了。

当用户停止说话时,您是否有停止听写的想法?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM