Question

I'm trying to capture music from an iPhone 4s microphone, using the Gracenote API.

When running on the device, the application gets closed by the OS with failed to launch in time when calling startRecordingon an instance ofGNAudioSourceMic. Find the log below. I copy & pasted most of the code from the GN example app, which is working fine.

There are no issues running it through the simulator.

    - (void)mk_initialize
    {
    AudioSessionInitialize (
                            NULL,
                            NULL,
                            interruptionListenerCallback,
                            (__bridge void *)(self)
                            );
    @try {
        _config = [GNConfig init:GN_CLIENT_ID];
    }
    @catch (NSException * e) {
        NSLog(@"clientId issue");
        return;
    }

    [self.config setProperty: @"debugEnabled"
                       value: @"1"];
    _recognizeFromStream = [GNRecognizeStream gNRecognizeStream:self.config];
    _audioConfig = [GNAudioConfig gNAudioConfigWithSampleRate:44100
                                               bytesPerSample:2
                                                 numChannels:1];
    _audioSourceMicObj = [GNAudioSourceMic gNAudioSourceMic:self.audioConfig];
    self.audioSourceMicObj.delegate = self;

     NSError *error = nil;
    [RecognizeStreamOperation recognizeStreamOperation:self.config];
    error = [self.recognizeFromStream startRecognizeSession:op
                                            audioConfig:self.audioConfig];
    if (error) {
        NSLog(@"ERROR: %@",[error localizedDescription]);
    }
    [self.audioSourceMicObj startRecording]; // hanging call

    [self performSelectorInBackground:@selector(setUpRecognizePCMSession)
                           withObject:nil];
}

Device Log:

OS Version:      iOS 6.1.3 (10B329)
Report Version:  104

Exception Type:  00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread:  0

Application Specific Information:
XXXXXXX failed to launch in time

Elapsed total CPU time (seconds): 3.080 (user 3.080, system 0.000), 15% CPU 
Elapsed application CPU time (seconds): 0.527, 3% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_kernel.dylib          0x397ab0fc __psynch_mutexwait + 24
1   libsystem_c.dylib               0x396f4124 pthread_mutex_lock + 388
2   AudioToolbox                    0x30fd54e8 CAMutex::Lock() + 32
3   AudioToolbox                    0x3102645c AUConverterBase::Reset(unsigned long,   unsigned long) + 48
4   AudioToolbox                    0x310df602 AUGenericOutput::Start() + 26
5   AudioToolbox                    0x310d1126 AURemoteIO::Start() + 942
6   AudioToolbox                    0x31100776 AUMethodStart(void*) + 118
.
.
.
Was it helpful?

Solution

Is another application on your device using the microphone when you try to launch your app? You should make sure to set the audio session category to one that supports recording, and also activate the audio session prior to calling start on the GnAudioSourceMic instance. For example:

NSError *error = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord   error:&error];
if (error) {
    NSLog(@"Error setting audio session category: %d, %@", [error code], [error description]);
}
[[AVAudioSession sharedInstance] setActive:YES error:&error];
if (error) {
    NSLog(@"Error activating audio session category: %d, %@", [error code], [error description]);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top