1

I am using SFSpeechRecognizer work fine but when recording start in continues in background that time get incoming call app crash.

i am using this code

 AVAudioSession *session = [AVAudioSession sharedInstance];
    NSError *error = nil;
    [session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
    [session setMode:AVAudioUnitTypeMixer error:&error];


AVAudioFormat *format = [inputNode outputFormatForBus:0];
    [inputNode removeTapOnBus:0];

    if (inputNode != nil)
    {
        [inputNode installTapOnBus: 0 bufferSize: 8192 format: format block: ^(AVAudioPCMBuffer *buf, AVAudioTime *when)
         {
             [recognitionRequest appendAudioPCMBuffer:buf];
         }];
    }

 [audioEngine prepare];

error generate by xcode.

failed: '!pri' (enable 1, outf< 2 ch,      0 Hz, Float32, non-inter> inf< 1 ch,  44100 Hz, Float32>)
 [central] 54:   ERROR:    [0x1af844c40] >avae> AVAudioIONodeImpl.mm:883: SetOutputFormat: required condition is false: IsFormatSampleRateAndChannelCountValid(hwFormat)
Nilesh Parmar
  • 399
  • 5
  • 14

1 Answers1

1

You have to respond to app interruptions to prevent it from crashing. For example: Incase of an interrupt like incoming call,

After interruption starts Save state and context Update user interface

After interruption ends Restore state and context Reactivate audio session if app appropriate Update user interface

Please refer to link for further information Audio Session Programming Guide

For example,

 AVAudioSession *session=[AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleInterruption:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:session];
- (void)handleInterruption:(NSNotification *)notification{}

Once you handle this particular usecase, you should be good to go.

Shaheen M Basheer
  • 1,010
  • 6
  • 11