如何在JavaScript中检测声音的频率?

时间:2016-03-24 23:43:00

标签: javascript html5 audio

如何检测听觉范围内是否有声音?

例如,

如果出现沉默图标:

  • 范围低于 20 Hz
  • 范围高于 20 kHz

stream.pausedfalse

2 个答案:

答案 0 :(得分:0)

您可以使用此pitch detection音频库。

示例:

var voice = new Wad({source : 'mic' });
var tuner = new Wad.Poly();
tuner.add(voice);
voice.play();

tuner.updatePitch() // The tuner is now calculating the pitch and note name of its input 60 times per second. These values are stored in tuner.pitch and tuner.noteName.

var logPitch = function(){
    console.log(tuner.pitch, tuner.noteName)
    requestAnimationFrame(logPitch)
};
logPitch();
// If you sing into your microphone, your pitch will be logged to the console in real time.

tuner.stopUpdatingPitch(); // Stop calculating the pitch if you don't need to know it anymore.

答案 1 :(得分:-1)

我不知道你是否可以用javascript找到hz。您可能必须使用Web音频API。但是,使用javascript,您绝对可以在数字刻度上检查和设置音量。在此处查看详细信息和示例代码:http://www.w3schools.com/tags/av_prop_volume.asp

示例值: 1.0是最高音量(100%。这是默认值) 0.5是半体积(50%) 0.0是静音(与静音相同)