Post

Replies

Boosts

Views

Activity

Comment on Random AVAudioEngine crash
Under Organizer -> Crashes section in xCode, the log tells me that the error was thrown from mystartRecording() function. I will also post bellow the code for it and maybe someone with more experience can help me to identify what I'm doing wrong and why AVAudioEngine is crashing. func startRecording() {           startStopRecordBtn.setImage(UIImage(#imageLiteral(resourceName: "microphone_off")), for: .normal)     commentTextView.isUserInteractionEnabled = false     recordingLabel.text = Constants.recording           if recognitionTask != nil {       recognitionTask?.cancel()       recognitionTask = nil     }           let audioSession = AVAudioSession.sharedInstance()     do {       try audioSession.setCategory(AVAudioSession.Category.record)       try audioSession.setMode(AVAudioSession.Mode.measurement)       try audioSession.setActive(true, options: .notifyOthersOnDeactivation)     } catch {       showAlertWithTitle(message: Constants.error)     }           recognitionRequest = SFSpeechAudioBufferRecognitionRequest()           let inputNode = audioEngine.inputNode           guard let recognitionRequest = recognitionRequest else {       fatalError(Constants.error)     }           recognitionRequest.shouldReportPartialResults = true           recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in               var isFinal = false               if result != nil {                   self.commentTextView.text = result?.bestTranscription.formattedString         isFinal = (result?.isFinal)!       }               if error != nil || isFinal {         self.audioEngine.stop()         inputNode.removeTap(onBus: 0)                   self.recognitionRequest = nil         self.recognitionTask = nil                   self.startStopRecordBtn.isEnabled = true       }     })           let recordingFormat = inputNode.outputFormat(forBus: 0)     inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer, when) in       self.recognitionRequest?.append(buffer)     }           audioEngine.prepare()           do {       try audioEngine.start()     } catch {       showAlertWithTitle(message: Constants.error)     }   }
Mar ’22