gpt4 book ai didi

ios - 音频队列录制错误 : AudioConverterNew from AudioQueueNew returned 'fmt?'

转载 作者:行者123 更新时间:2023-12-02 23:44:06 25 4
gpt4 key购买 nike

这是我设置音频队列服务的代码:

aqData = AQRecorderState()
aqData.mDataFormat.mFormatID = kAudioFormatMPEG4AAC
aqData.mDataFormat.mSampleRate = 16000.0
aqData.mDataFormat.mChannelsPerFrame = 1
aqData.mDataFormat.mBitsPerChannel = 16
aqData.mDataFormat.mBytesPerPacket = aqData.mDataFormat.mChannelsPerFrame * UInt32(sizeof(UInt16))
aqData.mDataFormat.mBytesPerFrame = aqData.mDataFormat.mChannelsPerFrame * UInt32(sizeof(UInt16))
aqData.mDataFormat.mFramesPerPacket = 1
aqData.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsBigEndian
aqData.mQueue = AudioQueueRef()
fileType = kAudioFileM4AType

// create new input for audio queue
AudioQueueNewInput(&aqData.mDataFormat, handleInputBuffer, &aqData, nil, kCFRunLoopCommonModes, 0, &aqData.mQueue)
var dataFormatSize:UInt32 = UInt32(sizeof(aqData.mDataFormat.dynamicType))
AudioQueueGetProperty(aqData.mQueue, kAudioQueueProperty_StreamDescription, &aqData.mDataFormat, &dataFormatSize)

// create file to store audio
let data = recordUrl.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
let audioFileURL: CFURLRef = CFURLCreateFromFileSystemRepresentation(nil, UnsafePointer(data.bytes), data.length, false)
AudioFileCreateWithURL(audioFileURL, fileType, &aqData.mDataFormat, AudioFileFlags.EraseFile, &aqData.mAudioFile)

// set magic cookie for file if needed
setMegicCookieForFile(aqData.mQueue, inFile: aqData.mAudioFile)

// derive buffer size
deriveBufferSize(aqData.mQueue, ASBDescription: &aqData.mDataFormat, seconds: kBufferLengthInSecond, outbufferSize: &aqData.bufferByteSize)

// allocate and enqueue each buffer
for i in 0..<Record.kNumberBuffers {
AudioQueueAllocateBuffer(aqData.mQueue, aqData.bufferByteSize, &aqData.mBuffers[i])
AudioQueueEnqueueBuffer(aqData.mQueue, aqData.mBuffers[i], 0, nil)
}

代码在行产生错误
AudioQueueNewInput(&aqData.mDataFormat, handleInputBuffer, &aqData, nil, kCFRunLoopCommonModes, 0, &aqData.mQueue)

错误信息是
AudioConverterNew from AudioQueueNew returned 'fmt?'

io:1 channel ,44100 Hz,Float32
客户端:1 channel ,44100 Hz,'aac' (0x00000003) 16 位/ channel ,2 字节/包,1 帧/包,2 字节/帧

我尝试了不同的音频格式设置,但似乎没有一个能修复这个错误。任何人都可以帮忙吗?

最佳答案

来自 CoreAudioTypes.h头文件,我们收集到:

kAudioFormatMPEG4AAC MPEG-4 Low Complexity AAC audio object, has no flags.



并在 AudioStreamBasicDescription 上方发表评论在同一个文件中说:

In compressed audio, a Packet is an indivisible chunk of compressed data, for example an AAC packet will contain 1024 sample frames.



而且由于 AAC 可以是可变比特率(这在 CAF spec 和注释中有所暗示
对于变量 mBytesPerPacket
compressed audio formats ) mBitsPerChannel , mBytesPerPacketmFramesPerPacket应该为零。

所以我会尝试更改您的 AudioStreamBasicDescription 的这些字段:
aqData.mDataFormat.mBitsPerChannel       = 0
aqData.mDataFormat.mBytesPerPacket = 0
aqData.mDataFormat.mBytesPerFrame = 0
aqData.mDataFormat.mFramesPerPacket = 1024
aqData.mDataFormat.mFormatFlags = 0

关于ios - 音频队列录制错误 : AudioConverterNew from AudioQueueNew returned 'fmt?' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33882455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com