iOS录音可以使用框架中的类来实现。是一段示例代码:// 创建录音文件保存路径
iOS录音可以使用Foundation框架中的AudioRecorder类来实现。是一段示例代码:
// 创建录音文件保存路径
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
// 初始化录音器
AudioSession *session = [AudioSession sharedInstance];
[session setCategory:AudioSessionCategoryPlayAndRecord error:nil];
NSDictionary *recordSettings = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEG4AAC], FormatIDKey,
[NSNumber numberWithFloat:44100.0], SampleRateKey,
[NSNumber numberWithInt: 2], NumberOfChannelsKey,
[NSNumber numberWithInt:16], LinearPCMBitDepthKey,
[NSNumber numberWithBool:NO], LinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO], LinearPCMIsFloatKey,
nil];
AudioRecorder *recorder = [[AudioRecorder alloc] initWithURL:outputFileURL settings:recordSettings error:nil];
// 开始录音
[recorder record];
// 停止录音
[recorder stop];
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(81条)