jeudi 27 juillet 2017

Get sound frequency with web Audio API

I would like to get the real time frequency of a sound but it does not work. here is my code:

navigator.getUserMedia({audio:true,video:false}, function (stream) {
document.querySelector("#music").src = window.URL.createObjectURL(stream)
document.querySelector("#music").play()
var contexteAudio = new (window.AudioContext || window.webkitAudioContext)();
var analyseur = contexteAudio.createAnalyser();
source = contexteAudio.createMediaStreamSource(stream);
source.connect(analyseur);
var tab = new Float32Array();

for (var i=0;i<=100;i++) {
    var datas = analyseur.getFloatFrequencyData(tab);
  document.querySelector("#datas").innerHTML = tab[i];
}

}, function(error) {
console.log(error)
})

You can test it here: http://ift.tt/2w4qwgg

Why can't I get the float value of my real time frequency microphone based ? the value is undefined....




Aucun commentaire:

Enregistrer un commentaire