Question

I've been looking at the thread re: voice detection (http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/).

I'm looking to implement something similar, however, with the following variation.

The levelTimer in that example fires continuously every .03 seconds. I essentially need to wrap another timer around this so that the voice check process only runs for (say) 10 seconds.

I'm finding that having something like:

outerTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
                                              target:self
                                            selector:@selector(outerTimerFinished:)
                                            userInfo:nil
                                             repeats:NO];

levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
                                              target:self
                                            selector:@selector(listenForSounds:)
                                            userInfo:nil
                                             repeats:YES];

…where outerTimerFinished method calls [levelTimer invalidate] isn't working - maybe due to thread blocking?

So can someone help me determine a way for levelTimer to do its work, but only for a specific amount of time?

Thanks.

Was it helpful?

Solution

Put a counter in the listenForSounds: method, and increment it each time the method is called. If you want to run the levelTimer for 10 seconds say, then check for when the counter > 333 and then invalidate the timer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top