Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

前端控制音频左、右声道单独播放?

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

找到一个根据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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...