我想在录制时检测声音。如果声音停止 2-3 秒,则录音应自动停止。
有什么办法吗?我已经完成了录制:-
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ddMMyyyyhh:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *dateString = [dateFormatter stringFromDate:now];
dateString=[NSString stringWithFormat:@"%@.caf",dateString];
soundFilePath = [docsDir
stringByAppendingPathComponent:dateString];
NSLog(@"soundFilePath==>%@",soundFilePath);
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
[soundFilePath retain];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],
AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],
AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],
AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],
AVSampleRateKey,
nil];
NSError *error = nil;
recorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
} else {
[recorder prepareToRecord];
}
[recorder record];
提前致谢