ios - 以 AAC 格式录制的 xCode 无法正常工作

标签 ios xcode swift audio-recording

这是我在 iOS8 Swift 应用程序中录制音频的代码:

var fileName = "/SFRecording-" + String(recordingSequence) + ".caf"
var str =  storageLocation + fileName
var url = NSURL.fileURLWithPath(str as String)

audioSession.setCategory(AVAudioSessionCategoryRecord, error: nil)
audioSession.setActive(true, error: nil)

var recordSettings = [
    AVFormatIDKey:kAudioFormatAppleIMA4,
    AVSampleRateKey:44100.0,
    AVNumberOfChannelsKey:2,
    AVEncoderBitRateKey:12800,
    AVLinearPCMBitDepthKey:16,
    AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue
]
    var error: NSError?

    realRecorder = AVAudioRecorder(URL:url, settings: recordSettings as [NSObject : AnyObject], error: &error)

它工作正常,但生成的 CAF 文件在 Windows 系统上没有用。我想以更熟悉的格式录制,例如 MP3,但由于许可问题,您不能在 iOS 中使用。

现在我想以 AAC 格式录制,我已在上面的代码中将文件扩展名从 .CAF 更改为 .AAC 和还将 AVFormatIDKey:kAudioFormatAppleIMA4 中的值切换为 kAudioFormatMPEG4AAC 但这些设置无法记录任何内容。我是否也应该更改其他一些设置以使 AAC 录音正常工作?

记住我的目标是以一种可以在 mac/win/browser 上轻松播放的格式进行录制

最佳答案

我自己想通了。我必须删除以下行才能使 .AAC 格式正常工作:

AVSampleRateKey:44100.0,
AVNumberOfChannelsKey:2,
AVEncoderBitRateKey:12800,
AVLinearPCMBitDepthKey:16,

关于ios - 以 AAC 格式录制的 xCode 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332319/

相关文章:

ios - 如何进行多线程以更快地将图像加载到tableView?

ios - 移动场景 : SKAction animation or anchorPoint in update method?

ios - 强制更新 subview Controller 的 safeAreaInsets

arrays - 使用 Swift 反转数组中的字符串

ios - 奇怪的错误/SIGABRT 线程 1

ios - 在 64 种不同的可用概率中切换的最佳方式是什么

ios - 快速从文本文件加载单独的组件

xcode 中的 c++ : error when calling any(! !!!) 来自 main 中自定义对象的方法

swift - Xcode Storyboard : how do I add a custom ImageView? macOS

ios - 尝试在 swift 中为 iphone 构建 tableView 时出现错误