我正在尝试对在我的计算机上运行的可视化器进行一些音频分析。
是否可以直接从浏览器访问输出音频数据流?
当前使用three.js 和meyda 库运行JavaScript。
我已经弄清楚如何使用 webAudio API 来分析来自麦克风的输入,但似乎无法访问我计算机上的音频输出。
我尝试使用将源连接到目标
source.connect(audioContext.destination)
但这似乎无济于事。
这是我们当前的监听器配置:
// // 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();
}