Javascript 基音检测程序问题

Javascript 基音检测程序问题,javascript,pitch,Javascript,Pitch,我已经搜索了一个音高检测程序,但是没有任何东西给我提供我需要的指导。我正在尝试使用pitch.js,但无法将麦克风缓冲区放入程序中 我正在尝试创建一个程序,使用歌手的音调在屏幕上上上下移动一个对象。为此,我需要一个连续(或每250ms左右)的音调检测程序,并使用麦克风。 我试图使用“pitch.js”,但无法将麦克风缓冲区设置为“pitch.input” /* Copy samples to the internal buffer */ pitch.input(inputBuffe

我已经搜索了一个音高检测程序,但是没有任何东西给我提供我需要的指导。我正在尝试使用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>
var audioContext=new audioContext();
log(“音频正在启动…”);
var BUFF_SIZE=16384;
var audioInput=null,
麦克风\u流=空,
增益节点=空,
脚本\处理器\节点=null,
脚本\处理器\节点=null,
AnalyzerNode=null;
如果(!navigator.getUserMedia)
navigator.getUserMedia=navigator.getUserMedia |
navigator.webkitGetUserMedia||
navigator.mozGetUserMedia |
navigator.msGetUserMedia;
if(navigator.getUserMedia){
getUserMedia({audio:true},
功能(流){
启动麦克风(流);
},
职能(e){
警报(“捕获音频时出错”);
}
);
}else{alert('getUserMedia在此浏览器中不受支持。');}
功能启动\u话筒(流){
gain_node=audioContext.createGain();
获取节点连接(audioContext.destination);
麦克风\u流=audioContext.createMediaStreamSource(流);
麦克风\流连接(增益\节点);
//---为输出扬声器启用音量控制
document.getElementById('volume')。addEventListener('change',function()
{ 
var curr_volume=此值;
增益节点。增益值=当前音量;
日志(“当前卷”,当前卷);
});
script\u processor\u node=audioContext.createScriptProcessor(2048,1,1);
脚本\处理器\节点。连接(增益\节点);
函数setPitch(){
变桨距=新变桨距分析器(4100);
/*将样本复制到内部缓冲区*/
//这就是我一直遇到的问题。
音高输入(??);
/*处理内部缓冲区中的当前输入*/
pitch.process();
var tone=pitch.findTone();
如果(音调===null){
console.log('找不到音调!');
}否则{
console.log('找到一个音调,频率:',tone.freq',volume:',
音调(db);
}
}

问题解决了!我在githum找到了一个名为“Wad”的资源
这正是我想要的!问题解决了!我在githum找到了一个名为“Wad”的资源
它完全符合我的要求!

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