フレームワークを使用AVAudioRecorder
しAVAudioPlayer
て、iPhoneで録音されたオーディオを録音および再生しています。それは働いています。マイクを使用して録音し、再生できます。
しかし、録音したオーディオから pcm データを取得する必要があります。サウンドを変更するために使用しているLE_SpectrumWorkx
ため、入力データに「.pcm」が必要です。pcm データを取得して送信する必要がありますLE_SpectrumWorkx
(詳細については、http ://www.littleendian.com を参照してください)。
録音したオーディオから pcm データを取得するにはどうすればよいですか? 「sound.caf」を任意の型に変換する必要がありますか?
ここに現在のコードがあります:
@synthesize btnRecord, btnPlay, btnStop, txtResult;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
btnPlay.enabled = NO;
btnStop.enabled = NO;
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings =
[
NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt:AVAudioQualityMin], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16], AVEncoderBitRateKey,
[NSNumber numberWithInt:2], AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
nil
];
NSError *error = nil;
audioRecorder =
[
[AVAudioRecorder alloc]
initWithURL:soundFileURL
settings:recordSettings
error:&error
];
if(error)
{
NSLog(@"error: %@", [error localizedDescription]);
}
else
{
[audioRecorder prepareToRecord];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
audioPlayer = nil;
audioRecorder = nil;
btnRecord = nil;
btnPlay = nil;
btnStop = nil;
}
- (void)dealloc
{
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(IBAction)onRecord:(id)sender
{
NSLog(@" //-- record start button clicked");
if(!audioRecorder.recording)
{
btnPlay.enabled = NO;
btnStop.enabled = YES;
[audioRecorder record];
}
}
-(IBAction)onStop:(id)sender
{
NSLog(@" //-- record stop button clicked");
btnStop.enabled = NO;
btnPlay.enabled = YES;
btnRecord.enabled = YES;
if(audioRecorder.recording)
{
[audioRecorder stop];
}
else
{
[audioPlayer stop];
}
}
-(IBAction)onPlayAudio:(id)sender
{
NSLog(@" //-- play");
if(!audioRecorder.recording)
{
btnStop.enabled = YES;
btnRecord.enabled = NO;
// if(audioPlayer) [audioPlayer release];
NSError *error;
audioPlayer = [
[AVAudioPlayer alloc]
initWithContentsOfURL:audioRecorder.url
error:&error
];
audioPlayer.delegate = self;
if(error)
{
NSLog(@"Error: %@", [error localizedDescription]);
}
else
{
[audioPlayer play];
}
}
}
-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
NSLog(@"Playback Finished");
btnRecord.enabled = YES;
btnStop.enabled = NO;
[self onStop:nil];
}
-(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
{
NSLog(@"Decode Error occured");
}
-(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
NSLog(@"Record Finished");
}
-(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error
{
NSLog(@"Encode Error occured");
}