Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my <code>- (void)setUpAudio</code> method I have created a dictionary which holds the settings for the AVAudioRecorder.(It's a bit cleaner) Your code above is almost correct, but not quite. See below. </p> <pre><code>// empty URL NSURL *url = [NSURL fileURLWithPath:@"/dev/null"]; // define settings for AVAudioRecorder NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithFloat: 44100.0], AVSampleRateKey, [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey, [NSNumber numberWithInt:1], AVNumberOfChannelsKey, [NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey, nil]; NSError *error; // init and apply settings recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&amp;error]; // This here is what you are missing, without it the mic input will work in the simulator, // but not on a device. AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; if (recorder) { [recorder prepareToRecord]; recorder.meteringEnabled = YES; NSTimer *levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(levelTimerCallback:) userInfo:nil repeats:YES]; [recorder record]; } else { NSLog([error description]); } </code></pre> <p>Then in the update method you can keep track of your mic input levels like this. </p> <pre><code>- (void)levelTimerCallback:(NSTimer *)timer { [recorder updateMeters]; NSLog(@"Average input: %f Peak input: %f", [recorder averagePowerForChannel:0], [recorder peakPowerForChannel:0]); } </code></pre> <p>Any questions or ways I can improve my answer please let me know. Still pretty new around here. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload