3
是否有可能提取緩衝區中的數據作爲數組?我已經將一個音頻文件保存到緩衝區中,現在想要提取數據。該代碼是:斯威夫特 - 從audioPCMbuffer陣列
import UIKit
import AVFoundation
//importing audio
let audioFileURL = Bundle.main.url(forResource: "Morning", withExtension: "wav")
let audioFile = try AVAudioFile(forReading: audioFileURL!)
//extract information
var audioFileFormat = audioFile.fileFormat
var audioFilePFormat = audioFile.processingFormat
var audioFileLength = audioFile.length
var audioFrameCount = UInt32(audioFile.length)
var audioFileChannels = audioFile.fileFormat.channelCount
var audioFileSamplingRate = audioFile.fileFormat.sampleRate
// insert into buffer
let audioBuffer = AVAudioPCMBuffer(pcmFormat: audioFilePFormat, frameCapacity: AVAudioFrameCount(audioFileLength))
try audioFile.read(into: audioBuffer, frameCount: AVAudioFrameCount(audioFileLength))