【发布时间】:2016-10-15 18:22:00
【问题描述】:
我正在尝试继续。在 iOS 10 测试版上使用 AVCapture 进行语音识别。我已设置captureOutput(...) 以不断获取CMSampleBuffers。我将这些缓冲区直接放入我之前设置的SFSpeechAudioBufferRecognitionRequest 中:
... do some setup
SFSpeechRecognizer.requestAuthorization { authStatus in
if authStatus == SFSpeechRecognizerAuthorizationStatus.authorized {
self.m_recognizer = SFSpeechRecognizer()
self.m_recognRequest = SFSpeechAudioBufferRecognitionRequest()
self.m_recognRequest?.shouldReportPartialResults = false
self.m_isRecording = true
} else {
print("not authorized")
}
}
.... do further setup
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
if(!m_AV_initialized) {
print("captureOutput(...): not initialized !")
return
}
if(!m_isRecording) {
return
}
let formatDesc = CMSampleBufferGetFormatDescription(sampleBuffer)
let mediaType = CMFormatDescriptionGetMediaType(formatDesc!)
if (mediaType == kCMMediaType_Audio) {
// process audio here
m_recognRequest?.appendAudioSampleBuffer(sampleBuffer)
}
return
}
整个过程只持续了几秒钟。然后不再调用 captureOutput 。如果我注释掉 appendAudioSampleBuffer(sampleBuffer) 行,那么只要应用程序运行(如预期的那样),就会调用 captureOutput。显然,将样本缓冲区放入语音识别引擎会以某种方式阻止进一步的执行。我猜想可用的缓冲区会在一段时间后被消耗掉,并且进程会以某种方式停止,因为它无法再获得缓冲区???
我应该提到,在前 2 秒内记录的所有内容都会导致正确识别。我只是不知道 SFSpeech API 是如何工作的,因为 Apple 没有在 beta 文档中添加任何文本。顺便说一句:如何使用 SFSpeechAudioBufferRecognitionRequest.endAudio() ?
这里有人知道吗?
谢谢 克里斯
【问题讨论】:
-
在developer.apple.com/library/prerelease/content/samplecode/…查看苹果的示例代码,好像是在做连续实时识别
-
@DavidWilliames,该示例代码使用
AVAudioEngine而不是AVFoundation。 -
@chris 你是使用委托方法还是回调方法?
-
我在Objective c中实现:github.com/yao23/iOS_Playground/tree/master/…