Already I have created an iPhone application to record. It will record in .caf file.
But I want to record in .m4a format.
Please help me to do this.
Thanks.
Already I have created an iPhone application to record. It will record in .caf file.
But I want to record in .m4a format.
Please help me to do this.
Thanks.
Here is an alternative code sample that will encode the file as AAC inside an m4a:
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docsDir = [dirPaths objectAtIndex:0];
NSURL *tmpFileUrl = [NSURL fileURLWithPath:[docsDir stringByAppendingPathComponent:@"tmp.m4a"]];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
nil];
NSError *error = nil;
AVAudioRecorder *recorder = [[AVAudioRecorder alloc] initWithURL:tmpFileUrl settings:recordSettings error:&error];
[recorder prepareToRecord];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:nil];
[session setActive:YES error:nil];
[recorder record];
Then to end the recording I used:
[recorder stop];
AVAudioSession *session = [AVAudioSession sharedInstance];
int flags = AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivation;
[session setActive:NO withFlags:flags error:nil];
Then the file at tmpFileUrl
can be used.
Here is the working SWIFT code to record m4a Audio files. Bear in mind that hitting the right format parameters that produce usable audio files in iOS is really painful to find. I found that this combination works, after much trial and error. I hope it saves you time, enjoy!
let recordSettings: [String : AnyObject] = [AVSampleRateKey : NSNumber(float: Float(16000)),
AVFormatIDKey : NSNumber(int: Int32(kAudioFormatMPEG4AAC)),
AVNumberOfChannelsKey : NSNumber(int: 1),
AVEncoderAudioQualityKey : NSNumber(int: Int32(AVAudioQuality.Low.rawValue))]
func initializeAudioSession(){
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try audioRecorder = AVAudioRecorder(URL: self.directoryURL()!,
settings: recordSettings)
audioRecorder.delegate = self
audioRecorder.meteringEnabled = true
audioRecorder.prepareToRecord()
} catch let error as NSError{
print("ERROR Initializing the AudioRecorder - "+error.description)
}
}
func recordSpeechM4A(){
if !audioRecorder.recording {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setActive(true)
audioRecorder.record()
print("RECORDING")
} catch {
}
}
}
func directoryURL() -> NSURL { //filename helper method
let fileManager = NSFileManager.defaultManager()
let urls = fileManager.URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
filepath = urls[0]
let documentDirectory = urls[0] as NSURL
print("STORAGE DIR: "+documentDirectory.description)
//print("---filepath: "+(filepath?.description)!)
let soundURL = documentDirectory.URLByAppendingPathComponent("recordedAudio.m4a") //.m4a
print("SAVING FILE: "+soundURL.description)
return soundURL
}
I am trying to convert caf file to m4a file using AudioUnit. I have implemented the code to convert. When I tried to run the application, I am getting following error message; couldn t set ...
I have tried with more AudioStreamBasicDescription for m4a file format. Still I am getting some issues with that. Please anyone tell me the exact AudioStreamBasicDescription for m4a file format.
I am trying to play m4a(http://a1.phobos.apple.com/us/r1000/020/Music/ad/41/da/mzm.fkekhvue.aac.p.m4a) file from iTunes affiliates using AvAudioPlayer but can not able to play it. I think there is ...
Already I have created an iPhone application to record. It will record in .caf file. But I want to record in .m4a format. Please help me to do this. Thanks.
I m looking for a (free) flash player that I can embed in my site and use to play a .m4a (.mp4 with AAC audio) file that will be obtained using a URL (i.e. it s not local to the server hosting the web ...
I m working with a simple mediaplayer based on this msdn example where the user can control volume, playback speed (SpeedRatio) and seek (Position) using 3 sliders. Everything works correctly when I ...
I currently have a FileUpload.mxml component that uploads a .m4a to an oracle database, retrieves metadata from the file and saves the metadata info in the database. to acheive this I use ...
I ve got some heavily modified code that ultimately came from the Windows Media SDK that works great for reading tags out of MP3 and WMV files. Somewhere along the line, Windows Media Player added ...