间距检测程序问题

时间:2017-05-18 10:57:58

标签: javascript pitch

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

我正在尝试创建一个程序,该程序使用歌手的音高在屏幕上上下移动对象。为此,我需要连续(或每250ms左右)音高检测程序并访问麦克风。 我正在尝试使用“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>

1 个答案:

答案 0 :(得分:0)

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