# How can I get sound data?

**URL:** <https://discourse.processing.org/t/how-can-i-get-sound-data/26160>\
**Category:** Libraries\
**Created:** [December 12, 2020, 4:41pm UTC](https://discourse.processing.org/t/how-can-i-get-sound-data/26160 "2020-12-12T16:41:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kokosic](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kokosic](https://discourse.processing.org/u/kokosic)\
**Post date:** [December 12, 2020, 4:41pm UTC](https://discourse.processing.org/t/how-can-i-get-sound-data/26160/1 "2020-12-12T16:41:18Z")

</div>

I have this [library](https://www.npmjs.com/package/music-tempo)  
and this code

```auto
var context = new AudioContext();
var fileInput = document.getElementById("fileInput");

fileInput.onchange = function () {
  var files = fileInput.files;

  if (files.length == 0) return;
  var reader = new FileReader();

  reader.onload = function(fileEvent) {
    context.decodeAudioData(fileEvent.target.result, calcTempo);
    print(fileEvent.target.result);
  }

  reader.readAsArrayBuffer(files[0]);
}
var calcTempo = function (buffer) {
  var audioData = [];
  // Take the average of the two channels
  if (buffer.numberOfChannels == 2) {
    var channel1Data = buffer.getChannelData(0);
    var channel2Data = buffer.getChannelData(1);
    var length = channel1Data.length;
    for (var i = 0; i < length; i++) {
      audioData[i] = (channel1Data[i] + channel2Data[i]) / 2;
    }
  } else {
    audioData = buffer.getChannelData(0);
  }
  var mt = new MusicTempo(audioData);

  console.log(mt.tempo);
  console.log(mt.beats);
}

```

But how do I point to a file from a project without file input?  
Thanks)

---

<div class="post-metadata">

**Author:** ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)\
**Post date:** [December 13, 2020, 8:55am UTC](https://discourse.processing.org/t/how-can-i-get-sound-data/26160/2 "2020-12-13T08:55:20Z")

</div>

Not sure about your specific library if it’s not in its documentation, I assume you looked there or in the code/examples.

I’ve been using the minim library ([http://code.compartmental.net/tools/minim/](http://code.compartmental.net/tools/minim/))

> Here are some of the features of Minim:

- AudioPlayer: Mono and Stereo playback of WAV, AIFF, AU, SND, and MP3 files.
- AudioMetaData: An object filled with metadata about a file, such as ID3 tags.
- AudioRecorder: Mono and Stereo audio recording either buffered or direct to disk.
- AudioInput: Mono and Stereo input monitoring.
- AudioOutput: Mono and Stereo sound synthesis.
- FFT: perform a Fourier Transform on audio data to generate a frequency spectrum.
- BeatDetect: a class for doing beat detection.
- A [real-time synthesis framework](http://code.compartmental.net/minim/index_ugens.html) based around unit generators, which we call UGens.
