About iOS under recording

Source: Internet
Author: User

I'm using the Avaudiorecorder frame to do the recording.

This recording is different from the Speakhere on the official website, the biggest difference is that this must be recorded to complete to process the file, and the Speakhere example is able to achieve edge recording side of the effect of uploading.

#import <AVFoundation/AVFoundation.h>

#import <CoreAudio/CoreAudioTypes.h> Introduction Framework, which is the basic feature of the use of recording functions


First of all, the default Avaudiorecorder recording format is. CAF, and most of the players do not support this format, the following paragraph is the format can make the recording format wav


Nsdictionary *recordsetting = [[Nsdictionary alloc] Initwithobjectsandkeys:

[NSNumber Numberwithfloat:44100.0],avsampleratekey,//sampling rate

[NSNumber Numberwithint:kaudioformatlinearpcm],avformatidkey,

[NSNumber numberwithint:16],avlinearpcmbitdepthkey,//sampling digits default 16

[NSNumber Numberwithint:2], number of avnumberofchannelskey,//channels

[NSNumber numberwithbool:no],avlinearpcmisbigendiankey,//big or small end is the memory organization way

[NSNumber numberwithbool:no],avlinearpcmisfloatkey,nil];//sampling signal is an integer or a floating-point number


Nsurl *recordedtmpfile = [Nsurl fileurlwithpath:[nstemporarydirectory () stringbyappendingpathcomponent: [NSString  stringWithFormat: @ "%.0f.%@", [nsdate timeintervalsincereferencedate] * 1000.0, @ "WAV"]]]; Settings for file names

Setup the recorder to use this file and a record to it.

Avaudiorecorder *recorder = [[Avaudiorecorder alloc] Initwithurl:recordedtmpfile settings:recordsetting error:& ERROR];

[Recorder Preparetorecord];

[Recorder record];

The following code should be set when the current. m file is loaded

Avaudiosession * audiosession = [avaudiosession sharedinstance];

[Audiosession Setcategory:avaudiosessioncategoryplayandrecord Error: &error]; Set the audio category, which means that when the application starts, stop the other audio in the background

[Audiosession setactive:yes Error: &error];//setting current application audio active





Related Article

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.