Ios 当用户结束讲话时停止语音识别
Siri是如何确定我何时结束发言的。我想知道的原因是,我想在我的应用程序中使用苹果的语音识别API实现类似的功能。这是可行的,还是只有通过用户输入才能知道用户何时停止讲话?你可以使用计时器,我也有同样的问题,我无法用优雅的方法解决Ios 当用户结束讲话时停止语音识别,ios,swift,speech-recognition,Ios,Swift,Speech Recognition,Siri是如何确定我何时结束发言的。我想知道的原因是,我想在我的应用程序中使用苹果的语音识别API实现类似的功能。这是可行的,还是只有通过用户输入才能知道用户何时停止讲话?你可以使用计时器,我也有同样的问题,我无法用优雅的方法解决 fileprivate var timer:Timer? func startRecordingTimer() { lastString = "" createTimerTimer(4) } func stopRecordingTimer() {
fileprivate var timer:Timer?
func startRecordingTimer() {
lastString = ""
createTimerTimer(4)
}
func stopRecordingTimer() {
timer?.invalidate()
timer = nil
}
fileprivate func whileRecordingTimer() {
createTimerTimer(2)
}
fileprivate var lastString = ""
func createTimerTimer(_ interval:Double) {
OperationQueue.main.addOperation({[unowned self] in
self.timer?.invalidate()
self.timer = Timer.scheduledTimer(withTimeInterval: interval, repeats: false) { (_) in
self.timer?.invalidate()
if(self.lastString.characters.count > 0){
//DO SOMETHING
}else{
self.whileRecordingTimer()
}
}
})
}
在SFSpeechRecognitionTaskDelegate
public func speechRecognitionTask(_ task: SFSpeechRecognitionTask, didHypothesizeTranscription transcription: SFTranscription) {
let result = transcription.formattedString
lastString = result
}
我的理解是,您不需要处理“当用户结束讲话时”。您应该在此处阅读SiriKit指南:。基本上SiriKit通过从用户语音中收集的数据为您提供了一个“意图”,您只需要处理意图并执行自己的操作。问题是询问语音识别API,而不是SiriKit。幸运吗?我自己也在努力解决这个问题有什么更新吗?