【问题标题】:Pitch detection program problems音高检测程序问题
【发布时间】:2017-05-18 10:57:58
【问题描述】:

我已经搜索了一个音高检测程序,但没有任何东西可以为我提供所需的指导。我正在尝试使用 pitch.js,但我无法将麦克风缓冲区放入程序中。

我正在尝试创建一个程序,该程序使用歌手的音高在屏幕上上下移动对象。为此,我需要一个连续(或每 250 毫秒左右)的音高检测程序并访问麦克风。 我正在尝试使用“pitch.js”,但无法将麦克风缓冲区放入“pitch.input”

  /* Copy samples to the internal buffer */

    pitch.input(inputBuffer);

我使用的代码是:

var audioContext = new AudioContext();

console.log("audio is starting up ...");

var BUFF_SIZE = 16384;

var audioInput = null,
        microphone_stream = null,
        gain_node = null,
        script_processor_node = null,
        script_processor_node = null,
        analyserNode = null;

if (!navigator.getUserMedia)
    navigator.getUserMedia = navigator.getUserMedia || 
navigator.webkitGetUserMedia ||
                          navigator.mozGetUserMedia || 
navigator.msGetUserMedia;

if (navigator.getUserMedia) {

    navigator.getUserMedia({ audio: true },
          function (stream) {
              start_microphone(stream);
          },
          function (e) {
              alert('Error capturing audio.');
          }
        );

} else { alert('getUserMedia not supported in this browser.'); }

function start_microphone(stream) {

    gain_node = audioContext.createGain();
    gain_node.connect(audioContext.destination);

    microphone_stream = audioContext.createMediaStreamSource(stream);
    microphone_stream.connect(gain_node);

    // --- enable volume control for output speakers

    document.getElementById('volume').addEventListener('change', function () 
  { 
        var curr_volume = this.value;
        gain_node.gain.value = curr_volume;

        console.log("curr_volume ", curr_volume);
    });

    script_processor_node = audioContext.createScriptProcessor(2048, 1, 1);
    script_processor_node.connect(gain_node);

   function setPitch() {

    var pitch = new PitchAnalyzer(4100);

    /* Copy samples to the internal buffer */
    //This is where I have been having the problem.

    pitch.input(????);
    /* Process the current input in the internal buffer */

    pitch.process();
    var tone = pitch.findTone();

    if (tone === null) {
        console.log('No tone found!');
    } else {
        console.log('Found a tone, frequency:', tone.freq, 'volume:', 
 tone.db);
    }
}


</script>
</body>
</html>

【问题讨论】:

  • 你看过演示了吗? github.com/audiocogs/pitch.js-demo
  • 我已经尝试了好几次让 pitch.js-demo 工作但我没能做到。我已经安装了所有库,控制台上没有错误,但它只是在程序刚刚要求访问“flash”的同一位置冻结了一个小屏幕。我猜这是 Flash 问题,但我的浏览器(Windows 平台上的 Chrome)似乎是最新的。
  • 问题解决了!我在 githum github.com/rserota/wad 找到了一个名为“Wad”的资源,它完全符合我的要求!

标签: javascript pitch


【解决方案1】:

问题解决了!我在 githum 找到了一个名为“Wad”的资源 https://github.com/rserota/wad 它完全符合我的要求!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2011-09-23
    相关资源
    最近更新 更多