The AnalyserNode
interface represents a node able to provide real-time frequency and time-domain analysis information. It is an AudioNode
that passes the audio stream unchanged from the input to the output, but allows you to take the generated data, process it, and create audio visualizations.
An AnalyserNode
has exactly one input and one output. The node works even if the output is not connected.
Number of inputs | 1 |
---|---|
Number of outputs |
1 (but may be left unconnected) |
Channel count mode | "explicit" |
Channel count | 1 |
Channel interpretation | "speakers" |
This interface inherits from the following parent interfaces:
AnalyserNode()
AnalyserNode
object.Inherits properties from its parent, AudioNode
.
AnalyserNode.fftSize
AnalyserNode.frequencyBinCount
Read only
AnalyserNode.minDecibels
getByteFrequencyData()
.AnalyserNode.maxDecibels
getByteFrequencyData()
.AnalyserNode.smoothingTimeConstant
Inherits methods from its parent, AudioNode
.
AnalyserNode.getFloatFrequencyData()
Float32Array
array passed into it.AnalyserNode.getByteFrequencyData()
Uint8Array
(unsigned byte array) passed into it.AnalyserNode.getFloatTimeDomainData()
Float32Array
array passed into it.AnalyserNode.getByteTimeDomainData()
Uint8Array
(unsigned byte array) passed into it.Note: See the guide Visualizations with Web Audio API for more information on creating audio visualizations.
The following example shows basic usage of an AudioContext
to create an AnalyserNode
, then requestAnimationFrame
and <canvas>
to collect time domain data repeatedly and draw an "oscilloscope style" output of the current audio input. For more complete applied examples/information, check out our Voice-change-O-matic demo (see app.js lines 128–205 for relevant code).
var audioCtx = new(window.AudioContext || window.webkitAudioContext)(); var analyser = audioCtx.createAnalyser(); // ... analyser.fftSize = 2048; var bufferLength = analyser.frequencyBinCount; var dataArray = new Uint8Array(bufferLength); analyser.getByteTimeDomainData(dataArray); // Get a canvas defined with ID "oscilloscope" var canvas = document.getElementById("oscilloscope"); var canvasCtx = canvas.getContext("2d"); // draw an oscilloscope of the current audio source function draw() { requestAnimationFrame(draw); analyser.getByteTimeDomainData(dataArray); canvasCtx.fillStyle = "rgb(200, 200, 200)"; canvasCtx.fillRect(0, 0, canvas.width, canvas.height); canvasCtx.lineWidth = 2; canvasCtx.strokeStyle = "rgb(0, 0, 0)"; canvasCtx.beginPath(); var sliceWidth = canvas.width * 1.0 / bufferLength; var x = 0; for (var i = 0; i < bufferLength; i++) { var v = dataArray[i] / 128.0; var y = v * canvas.height / 2; if (i === 0) { canvasCtx.moveTo(x, y); } else { canvasCtx.lineTo(x, y); } x += sliceWidth; } canvasCtx.lineTo(canvas.width, canvas.height / 2); canvasCtx.stroke(); } draw();
Specification | Status | Comment |
---|---|---|
Web Audio API The definition of 'AnalyserNode' in that specification. | Working Draft |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 14 | Yes | 25 | No | 15 | 6 |
AnalyserNode() constructor |
55 | ? | 53 | No | 42 | ? |
fftSize |
14 | 12 | 25 | No | 15 | 6 |
frequencyBinCount |
14 | 12 | 25 | No | 15 | 6 |
minDecibels |
14 | 12 | 25 | No | 15 | 6 |
maxDecibels |
14 | 12 | 25 | No | 15 | 6 |
smoothingTimeConstant |
14 | 12 | 25 | No | 15 | 6 |
getFloatFrequencyData |
14 | 12 | 25 | No | 15 | 6 |
getByteFrequencyData |
14 | 12 | 25 | No | 15 | 6 |
getFloatTimeDomainData |
14 | 12 | 25 | No | 15 | 6 |
getByteTimeDomainData |
14 | 12 | 25 | No | 15 | 6 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | 18 | Yes | 26 | 15 | ? | Yes |
AnalyserNode() constructor |
55 | 55 | ? | 53 | 42 | ? | 6.0 |
fftSize |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
frequencyBinCount |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
minDecibels |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
maxDecibels |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
smoothingTimeConstant |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
getFloatFrequencyData |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
getByteFrequencyData |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
getFloatTimeDomainData |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
getByteTimeDomainData |
Yes | 18 | Yes | 26 | 15 | ? | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode