我有两台计算机,这些计算机通过音频到麦克风的电缆相互连接,其中一台是带有html文件的笔记本电脑,该笔记本计算机生成的频率从1khz到20khz,名为(generator.html),另一台在台式机上可以检测到称为(pitchdetect.html)的频率,在6khz以下一切都可以正常工作,但是当我超过该频率时(pitchdetect.js)文件无法捕获该频率,它将指示错误值,我试图更改频率在pitchdetect.html中没有成功。这是我的两个代码
generator.html:
<html>
<head>
<title>Alertku - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function alertku(){
if(alertku.opt){
document.getElementById('alertku_span').firstChild.nodeValue += ', run';
var fx = Number(document.getElementById("fof").value);
//create the context for the web audio
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
//create, tune, start and connect each oscillator sinea
var sinea = audioCtx.createOscillator();
sinea.frequency.value = fx;
sinea.type = "sine";
sinea.start();
sinea.connect(audioCtx.destination);
setTimeout(alertku, 1000);
}
};
</script>
</head>
<body>
<div>
<input type="text" id="fof" value="1000">
<input type="button" value="RUN" onclick="alertku.opt = true; alertku();">
<input type="button" value="STOP" onclick="alertku.opt = false;"><br>
<span id="alertku_span">hum</span>
</div>
</body>
</html>
以及该URL上可用的pitchdetect.js:
https://github.com/cwilso/PitchDetect/blob/master/js/pitchdetect.js
我将MAX_SIZE频率值从5000更改为 20000 ,但没有成功:
audioContext = new AudioContext();
MAX_SIZE = Math.max(4,Math.floor(audioContext.sampleRate/5000)); //
corresponds to a 5kHz signal.....I have changed it to 20000
var request = new XMLHttpRequest();
request.open("GET", "../sounds/whistling3.ogg", true);
request.responseType = "arraybuffer";
request.onload = function() {
audioContext.decodeAudioData( request.response, function(buffer) {
theBuffer = buffer;
有帮助吗?