简体   繁体   English

听不到 Tone.js 音频过滤器

[英]Tone.js audio filters not being heard

I'm trying to add filter effects to an audio stream I have playing on my website.我正在尝试为我在我的网站上播放的音频 stream 添加滤镜效果。 I'm able to connect the Tone.js library to the audio stream but I'm not hearing any changes in the audio stream playing on the website.我可以将 Tone.js 库连接到音频 stream,但我没有听到网站上播放的音频 stream 有任何变化。 I'm not seeing any errors in the console and I've tried adjusting the filter from 50 to 5000 but nothing seems to have any effect on the audio.我在控制台中没有看到任何错误,我尝试将过滤器从 50 调整到 5000,但似乎对音频没有任何影响。 Do I need to set up the new Tone.Player() to actually hear the audio?我是否需要设置new Tone.Player()才能真正听到音频? If so, how do you go about setting up the Player if there is no src for the existing audio element.如果是这样,如果现有音频元素没有 src,您将如何设置播放器 go。

    $('#testBtn').click(async function () {
        const audioElement = document.getElementById('theAudioStream');
        const mediaElementSource = Tone.context.createMediaElementSource(audioElement);
        const filter = new Tone.Filter(50, 'lowpass').toDestination();
        Tone.connect(mediaElementSource, filter);
        await Tone.start();
        console.log("Started?");
    });

The audio stream I'm trying to modify is set up from a JsSip call.我尝试修改的音频 stream 是通过 JsSip 调用设置的。 The code to start the stream is as follows:启动stream的代码如下:


    var audioStream = document.getElementById('theAudioStream')

    //further down in code    

    currentSession.answer(options);
    if (currentSession.connection) {
        currentSession.connection.ontrack = function (e) {
          audioStream.srcObject = e.streams[0];
          audioStream.play();
        }
    }

I click the test button after the call has started so I know the audio stream is present before initializing the Tone.js Filters我在通话开始后单击测试按钮,因此我知道在初始化 Tone.js 过滤器之前存在音频 stream

Working solution:工作解决方案:
Removing the audioStream.play() from where the JsSIP call is answered solves the issue.从回答JsSIP呼叫的地方删除audioStream.play()解决了这个问题。
I don't know the exact reason why this solves the issue (it might even be a workaround) but after much trial and error this way allows the audio to be available to ToneJS for effecting.我不知道这解决问题的确切原因(它甚至可能是一种解决方法),但经过多次试验和错误后,这种方式允许ToneJS可以使用音频进行效果。

Any other solutions are welcome.欢迎任何其他解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM