Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

前端有没有可以控制双声道音频 左、右声道单独播放的方案?

使用wavesurfer.js可以显示双声道的波形图,但是没找到控制单独播放的方法。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.5k views
Welcome To Ask or Share your Answers For Others

1 Answer

找到一个根据AudioBuffer接口的方法进行单声道播放操作。
根据 [AudioBuffer.getChannelData()](https://developer.mozilla.org/zh-CN/docs/Web/API/AudioBuffer/getChannelData)[AudioBuffer.copyFromChannel()](https://developer.mozilla.org/zh-CN/docs/Web/API/AudioBuffer/copyFromChannel)以及[AudioBuffer.copyToChannel()](https://developer.mozilla.org/zh-CN/docs/Web/API/AudioBuffer/copyToChannel),当加载完毕时,替换左、右声道的缓存数据,可以将当前声道的声音屏蔽掉。

 const anotherArray = new Float32Array(AudioBuffer.length)
 // 替换左声道的数据,即可将声道静音
 AudioBuffer.copyToChannel(anotherArray,0,0)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...