diff --git a/cmd/audio-player/main.js b/cmd/audio-player/main.js index 00d0eab6..1d893bb3 100644 --- a/cmd/audio-player/main.js +++ b/cmd/audio-player/main.js @@ -23,35 +23,36 @@ LICENSE */ window.onload = function () { + document.getElementById('input').addEventListener('change', processData) +} - document.getElementById('input').addEventListener('change', function () { - const input = event.target.files[0] - const reader = new FileReader() +function processData() { + const input = event.target.files[0] + const reader = new FileReader() - reader.onload = event => { - bytes = new Uint8Array(event.target.result) + reader.onload = event => { + bytes = new Uint8Array(event.target.result) - // decode adpcm to pcm - var decoded = decode(Array.from(bytes)) + // decode adpcm to pcm + var decoded = decode(Array.from(bytes)) - // convert raw pcm to wav - var wav = pcmToWav(decoded, 48000, 1, 16); + // convert raw pcm to wav + var wav = pcmToWav(decoded, 48000, 1, 16); - // play wav data in player - const blob = new Blob([Uint8Array.from(wav)], { - type: 'audio/wav' - }); - const url = URL.createObjectURL(blob); + // play wav data in player + const blob = new Blob([Uint8Array.from(wav)], { + type: 'audio/wav' + }); + const url = URL.createObjectURL(blob); - const audio = document.getElementById('audio'); - const source = document.getElementById('source'); + const audio = document.getElementById('audio'); + const source = document.getElementById('source'); - source.src = url; - audio.load(); - audio.play(); - } - reader.onerror = error => reject(error) - reader.readAsArrayBuffer(input) + source.src = url; + audio.load(); + audio.play(); + } + reader.onerror = error => reject(error) + reader.readAsArrayBuffer(input) - }) } \ No newline at end of file