You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2KB

  1. var audioFileChooser = document.getElementById('audioFileChooser');
  2. audioFileChooser.addEventListener('change', readFile);
  3. function readFile() {
  4. // TODO: deal with multiple files
  5. var fileReader = new FileReader();
  6. fileReader.readAsArrayBuffer(audioFileChooser.files[0]);
  7. fileReader.addEventListener('load', function(ev) {
  8. processFile(ev.target.result);
  9. });
  10. }
  11. function processFile(file) {
  12. var context = new window.AudioContext();
  13. context.decodeAudioData(file, function(buffer) {
  14. var source = context.createBufferSource();
  15. source.buffer = buffer;
  16. source.loop = false;
  17. source.connect(context.destination);
  18. source.start(0);
  19. });
  20. }
  21. function generateOutputFile(fileContents) {
  22. var textFileURL = null;
  23. var blob = new Blob([fileContents], {type: 'text/plain'});
  24. textFileURL = window.URL.createObjectURL(blob);
  25. return textFileURL;
  26. }
  27. var outputFileHolder = document.getElementById('outputFileHolder');
  28. var downloadLink = document.createElement('a');
  29. downloadLink.setAttribute('download', 'test.txt');
  30. downloadLink.href = generateOutputFile("this is a test");
  31. downloadLink.innerHTML = 'download link';
  32. outputFileHolder.appendChild(downloadLink);