我正在做一个在线音频播放器,所以我想在我的应用程序中集成音调移位器,它可以在音调js上获得,但不在网络音频API中.
所以我的想法是将Tonejs 音调移位器连接到Web的audioContext上。
有什么可能的办法吗?
这是我的代码供参考
var audioCtx = new (window.AudioContext || window.webkitAudioContext);
var mediaElem = document.querySelector('audio');
var stream = audioCtx.createMediaElementSource(mediaElem);
var gainNode = audioCtx.createGain();
stream.connect(gainNode);
// tone js
var context = new Tone.Context(audioCtx); // Which is Mentioned in Tonejs Docs!
var pitchShift = new Tone.PitchShift().toMaster();
pitchShift.connect(gainNode);
// Gives Error!
gainNode.connect(audioCtx.destination);发布于 2019-11-03 12:54:42
我想你想要实现这样的信号流:
mediaElement > gainNode > pitchShift > destination为了确保Tone.js使用的是相同的AudioContext,您可以通过在Tone对象上使用setter来分配它。在使用Tone.js进行任何其他操作之前,都需要这样做。
Tone.context = context;Tone.js还导出一个助手,该助手可用于将本机AudioNodes连接到Tone.js提供的节点。
Tone.connect(gainNode, pitchShift);我对您的示例代码做了一些修改,以合并这些更改。
var audioCtx = new (window.AudioContext || window.webkitAudioContext);
var mediaElem = document.querySelector('audio');
var stream = audioCtx.createMediaElementSource(mediaElem);
var gainNode = audioCtx.createGain();
// This a normal connection between to native AudioNodes.
stream.connect(gainNode);
// Set the context used by Tone.js
Tone.context = audioCtx;
var pitchShift = new Tone.PitchShift();
// Use the Tone.connect() helper to connect native AudioNodes with the nodes provided by Tone.js
Tone.connect(gainNode, pitchShift);
Tone.connect(pitchShift, audioCtx.destination);https://stackoverflow.com/questions/58676929
复制相似问题