保存记录AVAudioRecorder声音文件:现在怎么办? (iOS版,X code 4) [英] Saving a recorded AVAudioRecorder sound file: Now what? ( iOS, Xcode 4 )

查看:266
本文介绍了保存记录AVAudioRecorder声音文件:现在怎么办? (iOS版,X code 4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我希望用户能够记录一个声音文件并播放,然后保存声音文件供以后使用。我用<一个href=\"http://www.techotopia.com/index.php/Recording_Audio_on_an_iPhone_with_AVAudioRecorder_%28iOS_4%29\"相对=nofollow>本教程建立播放和录制界面,但本教程中遗漏了一个关键组成部分:?我怎么永久的声音保存到磁盘

In my App, I want the user to be able to record one sound file and play it back, and then save the sound file for later. I used this tutorial to set up the play and record interface, but this tutorial leaves out a key part: how do I permanently save the sound to the disk?

此外,当你在这里,我怎么设置声音文件记录的最大时间?我不想声音文件超过30秒的长度。

Also, while you're here, how do I set a maximum time for the sound file to record? I don't want sound files exceeding 30 seconds in length.

谢谢,希望我能得到这一切整理出来。

Thanks, hopefully I can get this all sorted out.

推荐答案

语音录制演示是一个很好的例子来看一看。它使用的Cocos2D的UI,但如果你只是看看在HelloWorldScene.m中的类,它包含所有的code,你需要:

Voice Record Demo is a great example to take a look at. It uses Cocos2D for the UI but if you just take a look at the HelloWorldScene.m class, it contains all the code you need to:


  1. 创建一个新的音频会话

  2. 检查麦克风连接

  3. 开始录制

  4. 停止录制

  5. 保存录制的音频文件

  6. 播放保存语音文件

在你初始化你的音频会话,你可以使用的方法类似下面的方式的记录保存到指定的文件名:

After you init your audio session, you could use a method like the one below to save an a recording to a given filename:

-(void) saveAudioFileNamed:(NSString *)filename {

destinationString = [[self documentsPath] stringByAppendingPathComponent:filename];
NSLog(@"%@", destinationString);
NSURL *destinationURL = [NSURL fileURLWithPath: destinationString];

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                          [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                          [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                          [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                          [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                          nil];

NSError *error;

recorder = [[AVAudioRecorder alloc] initWithURL:destinationURL settings:settings error:&error];
recorder.delegate = self;
}

这篇关于保存记录AVAudioRecorder声音文件:现在怎么办? (iOS版,X code 4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆