javascript - Tone.PitchShift 和 Howler.js 问题

标签 javascript web-audio-api howler.js tone.js pitch-shifting

我喜欢在我的 (Meteor) 应用程序中使用 Howler.js。然而,播放速率功能导致了我不想要的音调变化(我只想延长时间,并保持音调)。因此,我的解决方案是对其进行音调变换以“纠正”音调。看起来很简单,这就是我选择使用https://tonejs.github.io/的原因

唯一的问题是,我一生都无法让它正常工作。经过几个小时的阅读 Web Audio API、Tone.js 文档以及在线讨论/故障排除论坛后,我得到的最接近潜在解决方案的东西是这样的(在我的应用程序的渲染期间调用,以防万一问题不得不解决)过早加载):

Tone.setContext(Howler.ctx); //set tone's context to the Howler.js audiocontext
var pShift = new Tone.PitchShift(3); //create the PitchShift effect, +3 semi-tones transposition
pShift.context = Howler.ctx; //set the PitchShift's context to the Howler.js audiocontext
pShift.connect(Howler.ctx.destination); //connect the PitchShift's output to the Howler's destination
Howler.masterGain.connect(pShift); //connect the Howler's master GainNode output to the PitchShift effect

//For debugging purposes:
console.log(Howler.masterGain)
console.log(pShift);

当我运行此命令时,我收到此错误消息:

Exception from Tracker afterFlush function: meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:1059 TypeError: Failed to execute 'connect' on 'AudioNode': Overload resolution failed.

我还注意到下面的 console.log() 命令甚至没有显示在控制台中,奇怪的是。然而,当我删除最后一行(mastergain.connect 到 pShift)时,它们确实如此。

我尝试了一些其他技术,例如 https://github.com/mmckegg/soundbank-pitch-shift/ (这有效,但无论我将其设置为何种设置,它都会播放音调变化的声音和非音调变化的声音), 或者简单地使用 AudioBufferSourceNode.detune (我不知道如何让它与 Howler.js 一起工作,因为 Howler 只有可以公开 GainNode 和 AudioContext 的函数,无法弄清楚如何从那里读取输出同时仍在使用 Howler)。

任何帮助/线索将不胜感激!

最佳答案

我认为您不需要代码片段中的第三行。因为您的第一行告诉 Tone.js 使用 howler.js 创建的 AudioContext 。因此,pShift.context 应等于Howler.ctx。但仔细检查可能是有意义的。

console.assert(pShift.context === Howler.ctx);

howler.js 公开的 masterGain 是一个原生音频节点。这意味着它无法直接连接到使用 Tone.js 创建的节点,因为这些节点不是 native 音频节点。但 Tone.js 提供了一个帮助器来做到这一点。

Tone.connect(Howler.masterGain, pShift);

我认为您还需要在 masterGain 上调用 disconnect() 来删除任何现有连接。

下面的代码片段应该可以工作。

Tone.setContext(Howler.ctx);

const pShift = new Tone.PitchShift(3);

Howler.masterGain.disconnect();

Tone.connect(Howler.masterGain, pShift);
pShift.toDestination();

关于javascript - Tone.PitchShift 和 Howler.js 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69621611/

相关文章:

javascript - 在不加载完整歌曲的情况下制作音频 Sprite

JavaScript 翻译模板

php - 浏览器没有立即呈现 ob_flush 输出

javascript - 如何确定在 Safari 中使用哪个 AudioContext 构造函数?

javascript - 网络音频振荡器类型在 Chrome、Firefox 中不起作用吗?

javascript - HowlerJS - 音频播放器 - 错误 401(未经授权)

javascript - 无法将焦点设置在表格行上

javascript - 我无法在node.js中使用router.post方法

html5 音频 api - frequencyBinCount 在 Safari 上不返回任何内容

javascript - 在 Electron 内部使用时,咆哮会抛出 'Decoding audio data failed'