constaudioElement = document.getElementById('audio');constviewElement = document.getElementById('div-analyzer');constwaveFormGraph = newWaveformGraph(audioElement, viewElement, { colorPositive:'#00daff', colorNegative:'#00b6d5' });// We can start only after user starts interact with our page.// This is because of HTML Web Audio API restriction.document.body.onclick = () => {waveFormGraph.render();}
Example 2: Draw the waveform and set the data to the other graph.
constaudioElement = document.getElementById('audio');constviewElement1 = document.getElementById('div-analyzer-1');constviewElement2 = document.getElementById('div-analyzer-2');constwaveFormGraph1 = newWaveformGraph(audioElement, viewElement1, { colorPositive:'#00daff', colorNegative:'#00b6d5' });constwaveFormGraph2 = newWaveformGraph(newAudio(), viewElement2, { colorPositive:'#00daff', colorNegative:'#00b6d5' });// We can start only after user starts interact with our page.// This is because of HTML Web Audio API restriction.document.body.onclick = () => {// Draw the first graph.waveFormGraph1.render().then(() => {// Get a simplified data samples for drawing.// 2000 values are more than enough to draw fast and correct on full HD screen.constdata = waveFormGraph1.getDataSampling(2000);// Set obtained the data to the new waveform graph and draw it.waveFormGraph2.setDataSampling(data).render();// Obtained "data" - You can save and use for fast render. });}
Waveform graphic draw widget.
Example 1: Just draw the waveform.
Example 2: Draw the waveform and set the data to the other graph.
See more options at interface definition: IWaveFormGraphOptions