【问题标题】:How to avoid playing back the sound that is being recorded如何避免播放正在录制的声音
【发布时间】:2014-05-21 18:38:46
【问题描述】:

我说的是反馈 - 当您制作一个简单的 JavaScript 应用程序时,该应用程序会打开来自用户的流并读取频率分析(或其他任何内容),它会将所有接收到的数据发送回 Google Chrome 和 Opera 中的耳机. Firefox 大部分时间都处于沉默状态,并随机产生不稳定反馈的巨大混乱——它还会在几秒钟后关闭流。一般来说,这个东西在 Firefox 中还不能工作。

我创建了一个fiddle。如果您的浏览器不支持它,我假设您只会在控制台中收到错误。

代码的关键部分是当用户接受麦克风访问请求时调用的函数:

        //Not sure why do I do this
        var inputPoint = context.createGain();

        // Create an AudioNode from the stream.
        var source = context.createMediaStreamSource(stream);
        source.connect(inputPoint);        

        //Analyser - this converts raw data into spectral analysis
        window.analyser = context.createAnalyser();
        //Mores stuff I know nothing about
        analyser.fftSize = 2048;
        //Sounds much like connecting nodes in MatLab, doesn't it?
        inputPoint.connect(analyser);
        analyser.connect(context.destination);
        ///THIS should probably make the sound silent (gain:0) but it doesn't
        var zeroGain = context.createGain();
        zeroGain.gain.value = 0.0;
        //More connecting... are you already lost which node is which? Because I am.
        inputPoint.connect(zeroGain);
        zeroGain.connect(context.destination);

零收益的想法不是我的,我是从简单的sound recorder demo 那里偷来的。但是对他们有用的东西对我不起作用。 该演示在 Firefox 中也没有问题,就像我一样。

【问题讨论】:

    标签: javascript html5-audio audiocontext


    【解决方案1】:

    在函数 mediaGranted(stream) {...

    注释掉 .. Fiddle line #46: //analyser.connect(context.destination); ..

    更多信息https://mdn.mozillademos.org/files/5081/WebAudioBasics.png 不错的演示:http://mdn.github.io/voice-change-o-matic/

    【讨论】:

      猜你喜欢
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多