如果我检查了回调中的SFSpeechRecognizer
recognitionTask
回调标记(在 macOS 上):
recognitionTask = speechRecognizer.recognitionTask( with: recognitionRequest )
{ result, error in
// if more than two seconds elapsed since the last update, we send a notification
NSLog( "speechRecognizer.recognitionTask callback" )
:
...我观察到:
:
2019-11-08 14:51:00.35 ... speechRecognizer.recognitionTask callback
2019-11-08 14:51:00.45 ... speechRecognizer.recognitionTask callback
2019-11-08 14:51:32.31 ... speechRecognizer.recognitionTask callback
即在我最后一次发言后大约 30 秒,还有一个额外的不需要的回调。
result
用于nil
最后一次回调。
它接近 30 秒的事实表明它代表了最大超时。
我不希望超时,因为我已经手动关闭了我的会话(在 5 秒左右,通过单击一个按钮):
@objc
func stopRecording()
{
print( "stopRecording()" )
// Instructs the task to stop accepting new audio (e.g. stop recording) but complete processing on audio already buffered.
// This has no effect on URL-based recognition requests, which effectively buffer the entire file immediately.
recognitionTask?.finish()
// Indicate that the audio source is finished and no more audio will be appended
recognitionRequest?.endAudio()
//self.recognitionRequest = nil
audioEngine.stop()
audioEngine.inputNode.removeTap( onBus: 0 )
//recognitionTask?.cancel()
//self.recognitionTask = nil
self.timer?.invalidate()
print( "stopRecording() DONE" )
}
有很多注释掉的代码,因为在我看来,有些进程我无法关闭,但我无法弄清楚。
完整的代码在这里。
谁能看到出了什么问题?