IOS uses Ezaudio library to generate WAV error conditions

Source: Internet
Author: User

Using the Ezaudio Library

The M4A format can refer to the code in this library example.

Record WAV format to change the source. Look at the code below.

1Avaudiosession *session =[Avaudiosession sharedinstance];2Nserror *error =Nil;3[Session Setcategory:avaudiosessioncategoryplayandrecord error:&ERROR];4     if(Error) NSLog (@"Audio Session category error:%@", error);5[Session Setactive:yes error:&ERROR];6     if(Error) NSLog (@"Audio Session Active error:%@", error);7 8Self.microphone =[Ezmicrophone microphonewithdelegate:self];9Self.recorder =[Ezrecorder recorderwithurl:[nsurl Fileurlwithpath:record_path]Ten Clientformat:[self.microphone Audiostreambasicdescription] OneFiletype:ezrecorderfiletypewav//specified as WAV format A                                        Delegate: self]; -  - [Self.microphone Startfetchingaudio]; theSelf.recording =YES; -Self.audiotimer = [Nstimer scheduledtimerwithtimeinterval:1.0f - target:self - selector: @selector (audiotimer:) + Userinfo:nil Repeats:yes]; -  +  A //Timer calculates recording time at- (void) Audiotimer: (Nstimer *) Timer - { -Self.audioV.audioTime = (int) Self.recorder.currentTime; - } -  - //This is an agent function that can be used to calculate the volume in- (void) Microphone: (Ezmicrophone *) Microphone -Hasaudioreceived: (float**) Buffer to withbuffersize: (UInt32) buffersize + withnumberofchannels: (UInt32) Numberofchannels - { theDispatch_async (Dispatch_get_main_queue (), ^{ *         if(self.isrecording) { $CGFloat vol = [ezaudioutilities rms:buffer[0] length:buffersize];Panax Notoginseng             //Vol is the volume *150 because it controls the width of the control after zooming -Self.audioV.vol = (int) (Vol * Max); the         } +     }); A}
This type of writing will be rolled back. The reason is that this library is not configured in WAV format. Modify the Library EZAudioUtilities.mThe No. 287 line of the file function is
1+ (Audiostreambasicdescription) Stereofloatinterleavedformatwithsamplerate: (float) Samplerate2 {3 #if0//This library itself code record WAV format direct error flash back4 audiostreambasicdescription ASBD;5UInt32 floatbytesize =sizeof(float);6Asbd.mchannelsperframe =2;7Asbd.mbitsperchannel =8*floatbytesize;8Asbd.mbytesperframe = Asbd.mchannelsperframe *floatbytesize;9Asbd.mframesperpacket =1;TenAsbd.mbytesperpacket = Asbd.mframesperpacket *Asbd.mbytesperframe; OneAsbd.mformatflags =kaudioformatflagisfloat; AAsbd.mformatid =KAUDIOFORMATLINEARPCM; -Asbd.msamplerate =samplerate; -asbd.mreserved =0; the     returnASBD; - #endif -  -     //Use this configuration to record the WAV format. + audiostreambasicdescription ASBD; -memset (&ASBD,0,sizeof(ASBD)); +Asbd.msamplerate =8000;//Sample Rate AAsbd.mformatid =KAUDIOFORMATLINEARPCM; atAsbd.mformatflags = Klinearpcmformatflagissignedinteger |kaudioformatflagispacked; -Asbd.mchannelsperframe =1;//Single channel -Asbd.mframesperpacket =1;//every packet, one detective data . -Asbd.mbitsperchannel = -;//16bit quantization per sample point -Asbd.mbytesperframe = (Asbd.mbitsperchannel/8) *Asbd.mchannelsperframe; -Asbd.mbytesperpacket =Asbd.mbytesperframe; in  -     returnASBD; to}
Use the Encodeaudio library to convert to AMR format extract password: PRDQ

1 // turn into AMR format after sending 2 nsdata * data = [[NSData alloc] Initwithcontentsoffile: Record_path]; 3 data = [Encodeaudio convertwavtoamrfile:data];

IOS uses Ezaudio library to generate WAV error conditions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.