小程序
小游戏
企业微信
微信支付
扫描小程序码分享
5 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
支持 AudioBuffer.copyToChannel
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
playAudioBufferQueue() { if(this.data.playing || this.data.audioBufferQueue.length === 0) { return } if (this.data.audioBufferQueue.length > 0) { this.setData({ status: '正在回复', playing: true }) const currentPlayData = this.data.audioBufferQueue.shift() const source = this.createFadeInOutNode(currentPlayData, 0.018) source.start() source.onended = () => { this.setData({ playing: false }) this.playAudioBufferQueue() if(this.data.audioBufferQueue.length === 0) { this.setData({ status: '正在聆听', playing: false }) }) } } } }, createFadeInOutNode(buffer, fadeDuration) { const source = this.data.audioContext.createBufferSource() source.buffer = buffer const gainNode = this.data.audioContext.createGain() source.connect(gainNode) gainNode.connect(this.data.audioContext.destination) // 添加淡入效果 gainNode.gain.setValueAtTime(0, this.data.audioContext.currentTime) gainNode.gain.linearRampToValueAtTime(1, this.data.audioContext.currentTime + fadeDuration) // 添加淡出效果 gainNode.gain.setValueAtTime(1, this.data.audioContext.currentTime + buffer.duration - fadeDuration) gainNode.gain.linearRampToValueAtTime(0, this.data.audioContext.currentTime + buffer.duration) return source },
我尝试了一下自己拼装,倒是能播放了,就是来一个chunk 就拼起来, 格式是 wav 的,所以播放时都要在 chunk 前拼上 wav 的header
请问解决了吗,可以分享一下实现方案吗
请问解决了吗?有相关示例代码方便提供吗?
const audioCtx = wx.createWebAudioContext(); const source = audioCtx.createBufferSource(); audioCtx.decodeAudioData(data,(buffer)=>{ source.buffer = buffer; source.connect(audioCtx.destination); source.start(); })
我尝试后续在souce.buffer中动态添加数据,但并未成功
source.buffer.copyToChannel(buffer.getChannelData(0), 0, seek);
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
支持 AudioBuffer.copyToChannel
playAudioBufferQueue() { if(this.data.playing || this.data.audioBufferQueue.length === 0) { return } if (this.data.audioBufferQueue.length > 0) { this.setData({ status: '正在回复', playing: true }) const currentPlayData = this.data.audioBufferQueue.shift() const source = this.createFadeInOutNode(currentPlayData, 0.018) source.start() source.onended = () => { this.setData({ playing: false }) this.playAudioBufferQueue() if(this.data.audioBufferQueue.length === 0) { this.setData({ status: '正在聆听', playing: false }) }) } } } }, createFadeInOutNode(buffer, fadeDuration) { const source = this.data.audioContext.createBufferSource() source.buffer = buffer const gainNode = this.data.audioContext.createGain() source.connect(gainNode) gainNode.connect(this.data.audioContext.destination) // 添加淡入效果 gainNode.gain.setValueAtTime(0, this.data.audioContext.currentTime) gainNode.gain.linearRampToValueAtTime(1, this.data.audioContext.currentTime + fadeDuration) // 添加淡出效果 gainNode.gain.setValueAtTime(1, this.data.audioContext.currentTime + buffer.duration - fadeDuration) gainNode.gain.linearRampToValueAtTime(0, this.data.audioContext.currentTime + buffer.duration) return source },
我尝试了一下自己拼装,倒是能播放了,就是来一个chunk 就拼起来, 格式是 wav 的,所以播放时都要在 chunk 前拼上 wav 的header
请问解决了吗,可以分享一下实现方案吗
请问解决了吗?有相关示例代码方便提供吗?
const audioCtx = wx.createWebAudioContext(); const source = audioCtx.createBufferSource(); audioCtx.decodeAudioData(data,(buffer)=>{ source.buffer = buffer; source.connect(audioCtx.destination); source.start(); })
我尝试后续在souce.buffer中动态添加数据,但并未成功