tags:

views:

1130

answers:

6

How would I go about using Stephen Celis' fantastic SCListener singleton?

(http://stephencelis.com/2009/03/02/now-i-just-need-an-audience.html)

I would like to start with something incredibly simple.. like display the input volume in a textview or just display a UIImage when the listener detects something.

Any help would be greatly appreciated!

Thanks!

+1  A: 

What don't you understand, SCListener is a very simple class.

Add the AudioToolbox framework to your project then include Stephen's sample code from his posting into your source file.

I suspect your question is actually "How do I make my app respond to the return values from SCListener?" SCListerner is not asynchonous. You need to poll it to get peakValues.

For your use, I suggest you set up a timer or, extend SCListener so that it generates a callback when a peak value is reached.

Roger Nolan
thanks for replying, roger!at this point I have a simple animation that I would like to play when SCListener detects something. Basically..theMouse = [[UIImageView alloc] initWithFrame:self.view.frame];theMouse.startAnimating;
dot
Thanks, Roger. If anyone could help me with some example code, I would be greatly indebted!
dot
+1  A: 
blowTimer = [NSTimer timerWithTimeInterval: 1 
       target: self 
       selector: @selctor(checkBlow) 
       userInfo: nil
       repeats: YES];

[[NSRunLoop currentRunLoop] addTimer: blowTimer
       forMode: NSDefaultRunLoopMode];

[[SCListener sharedListener] listen];

This code will basically fire up the listener, and call the checkBlow method every second.

The code for checkBlow will look something like this:

- (void) checkBlow
{
    if ([SCListener sharedListener] != nil)
    {
     Float32 volume = [[SCListener sharedListener] peakPower];

     if (volume > BlowingTriggerThreshold)
 {
     //DO SOMETHING AWESOME HERE
 }
    }
}
Farid
A: 

SCListener is not working in Device 3.0 version, can anyone help me out in this issue.

A: 

but peakpower & averagepower show me the same value

Néstor
A: 

SClistener works fine in the iphone simulator but not working on the device (3.1.3). It does NOT detec anyvolume (0.00). Any clue anyone??

Thanks Baba

Baba
A: 

SCListener is now obsolete. It predates the AVAudioRecorder which is now part of the SDK. Look at this tutorial for audio levels:

http://www.mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/

rob