目前,我正在尝试将音频示例从AVAudioPCMBuffer转换为NSData --我已经查看了这个所以波斯特和这个GitHub代码上被接受的答案,但是似乎有一些AVFAudio API的有changed...below是对AVAudioPCMBuffer的扩展
private extension AVAudioPCMBuffer {
func toNSData() -> NSData {
let channels = UnsafeBufferPointer(start: int16ChannelData, count: 1)
let ch0Data = NSData(bytes: channels[0], length:Int(frameCapacity * format.streamDescription.inTotalBitsPerChannel))
return ch0Data
}
}我看到了Value of type 'UnsafePointer<AudioStreamBasicDescription>' has no member 'inTotalBitsPerChannel'的一个错误。到目前为止,我还没有找到任何其他方法来了解inTotalBitsPerChannel value...any帮助!
发布于 2018-04-05 16:50:46
在链接到的代码示例中,我没有看到任何名为inTotalBitsPerChannel的方法;相反,它们似乎都使用mBytesPerFrame。您还需要.pointee来取消指针的引用。最后,在现代Swift中,通常您应该更喜欢使用Data而不是NSData。因此,基本上,如果您将最后一行重写为:
let ch0Data = Data(bytes: channels[0], count: Int(frameCapacity * format.streamDescription.pointee.mBytesPerFrame))https://stackoverflow.com/questions/49677123
复制相似问题