您好,我在iOS中有点新鲜,我有一个特殊的任务,首先我用AVAudioRecorder录制声音,我可以录制和播放它没有麻烦,但我需要在这里记录的数据是我的职能:
@interface recordViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate>
{
AVAudioRecorder *audioRecorder;
AVAudioPlayer *audioPlayer;
UIButton *playButton;
UIButton *recordButton;
UIButton *stopButton;
}
记录:
-(void) recordAudio {
if (!audioRecorder.recording)
{
playButton.enabled = NO;
stopButton.enabled = YES;
[audioRecorder record];
}
}
播放:
-(void) playAudio {
if (!audioRecorder.recording)
{
stopButton.enabled = YES;
recordButton.enabled = NO;
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:audioRecorder.url
error:&error];
audioPlayer.delegate = self;
if (error)
NSLog(@"Error: %@", [error localizedDescription]);
else
[audioPlayer play];
}
}
如何获取记录中的数据?我在iOS Developer API中搜索过,我找不到任何东西,谢谢你们。
答案 0 :(得分:0)
我还没试过这个解决方案。但这可能会有所帮助。试试吧。
录制音频:
itsVoiceRecordedURL = [NSURL fileURLWithPath:[NSString stringWithFormat:<Path of the recorded file to be stored>]];
NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
itsAudioRecorder = [[ AVAudioRecorder alloc] initWithURL:itsVoiceRecordedURL settings:recordSetting error:&error];
[recordSetting release];
[itsAudioRecorder setDelegate:self];
//We call this to start the recording process and initialize
//the subsstems so that when we actually say "record" it starts right away.
[itsAudioRecorder prepareToRecord];
//Start the actual Recording
[itsAudioRecorder record];
将录制的音频文件转换为字节数组
NSData *data = [NSData dataWithContentsOfFile:AudioFilePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);