mercredi 11 février 2015

IOS:Audio Recording in HE AAC encoder and 3gp as output format

I am doing audio recording app related to recording data spoken by users.I need to record the data from he HE AAC format to 3gp format and send it to the server my code is as below



- (IBAction)playRecording
{
self.player = [[AVAudioPlayer alloc]
initWithContentsOfURL:self.currentRecording error:nil];
[self.player play];
}

- (void)startRecording
{
if (![self startAudioSession])
return;

NSError *err = nil;
self.recorder = [[ AVAudioRecorder alloc]
initWithURL:self.createDatedRecordingFile
settings:self.recordSettings error:&err];
if(!self.recorder){
NSLog(@"Could not create recorder: %@ %d %@", [err domain], [err
code], [[err userInfo] description]);
return;
}

[self.recorder prepareToRecord];
[self.recorder record];
[self.recorder recordAtTime:300];
self.isRecording = YES;
[self.recordButton setTitle:@"Stop Recording"
forState:UIControlStateNormal];


}



- (void)stopRecording
{
[self.recorder stop];
self.currentRecording = self.recorder.url;
self.isRecording = NO;
[self.recordButton setTitle:@"Record" forState:UIControlStateNormal];
}

- (BOOL)startAudioSession
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord
error:&err];
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err
userInfo] description]);
return NO;
}

[audioSession setActive:YES error:&err];
err = nil;
if(err){
NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err
userInfo] description]);
return NO;
}

BOOL audioHWAvailable = audioSession.inputAvailable;
if (! audioHWAvailable) {
NSLog(@"Audio input hardware not available");
return NO;
}

return YES;
}

- (NSDictionary *)recordSettings
{
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc]
init];

[recordSettings setValue :[NSNumber
numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSettings setValue:[NSNumber numberWithFloat:24000.0]
forKey:AVSampleRateKey];
[recordSettings setValue:[NSNumber numberWithInt: 1]
forKey:AVNumberOfChannelsKey];

return recordSettings;

}


- (NSURL *)createDatedRecordingFile
{
NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
NSString *caldate = [now description];

NSString *recorderFilePath = [NSString
stringWithFormat:@"%@/%@.m4a", [NSHomeDirectory()

stringByAppendingPathComponent:@"tmp"], caldate];

return [NSURL fileURLWithPath:recorderFilePath];
}


Code is working fine my my question is how to record the data in the above mentioned format and save it some database like sqlite and send it to server .if my code is not perfect please provide me with sample code to convert the saved data and send it to the server


Aucun commentaire:

Enregistrer un commentaire