ios 使用AVAudioRecorder錄音

weixin_34365417發表於2017-02-10

如何使用AVAudioRecorder錄音 如下:

// 錄音儲存的url

NSURL *fileUrl = [NSURL fileURLWithPath:@"/Users/midas/Desktop/sounds.m4a"];

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

// 取樣率

[dict setObject:@44100.0f forKey:AVSampleRateKey];

// 編碼格式

[dict setObject:@(kAudioFormatAppleLossless) forKey:AVFormatIDKey];

// 聲道數目

[dict setObject:@1 forKey:AVNumberOfChannelsKey];

// 質量

[dict setObject:@(AVAudioQualityLow) forKey:AVEncoderAudioQualityKey];

_recorder = [[AVAudioRecorder alloc] initWithURL:fileUrl settings:dict error:nil];

// 錄製5s

[_recorder recordForDuration:5];

[_recorder prepareToRecord];

// 開始錄製

[_recorder record];

相關文章