gpt4 book ai didi

javascript - 音高检测程序问题

转载 作者:行者123 更新时间:2023-11-28 04:37:41 28 4
gpt4 key购买 nike

我已经搜索过音高检测程序,但没有任何东西可以给我所需的指导。我正在尝试使用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>

最佳答案

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

关于javascript - 音高检测程序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44045891/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com