How to get the linear PCM from a recording on iPhone?
-
03-06-2021 - |
Question
I want to do something like speaker verification on iPhone (as a course project). And I'm wondering how to get linear PCM from the speaker. I read about the documentation about queue services, and it seems that it records the sound and then store it to a file. Is there a way to get the linear PCM directly from this? The documentation mentioned something about the buffer, but I don't quite understand that. Maybe it's the key to doing this?
La solution
Audio Queue Services is for doing this. Just type in the code you need in the call back function. http://developer.apple.com/library/ios/#documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005343
Autres conseils
AVAudioRecorder *audioRecorder = [[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error];
audioRecorder.delegate = self;
audioRecorder.meteringEnabled = YES;
then start recording using a NSTimer such as invoke the timer when you click the record button
-(IBAction)record:(id)sender{
NSTimer *recordTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self
selector:@selector(recordTimerAction:) userInfo:nil repeats:YES];
}
-(void)recordTimerAction:(id)sender {
[audioRecorder updateMeters];
const double ALPHA = 0.05;
double peakPowerForChannel = pow(10, (0.05 * [audioRecorder peakPowerForChannel:0]));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
NSLog(@"The Amplitude of the recording Sound is %f",lowPassResults);
NSLog(@"The Normal Linear PCM Value is %f",[audioRecorder peakPowerForChannel:0]);
}
// Delegate method
-(void)audioRecorderDidFinishRecording: (AVAudioRecorder *)recorder successfully:(BOOL)flag{
[recordTimer invalidate];
}