Audio visual feature for audio/video files in Java Script

You might have seen some wave like visuals representing the audio waves in many players or audio editing tools.

Let’s see how that feature can be added simply using an available library of JS.

Wavesurfer.js is a library that would help us achieve this. Using this feature is as simple as just importing a library. You can check the documentation of wavesurfer here

Let’s create a HTML page that will accept an audio/video file and when submitted, it shows the visual representation


<!DOCTYPE html>
		<meta charset="UTF-8">
		<title>audio visual</title>
		<script src=""></script>
   	        <link href="//" rel="stylesheet">
		<script src="" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
		<script src=""></script>
	        <script src=""></script>
	padding-bottom : 18px;
	<div class="container-fluid">
		<div id="waveform"></div>
		<div id="wave-timeline"></div>
		<div class="controls col-md-12" id="control-panel">
			<div class="col-md-2"><button id="play-btn" class="btn btn-primary" onclick="wavesurfer.playPause()">
					<i class="glyphicon glyphicon-play"></i>
					<i class="glyphicon glyphicon-pause"></i>
			<div class="col-sm-1 text-center">
				<i class="glyphicon glyphicon-zoom-out" title="slide left for zoom-out"></i>

			<div class="col-sm-3">
				<input id="slider" data-action="zoom" type="range" min="20" max="200" value="0" style="width: 100%">

			<div class="col-sm-1 text-center">
				<i class="glyphicon glyphicon-zoom-in" title="slide right for zoom-in"></i>

		<div class="controls col-md-12">
			<div class="col-md-4">	<input id="loadFile"class="btn btn-primary" type="file"></input></div>
			<div class="col-md-2">	<input  class="btn btn-primary" type="submit" value="submit" onclick="submit()" ></input></div>


The above html code would take care of uploading a audio file and send it to wavesurfer library on clicking submit button.

Let’s look at the js code now. This code can either be placed a separated js file and imported or you can add append this code between <script></script> before ending html tag.

var ctrlPanel = document.getElementById('control-panel');
var wavePanel = document.getElementById('waveform'); = "none";
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'violet',
progressColor: 'purple',
scrollParent: true,
notchPercentHeight: 90,
plugins: [
container: "#wave-timeline"
function submit(){
		var lFile = $('#loadFile').prop("files")[0];
		if(lFile !== undefined && lFile !== ""){
		var bFile = new Blob([lFile]);
		document.getElementById("waveform").style.border = "1px black solid";
	wavesurfer.on('ready', function () {; = "block";			});
	console.log("empty file");
document.querySelector('#slider').oninput = function () {

That’s it! you’re good to go now. You can access this html file through apache and upload a audio/video file to get the audio visual

Start a Conversation

Your email address will not be published. Required fields are marked *