我喜欢在我的(流星)应用程序中使用Howler.js。但是,播放速率函数导致了我不想要的音高变化(我只想要时间的延长,并保留音高)。因此,我的解决方案是将音高转换为“修正”音高。看起来很简单,这就是为什么我选择使用https://tonejs.github.io/
唯一的问题是,我不能为我的生活使它正确地工作。在阅读了几个小时的Web、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);当我运行它时,我会收到以下错误消息:
跟踪器meteor.js?hash=857dafb4b9dff17e29ed8498a22ea5b1a3d6b41d:1059 afterFlush函数的
异常: TypeError:未能在‘AudioNode’上执行'connect‘:重载解析失败。
我还注意到,在这些命令下面的console.log()命令甚至没有出现在控制台中,非常奇怪。但是,当我移除最后一行(mastergain.connect到pShift)时,就会出现这种情况。
我尝试了其他一些技术,比如https://github.com/mmckegg/soundbank-pitch-shift/ (它起作用了,但它同时播放了音高移位和非音高转换的声音,不管我把它放在什么设置中),或者简单地使用AudioBufferSourceNode.detune (我不知道如何让它与Howler.js一起工作,因为Howler只有一些函数可以公开GainNode和AudioContext,无法在仍然使用豪勒的时候从那里读取输出)。
任何帮助/线索都将不胜感激!
发布于 2021-10-18 19:59:36
我想你不需要第三行的片段。因为您的第一行已经告诉Tone.js使用howler.js创建的AudioContext。因此,pShift.context应该等于Howler.ctx。但再查一遍也许是有意义的。
console.assert(pShift.context === Howler.ctx);由masterGain公开的howler.js是一个本地音频节点。这意味着它不能直接连接到用Tone.js创建的节点,因为这些节点不是本地音频节点。但是Tone.js提供了一个助手来完成这个任务。
Tone.connect(Howler.masterGain, pShift);我认为还需要调用masterGain上的masterGain来删除任何现有的连接。
下面的片段应该可以工作。
Tone.setContext(Howler.ctx);
const pShift = new Tone.PitchShift(3);
Howler.masterGain.disconnect();
Tone.connect(Howler.masterGain, pShift);
pShift.toDestination();发布于 2022-02-17 12:31:33
只是想添加一下,如果您设置了html5: true选项,浏览器将自动为您修复该选项。
https://stackoverflow.com/questions/69621611
复制相似问题