Import Frame:
#import <AVFoundation/AVFoundation.h>
Declaring Global variables:
@interface Viewcontroller () <AVAudioRecorderDelegate>
{
Avaudiorecorder *audiorecorder;
}
@end
*button == CGRectMake (+); [Button Settitle: @" TICK " = [Uicolor Browncolor]; [Button addtarget:self action: @selector (Startaudiorecoder:) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button];
trigger events for buttons- (void) Startaudiorecoder: (UIButton *) sender{sender.selected= !sender.selected; if(sender.selected! =YES) {[Audiorecorder stop]; return; } //url is local URL avaudiorecorder requires a stored pathNSString *name = [NSString stringWithFormat:@"%d.aiff",(int) [NSDate date].timeintervalsince1970]; NSString*path =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES). Firstobject Stringbyappendingpathcomponent:name]; Nserror*error; //Recorder InitializationAudiorecorder = [[Avaudiorecorder alloc]initwithurl:[nsurl Fileurlwithpath:path] settings:@{avnumberofchannelskey:@2, avsampleratekey:@44100, avlinearpcmbitdepthkey:@ +, avencoderaudioqualitykey:@ (Avaudioqualitymax), avencoderbitratekey:@128000} error:&ERROR]; [Audiorecorder Preparetorecord]; [Audiorecorder Record]; Audiorecorder.Delegate=Self ; /*The 1.AVNumberOfChannelsKey channel number is typically a two-channel value of 2 2.AVSampleRateKey sampling rate unit Hz is usually set to 44100 that is 44.1k 3.AVLINEARPCMBITDEP Thkey bit rate 8 4.AVEncoderAudioQualityKey sound quality ①avaudioqualitymin = 0, minimum mass ②avaud Ioqualitylow = 0x20, lower quality ③avaudioqualitymedium = 0x40, intermediate mass ④avaudioqualityhigh = 0x60, High quality ⑤avaudioqualitymax = 0x7F Best quality 5.AVEncoderBitRateKey audio encoded bitrate unit Kbps transmission rate general Settings 128000 is 128KBP S*/NSLog (@"%@", path);} Proxy method:- (void) Audiorecorderdidfinishrecording: (Avaudiorecorder *) Recorder successfully: (BOOL) flag{NSLog (@"End of recording");//classes for file operationsNsfilemanager *manger =[Nsfilemanager Defaultmanager]; NSString*path =[Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) lastobject];//get all the child files of the current file SubpathsatpathNsarray *pathllist =[Manger Subpathsatpath:path];//need to get only audio filesNsmutablearray *audiopathlist =[Nsmutablearray array];//Traverse all sub-files under this folder for(NSString *audiopathinchpathllist) {//distinguish whether a file is recorded by comparing its extension name (extension suffix)if([Audiopath.pathextension isequaltostring:@"AIFF"]) {//Put the filtered files in the array[Audiopathlist Addobject:audiopath]; }} NSLog (@"%@", audiopathlist); }
An instance of iOS development to resolve recordings