js实现实时麦克风音量大小捕获指示器效果代码
代码语言:html
所属分类:多媒体
代码描述:js实现实时麦克风音量大小捕获指示器效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script> <script type="text/javascript"> navigator.mediaDevices.getUserMedia({ audio: true }) .then(function(stream) { audioContext = new AudioContext(); analyser = audioContext.createAnalyser(); microphone = audioContext.createMediaStreamSource(stream); javascriptNode = audioContext.createScriptProcessor(2048, 1, 1); analyser.smoothingTimeConstant = 0.8; analyser.fftSize = 1024; microphone.connect(analyser); analyser.connect(javascriptNode); javascriptNode.connect(audioContext.destination); javascriptNode.onaudioprocess = function() { var array = new Uint8Array(analyser.frequencyBinCount); analyser.getByteFrequencyData(array); var values = 0; var length = array.length; for (var i = 0; i < length; i++) { values += (array[i]); } var average = values / length; //检测到的声音输入带下,输出一下 console.log(Math.round(average)); colorPids(Math.round(average)); // colorPids(average); } }) .catch(function(err) { /* handle the error */ }); function colorPids(vol) { let all.........完整代码请登录后点击上方下载按钮下载查看
网友评论0