It seems I do get the same crash on my iOS code. I could not reproduce it, but get between 1 and 4 crashes from every 200 user sessions. Any hints on how to solve this issue would be highly appreciated.
Here is my code (very similar to code shown above):
private func transcribe() {
guard let recognizer, recognizer.isAvailable else {
print("--- SpeechRec.transcribe - SpeechRecognizer TRANSCRIBE ERROR: \(RecognizerError.recognizerIsUnavailable)")
return
}
do {
if let audioEngine {
let request = SFSpeechAudioBufferRecognitionRequest()
request.shouldReportPartialResults = true
request.requiresOnDeviceRecognition = false // might fix speechRec error 1101 in console
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.playAndRecord, mode: .measurement, policy: .default, options: .duckOthers)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let inputNode = audioEngine.inputNode
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, _) in
request.append(buffer)
}
try audioEngine.start()
self.recognitionTask = recognizer.recognitionTask(with: request, delegate: self)
} else {
let (audioEngine, request) = try Self.prepareEngine()
self.audioEngine = audioEngine
self.request = request
self.recognitionTask = recognizer.recognitionTask(with: request, delegate: self)
}
} catch {
Logger.audio.error("--- SpeechRec.transcribe - SpeechRecognizer AudioSession/AudioEngine ERROR: \(error)")
self.reset()
}
}
This is the backtrace that the Organizer shows in Xcode:
Last Exception Backtrace (0)
#0 (null) in __exceptionPreprocess ()
#1 (null) in objc_exception_throw ()
#2 (null) in +[NSException raise:format:arguments:] ()
#3 (null) in AVAE_RaiseException(NSString*, ...) ()
#4 (null) in AVAudioIONodeImpl::SetOutputFormat(unsigned long, AVAudioFormat*) ()
#5 (null) in AUGraphNodeBaseV3::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer) ()
#6 (null) in -[AVAudioNode installTapOnBus:bufferSize:format:block:] ()
#7 0x100d34e10 in SpeechRecognizer.transcribe() at /Users/klaus/Developer/ScriptBuddy/ScriptBuddy/Assistants/SpeechRecognizer.swift:245
#8 0x100d34298 in SpeechRecognizer.startTranscribing(andCompareTo:) at /Users/klaus/Developer/ScriptBuddy/ScriptBuddy/Assistants/SpeechRecognizer.swift:167
#9 (null) in Script.speakNextScriptElement() ()
#10 0x100d43bfc in specialized SpeechSynthesizer.speechSynthesizer(_:didFinish:) at /Users/klaus/Developer/ScriptBuddy/ScriptBuddy/Assistants/SpeechSynthesizer.swift:942
#11 (null) in SpeechSynthesizer.speechSynthesizer(_:didFinish:) ()
#12 (null) in @objc SpeechSynthesizer.speechSynthesizer(_:didFinish:) ()
#13 (null) in -[AVSpeechSynthesizer(PublicSpeechImplementation) processSpeechJobFinished:successful:] ()
#14 (null) in -[AVSpeechSynthesizer(PublicSpeechImplementation) _handleSpeechDone:successful:] ()
#15 (null) in __67-[AVSpeechSynthesizer(PublicSpeechImplementation) _speakUtterance:]_block_invoke_6 ()
#16 (null) in __46-[TTSSpeechManager _speechJobFinished:action:]_block_invoke ()
#17 (null) in _dispatch_call_block_and_release ()
#18 (null) in _dispatch_client_callout ()
#19 (null) in _dispatch_main_queue_drain ()
#20 (null) in _dispatch_main_queue_callback_4CF ()
#21 (null) in __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ ()
#22 (null) in __CFRunLoopRun ()
#23 (null) in CFRunLoopRunSpecific ()
#24 (null) in GSEventRunModal ()
#25 (null) in -[UIApplication _run] ()
#26 (null) in UIApplicationMain ()
#27 (null) in closure #1 in KitRendererCommon(_:) ()
#28 (null) in runApp<A>(_:) ()
#29 (null) in static App.main() ()
#30 (null) in static ScriptBuddyApp.$main() ()
#31 (null) in main ()
#32 (null) in start ()