如何通过 iPhone 应用录制音频?

Posted

技术标签:

【中文标题】如何通过 iPhone 应用录制音频?【英文标题】:How to record audio through an iPhone app? 【发布时间】:2011-04-09 04:35:48 【问题描述】:

我想在我的 iPhone 应用程序中录制音频,一旦录制了音频,我想打开一个对话框,询问文件名。

然后我想将具有该文件名的音频保存到我的应用程序中。我该怎么做?

【问题讨论】:

我在这里添加了完整的答案***.com/questions/1010343/… 【参考方案1】:

尝试使用 AVAudioPlayer 和 AVAudioRecorder 类进行音频录制和播放。最初您必须使用 AVAudio 会话类建立音频会话

AVAudiosession *audioS =[AVAudioSession sharedInstance];
[audioS setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioS setActive:YES error:&error];

NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];

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

然后初始化记录器和播放器类...希望这会有所帮助

【讨论】:

【参考方案2】:

查看 Apple 的 SpeakHere 示例应用,可在其 iOS 开发者网站上找到。

【讨论】:

【参考方案3】:

你可以看到这个问题How do I record audio on iPhone with AVAudioRecorder? ,这与你的问题非常相似,或者观看苹果http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html的这个示例代码

【讨论】:

以上是关于如何通过 iPhone 应用录制音频?的主要内容,如果未能解决你的问题,请参考以下文章

如何录制iphone扬声器用完的音频?

如何通过在 iphone 中混合多个音频来录制音频?

在 iPhone 上录制音频并使用 NSOutputStream 通过网络发送

有没有办法在 iPhone 上录制设备音频?

如何以编程方式在 iphone 中执行应用程序音频的内部录制

如何录制 iPhone 的音频输出? (就像我的应用程序的声音)