0

I am trying to do some audio analysis for a visualizer running on my computer.

Is is possible to access the output audio data stream directly from the browser?

Currently running JavaScript with the three.js and meyda libraries.

I've figured out how to use the webAudio API to analyze input from the microphone, but can't seem to gain access to the audio output on my computer.

I've tried to connect source to the destination using

source.connect(audioContext.destination) 

but this doesn't seem to do anything.

This is our current listener config:

// // Listener
const bufferSize = 256;
let analyzer;

// The navigator object contains information about the browser.
// this async call initializes audio input from the user
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(stream => {
  if (!analyzer) initAnalyzer(stream)
})


function initAnalyzer(stream) {
  const audioContext = new AudioContext();
  // set audio source to input stream from microphone (Web Audio API https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamAudioSourceNode)
  const source = audioContext.createMediaStreamSource(stream);

  analyzer = Meyda.createMeydaAnalyzer({
    audioContext: audioContext,
    source: source,
    bufferSize: bufferSize,
    featureExtractors: [ 'amplitudeSpectrum', 'spectralFlatness' ], // ["rms", "energy"],
    callback: features => null
  });
  analyzer.start();
}
Mugen87
  • 28,829
  • 4
  • 27
  • 50

2 Answers2

0

It's not possible to grab the audio from the computer without external software like Audio Hijack. Sorry!

Hugh Rawlinson
  • 979
  • 9
  • 29
0

audiooutputs cannot be accessed for privacy, only audioinputs (and only after confirming with the user). On Windows you can enable "stereo mix" that routes all outputs to a virtual input, and you can use that, but it requires all users to have stereo mix enabled...

The visualizers you see are using the buffer or source that they created so of course they have access to it.

aandroyd
  • 79
  • 3