text: //webkitURL is deprecated but nevertheless
  URL = window.URL || window.webkitURL;
  
  var gumStream; 						//stream from getUserMedia()
  var rec; 							//Recorder.js object
  var input; 							//MediaStreamAudioSourceNode we'll be recording
  
  // shim for AudioContext when it's not avb. 
  var AudioContext = window.AudioContext || window.webkitAudioContext;
  var audioContext //audio context to help us record
  
  var recordButton = document.getElementById("recordButton");
  var stopButton = document.getElementById("stopButton");
  var pauseButton = document.getElementById("pauseButton");
  
  //add events to those 2 buttons
  recordButton.addEventListener("click", startRecording);
  stopButton.addEventListener("click", stopRecording);
  pauseButton.addEventListener("click", pauseRecording);
  
  function startRecording() {
  	console.log("recordButton clicked");
  
  	/*
  		Simple constraints object, for more advanced audio features see
  		https://addpipe.com/blog/audio-constraints-getusermedia/
  	*/
      
      var constraints = { audio: true, video:false }
  
  	recordButton.disabled = true;
  	stopButton.disabled = false;
  	pauseButton.disabled = false
  
  	navigator.mediaDevices.getUserMedia(constraints).then(function(stream) {
  		console.log("getUserMedia() success, stream created, initializing Recorder.js ...");
  		audioContext = new AudioContext();
  
  		//update the format 
  		document.getElementById("formats").innerHTML="Format: 1 channel pcm @ "+audioContext.sampleRate/1000+"kHz"
  		gumStream = stream;
  		input = audioContext.createMediaStreamSource(stream);
  		rec = new Recorder(input,{numChannels:1})
  		rec.record()
  
  		console.log("Recording started");
  
  	}).catch(function(err) {
  	  	recordButton.disabled = false;
      	stopButton.disabled = true;
      	pauseButton.disabled = true
  	});
  }
  
  function pauseRecording(){
  	console.log("pauseButton clicked rec.recording=",rec.recording );
  	if (rec.recording){
  		rec.stop();
  		pauseButton.innerHTML="Resume";
  	}else{
  		rec.record()
  		pauseButton.innerHTML="Pause";
  	}
  }
  
  function stopRecording() {
  	console.log("stopButton clicked");
  
  	//disable the stop button, enable the record too allow for new recordings
  	stopButton.disabled = true;
  	recordButton.disabled = false;
  	pauseButton.disabled = true;
  
  	//reset button just in case the recording is stopped while paused
  	pauseButton.innerHTML="Pause";
  	
  	//tell the recorder to stop the recording
  	rec.stop();
  
  	//stop microphone access
  	gumStream.getAudioTracks()[0].stop();
  
  	//create the wav blob and pass it on to createDownloadLink
  	rec.exportWAV(createDownloadLink); 	
  }
  
  
  function createDownloadLink(blob) {
  	
  	var url = URL.createObjectURL(blob);
  	var au = document.createElement('audio');
  	var li = document.createElement('li');
  	var link = document.createElement('a');
  
  	// var filename = new Date().toISOString();
  
  	link.href = url;
  	link.download = "voice.wav"; //download forces the browser to donwload the file using the  filename
  	link.innerHTML = "Audio File";
  
  	//add the new audio element to li
  	li.appendChild(au);
  	
  	//add the save to disk link to li
  	li.appendChild(link);
  	
  	//add the li element to the ol
  	recordingsList.appendChild(li);
  }
  
  
  