我在 Swift 中使用 C api。我需要傳遞我使用來自 AVAudioPCMBuffer 的 floatChannelData 的音頻。
let audioFile = try! AVAudioFile(forReading: fileURL as URL)
let audioFormat = audioFile.processingFormat
let audioFrameCount = UInt32(audioFile.length)
let audioFileBuffer = AVAudioPCMBuffer(pcmFormat: audioFormat, frameCapacity: audioFrameCount)
if whisper_full(ctx, wparams, audioFileBuffer?.floatChannelData , Int32(audioFrameCount)) != 0 {
print("failed to process audio")
return
}
C 標頭:
WHISPER_API int whisper_full(
struct whisper_context * ctx,
struct whisper_full_params params,
const float * samples,
int n_samples);
我嘗試只使用 UnsafePointer(audioFileBuffer?.floatChannelData) 但這會產生不同的錯誤。我對指標在 Swift 中的作業方式有點困惑。
我已經閱讀了 Apple UnsafePointer 檔案,但感覺并不明智。https://developer.apple.com/documentation/swift/unsafepointer
uj5u.com熱心網友回復:
如Apple floatChannelData 檔案中所述,floatChannelData
是指向幀指標串列的指標,幀是frameLength
浮點串列(因此指向浮點指標的指標)。
另一方面,whisper_full()
函式似乎直接將指標指向完整的浮點數串列。
我不知道whisper_full()
它是做什么的,所以如果合適的話,你可以為每一幀呼叫一次,否則你將不得不執行一些操作來將所有幀一個接一個地放入記憶體中(這個操作會導致沉重CPU 和記憶體負載),并將指向第一個的指標傳遞給您的 C 函式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/516578.html
標籤:C迅速指针