title: Record sound when speaking to mic
body: <p>I want to write controller which handles sound recording. It should record sound when there is sound in mic. </p>
  
  <p>I have working code on recording sound when button is pressed.</p>
  
  <pre><code>-(IBAction) startRecording
  {
      NSLog(@"startRecording");
      audioRecorder = nil;
  
      // Init audio with record capability
      AVAudioSession *audioSession = [AVAudioSession sharedInstance];
      [audioSession setCategory:AVAudioSessionCategoryRecord error:nil];
  
      NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
     // if(recordEncoding == ENC_PCM)
      //{
  
          [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
          [recordSettings setObject:[NSNumber numberWithFloat:500.0] forKey: AVSampleRateKey];//44100.0
          [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
          [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
          [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
          [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
  
     // NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/recordTest.caf", [[NSBundle mainBundle] resourcePath]]];
  
      NSURL *url = [NSURL URLWithString:[self copyFile:@"recordTest.caf"]];
  
  
  
      NSError *error = nil;
      audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&amp;error];
      [audioRecorder setDelegate:self];
  
      if ([audioRecorder prepareToRecord] == YES){
          [audioRecorder record];
          NSLog(@"recording");
      }else {
          int errorCode = CFSwapInt32HostToBig ([error code]);
          NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&amp;errorCode);
  
      }
  
  }
  </code></pre>
  
  <p>So is it possible to record or monitor sounds from mic input and start recording when sound is above for example 1000 Hz ?</p>
  
  <p>I would also appreciate for literature on this. </p>
  
  <p>Thanks.</p>