我想编写处理录音的控制器。当麦克风中有声音时,它应该录制声音。
按下按钮时,我有录制声音的工作代码。
-(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:&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*)&errorCode);
}
}
那么是否可以录制或监控来自麦克风输入的声音并在声音高于例如 1000 Hz 时开始录制?
我也很欣赏这方面的文献。
谢谢。