这里ios的录音功能主要依靠AVFoundation.framework与CoreAudio.framework来实现
在工程内添加这两个framework
我这里给工程命名audio_text
在生成的audio_textViewController.h里的代码如下
设置下按键的属性
基本就ok了,可以开始录音了。
OSStatus error = AudioSessionInitialize(NULL, NULL, NULL, NULL);
UInt32 category = kAudioSessionCategory_PlayAndRecord;
error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, NULL, self);
UInt32 inputAvailable = 0;
UInt32 size = sizeof(inputAvailable);
AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &size, &inputAvailable);
AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable, NULL, self);
AudioSessionSetActive(true);
2.在录制声音开始的时候先把播放声音stop,加入
UInt32 category = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);