録音した音声ファイルを[Double]タイプの生のPCMデータに変換しようとしています。音声を[Double]タイプの生のPCMデータに変換します
// load audio from path
let file = try! AVAudioFile(forReading: self.soundFileURL)
// declare format
let format = AVAudioFormat(commonFormat: .PCMFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: 1, interleaved: false)
// initialize audiobuffer with the length of the audio file
let buf = AVAudioPCMBuffer(PCMFormat: format, frameCapacity: UInt32(file.length))
// write to file
try! file.readIntoBuffer(buf)
// copy to array
let floatArray = Array(UnsafeBufferPointer(start: buf.floatChannelData[0], count:Int(buf.frameLength)))
問題は、[ダブル]とAVAudioPCMBuffer()のみ.PCMFormatFloat32
を知っているように私がデータを必要とする、である:私はこのような[FLOAT32]ロードおよびタイプのPCMデータへの音声に変換する方法を見つけました。誰かが回避策を知っていますか? ありがとうございます。
?わたしにはできる。私はコード全体を表示するために質問を更新しました。 –
答えをありがとう、私の問題を解決!私はまだAVAudioPCMBufferを使用していたとは思えませんでした。 – user967493