We often come across conditions where manual audio file is to be created.
For example recording an audio or download audio data from server. These all need audio file in which data is to be populated.
Below, I'm creating an sound.caf file and after successful creation, data is populating.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"sound.caf"]; NSFileManager *fileManager = [NSFileManager defaultManager];
path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat: @"sound.caf"] ];
[data writeToFile: path atomically:YES]; // Here data is NSData or audioData which is to be written on audioFile.
One can create audio in other formats as well.
Note* Make sure you are using valid format that iOS sdk supports. for example: caf, wav etc.
0 Comment(s)