【发布时间】:2011-08-01 22:53:23
【问题描述】:
我想在我的 iPhone 应用程序中录制音频,一旦录制了音频,我想打开一个对话框,询问文件名。
然后我想将具有该文件名的音频保存到我的应用程序中。我该怎么做?
【问题讨论】:
-
我在这里添加了完整的答案stackoverflow.com/questions/1010343/…
标签: iphone objective-c cocoa-touch ios4 audio
我想在我的 iPhone 应用程序中录制音频,一旦录制了音频,我想打开一个对话框,询问文件名。
然后我想将具有该文件名的音频保存到我的应用程序中。我该怎么做?
【问题讨论】:
标签: iphone objective-c cocoa-touch ios4 audio
尝试使用 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];
然后初始化记录器和播放器类...希望这会有所帮助
【讨论】:
查看 Apple 的 SpeakHere 示例应用,可在其 iOS 开发者网站上找到。
【讨论】:
你可以看到这个问题How do I record audio on iPhone with AVAudioRecorder? ,这与你的问题非常相似,或者观看来自苹果http://developer.apple.com/library/ios/#samplecode/SpeakHere/Introduction/Intro.html的示例代码
【讨论】: