我需要將CMSampleBuffer
轉換爲Data
格式。我正在使用一個第三方框架進行音頻相關任務。該框架爲我提供了CMSampleBuffer
對象中的流媒體(即實時音頻)音頻。如何將Swift中的CMSampleBuffer轉換爲數據?
像這樣:
func didAudioStreaming(audioSample: CMSampleBuffer!) {
//Here I need to conver this to Data format.
//Because I am using GRPC framework for Audio Recognization,
}
請提供給我的步驟來轉換CMSampleBuffer
到Data
。
FYI
let formatDesc:CMFormatDescription? = CMSampleBufferGetFormatDescription(audioSample)
<CMAudioFormatDescription 0x17010d890 [0x1b453ebb8]> {
mediaType:'soun'
mediaSubType:'lpcm'
mediaSpecific: {
ASBD: {
mSampleRate: 16000.000000
mFormatID: 'lpcm'
mFormatFlags: 0xc
mBytesPerPacket: 2
mFramesPerPacket: 1
mBytesPerFrame: 2
mChannelsPerFrame: 1
mBitsPerChannel: 16 }
cookie: {(null)}
ACL: {(null)}
FormatList Array: {(null)}
}
extensions: {(null)}
}
請問你是怎麼在16000的採樣率記錄?我已經打電話給'''session.setPreferredSampleRate''',但我不斷收到採樣率44100 –