Sunday, July 19, 2026
HomeiOS DevelopmentUnable to make use of mic dictation correctly in iOS swift app...

Unable to make use of mic dictation correctly in iOS swift app utilizing AVAudioSession

[ad_1]

I get this error in my app:

Terminating app as a result of uncaught exception 'com.apple.coreaudio.avfaudio', motive: 'required situation is fake: IsFormatSampleRateAndChannelCountValid(format)'
terminating with uncaught exception of kind NSException

I’ve traced the error and it stems from the code the place I’m making an attempt to report dictations by the mic:

func startSpeechRecognization(){
        let node = audioEngine.inputNode
        
        do {
            strive AVAudioSession.sharedInstance().setCategory(AVAudioSession.Class.playAndRecord, choices: .mixWithOthers)
            strive AVAudioSession.sharedInstance().setActive(true)
        } catch let error {
            print("startSpeechRecognization: (error.localizedDescription)")
        }
        
        node.installTap(onBus: 0, bufferSize: 1024, format: node.outputFormat(forBus: 0)) { (buffer, _) in
            self.request.append(buffer)
        }
.
.
.

I’ve learn by related errors that match mine the place they are saying I’ve to set AVAudioSession correctly earlier than utilizing the mic. I’ve additionally gone over the half the place I ought to try to use node.inputFormat as an alternative of node.outputFormat in my installTap.

The one different place the place I’m altering AVAudioSession is within the viewDidLoad as seen beneath:

override func viewDidLoad() {
        tremendous.viewDidLoad()
        // To disregard the mute Swap
        // ====================================================================================
        do {
            strive AVAudioSession.sharedInstance().setCategory(.playback, choices: .defaultToSpeaker)
            strive AVAudioSession.sharedInstance().setActive(true, choices: .notifyOthersOnDeactivation)
        } catch let error {
            print("This error message from SpeechSynthesizer (error.localizedDescription)")
        }
        // ====================================================================================
.
.
.

I’m making an attempt to transcribe dictation in my app, however I nonetheless have not discovered an answer to my drawback. Hopefully I can get some assist right here.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments