AVAudioEngine inputNode installTap crash when restarting recording

后端 未结 5 1989
猫巷女王i
猫巷女王i 2020-12-14 18:59

I am implementing Speech Recognition in my app. When I first present the view controller with the speech recognition logic, everything works fine. However, when I try presen

5条回答
  •  盖世英雄少女心
    2020-12-14 19:33

    First, a small issue. When tapping the device's microphone, you'll want to use the format of the input bus:

    let recordingFormat = node.inputFormat(forBus: 0)
    

    Second, after some digging it seems like this crash most commonly stems from your application's shared AVAudioSession category settings. Make sure you have your audio session configured like so if you're going to be performing live microphone audio processing:

    private func configureAudioSession() {
        do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: .mixWithOthers)
            try AVAudioSession.sharedInstance().setActive(true)
        } catch { }
    }
    

提交回复
热议问题