wit-ai / wit-ios

Wit.ai iOS client
Other
222 stars 71 forks source link

Error when enqueuing buffer from callback: -66632 #54

Closed thediary closed 7 years ago

thediary commented 9 years ago

Hi all,

After Wit logs "Starting.............." when the start method is called on the singleton instance accessor, I get a list of typically between 3-6 lines of the following: 2015-07-26 12:12:28.052 TheDiary[384:32483] Error when enqueuing buffer from callback: -66632 2015-07-26 12:12:28.052 TheDiary[384:32483] Error when enqueuing buffer from callback: -66632 2015-07-26 12:12:28.053 TheDiary[384:32483] Error when enqueuing buffer from callback: -66632 2015-07-26 12:12:28.053 TheDiary[384:32483] Error when enqueuing buffer from callback: -66632

All have the same timestamp and callback. My question is why I would be getting these errors and if its an error in implementation on my end, how can I fix it?

The error itself is logged in the following method of WitRecorder.m

#pragma mark - AudioQueue callbacks
static void audioQueueInputCallback(void* data,
                                AudioQueueRef q,
                                AudioQueueBufferRef buffer,
                                const AudioTimeStamp *ts,
                                UInt32 numberPacketDescriptions,
                                const AudioStreamPacketDescription *packetDescs) {
void * const bytes = buffer->mAudioData;
UInt32 size        = buffer->mAudioDataByteSize;
int err;

if (WIT_DEBUG) {
    debug(@"Audio chunk %u/%u", (unsigned int)size, (unsigned int)buffer->mAudioDataBytesCapacity);
}

if (size > 0) {
    NSData* audio = [NSData dataWithBytes:bytes length:size];
    @autoreleasepool {
        WITRecorder* recorder = (__bridge WITRecorder*)data;
        [recorder.delegate recorderGotChunk:audio];
        if (recorder.vad != nil) {
            [recorder.vad gotAudioSamples:audio];
        }
    }
}
err = AudioQueueEnqueueBuffer(q, buffer, 0, NULL);
if (err) {
    NSLog(@"Error when enqueuing buffer from callback: %d", err);
    }
}

Perhaps this is a clue. It definitely has to do with the audio chunk and not the recognition of the audio itself. Maybe saving the audio chunk and sending it to the console?

Thanks for your help!

hactar commented 9 years ago

I get this too, when the recording ends I guess wit tries to enqueue an empty sound buffer for a while until it notices it is done and kills the queue. Doesn't affect anything though, everything still works for me.

thediary commented 9 years ago

It's really just annoying in the logs and I don't want to modify the framework source files. Wit.ai Team–Is there anyway this could be fixed in a future version?

Sure it doesn't affect anything? I haven't noticed anything functioning improperly, but I'd hate to be missing something ; )

tielur commented 9 years ago

66632 is kAudioQueueErr_EnqueueDuringReset. Reset is being called with the stop function here.

The error states:

During a call to the AudioQueueReset, AudioQueueStop, or AudioQueueDispose functions, the system does not allow you to enqueue buffers.

Reference: kAudioQueueErr_EnqueueDuringReset Apple Docs

So I don't think there's an issue that this is causing, but that's why it's being caused.

tielur commented 9 years ago

I think a possible fix would be to move this line up before the call to the AudioQueueReset and then wrap the AudioQueueEnqueueBuffer call in an If block only when the state->recording is YES.

Thoughts?

The problem I see is if the call to the AudioReset or AudioPause fails then your state is out of wack. I suppose you could set it back to YES if those fail.

constantx commented 9 years ago

having the same issue

trylovetom commented 8 years ago

So does I.

agarwalashish commented 8 years ago

I am having the same issue. Is there a solution ?

louis-quaintance commented 8 years ago

Me too,

[DEBUG] Wit stopped recording because of a (network?) error
[ERROR] when enqueuing buffer from callback: -66632
[ERROR] when enqueuing buffer from callback: -66632
[ERROR] when enqueuing buffer from callback: -66632
[ERROR] when enqueuing buffer from callback: -66632
[ERROR] when enqueuing buffer from callback: -66632
[ERROR] Clean WITRecorder
[ERROR] Clean WITVad
hactar commented 7 years ago

This has been fixed in the current commit. Please reopen if you see this again.