# AudioBuffer.copyFromChannel()

with Promise style call: Not supported

Mini Program plugin: Not supported

Copies from the specified channel of AudioBuffer to the array terminal.

# sample code

sample code


const audioCtx = wx.createWebAudioContext
const audioBuffer = audioCtx.createFromAudioFile({
  filePath:'/pages/res/bgm.mp3', // Static resources
  mixToMono:true,
  sampleRate:44100
})
const channels = audioBuffer.numberOfChannels
const anotherArray = new Float32Array(frameCount)
const rate = audioBuffer.sampleRate
const startOffSet = 0
const endOffset = rate * 3
const newAudioBuffer = audioCtx.createBuffer(channels,endOffset - startOffset,rate)
const offset = 0

for (let channel = 0 channel < channels channel++) {
  audioBuffer.copyFromChannel(anotherArray, channel, startOffset)
  newAudioBuffer.copyToChannel(anotherArray, channel, offset)
}