我有AVAudioPCMBuffer,我想将其中一部分复制到其他缓冲区(从其末尾剪切部分语音)
let samples = Array(UnsafeBufferPointer(start: buffer.floatChannelData![0], count:Int(buffer.frameLength)))
let newPcmBuffer = AVAudioPCMBuffer(pcmFormat: FileThatContainsTheBuffer.processingFormat, frameCapacity: AVAudioFrameCount(_playFile.length))
let count = Int(CGFloat(samples.count) * (/* some value between 0 and 1 */))
for i in 0 ..< count
{
newPcmBuffer.floatChannelData![0][i] = buffer.floatChannelData![0][i]
}
if let url = getFileUrl(fileExtension: "caf")
{
let newPlayFile = try AVAudioFile(forWriting: url as URL, settings: [:], commonFormat: self.format!.commonFormat, interleaved: false)
try newPlayFile.write(from: newPcmBuffer)
}
当我尝试播放newPlayFile时,它会播放静音(或根本不播放) 我知道问题出在for循环中, 什么是正确的方法呢?