读取 Node.js 中计算机的声音输出并分析声音
Read sound output of computer in Node.js and analyze sound
我找不到 Node.js npm 包可以让我记录我的 mac 声音的当前输出并让我分析它。
我正在尝试创建一个仅显示当前从计算机播放的音量的音乐可视化工具。
有没有人知道使用哪种软件包的提示或想法?
您可以使用 'node-audiorecorder' 将时间序列音频数据捕获为 WAV 流。 -> node-audiorecorder
这基本上会为您提供可以使用的浮点值。
上面的一些示例代码,
// Import module.
const AudioRecorder = require('node-audiorecorder');
// Options is an optional parameter for the constructor call.
// If an option is not given the default value, as seen below, will be used.
const options = {
program: `rec`, // Which program to use, either `arecord`, `rec`, or `sox`.
device: null, // Recording device to use, e.g. `hw:1,0`
bits: 16, // Sample size. (only for `rec` and `sox`)
channels: 1, // Channel count.
encoding: `signed-integer`, // Encoding type. (only for `rec` and `sox`)
format: `S16_LE`, // Encoding type. (only for `arecord`)
rate: 16000, // Sample rate.
type: `wav`, // Format type.
// Following options only available when using `rec` or `sox`.
silence: 2, // Duration of silence in seconds before it stops recording.
thresholdStart: 0.5, // Silence threshold to start recording.
thresholdStop: 0.5, // Silence threshold to stop recording.
keepSilence: true // Keep the silence in the recording.
};
// Optional parameter intended for debugging.
// The object has to implement a log and warn function.
const logger = console;
// Create an instance.
let audioRecorder = new AudioRecorder(options, logger);
您可以使用您捕获的数据并使用 audio-render 进行任何您需要做的分析。 (库本身有一些函数可以抓取数据)
myAudioStream
.pipe(Render(function (canvas) {
var data = this.getFloatTimeDomainData();
//draw volume, spectrum, spectrogram, waveform — any data you need
}))
.pipe(Speaker());
我找不到 Node.js npm 包可以让我记录我的 mac 声音的当前输出并让我分析它。
我正在尝试创建一个仅显示当前从计算机播放的音量的音乐可视化工具。
有没有人知道使用哪种软件包的提示或想法?
您可以使用 'node-audiorecorder' 将时间序列音频数据捕获为 WAV 流。 -> node-audiorecorder
这基本上会为您提供可以使用的浮点值。 上面的一些示例代码,
// Import module.
const AudioRecorder = require('node-audiorecorder');
// Options is an optional parameter for the constructor call.
// If an option is not given the default value, as seen below, will be used.
const options = {
program: `rec`, // Which program to use, either `arecord`, `rec`, or `sox`.
device: null, // Recording device to use, e.g. `hw:1,0`
bits: 16, // Sample size. (only for `rec` and `sox`)
channels: 1, // Channel count.
encoding: `signed-integer`, // Encoding type. (only for `rec` and `sox`)
format: `S16_LE`, // Encoding type. (only for `arecord`)
rate: 16000, // Sample rate.
type: `wav`, // Format type.
// Following options only available when using `rec` or `sox`.
silence: 2, // Duration of silence in seconds before it stops recording.
thresholdStart: 0.5, // Silence threshold to start recording.
thresholdStop: 0.5, // Silence threshold to stop recording.
keepSilence: true // Keep the silence in the recording.
};
// Optional parameter intended for debugging.
// The object has to implement a log and warn function.
const logger = console;
// Create an instance.
let audioRecorder = new AudioRecorder(options, logger);
您可以使用您捕获的数据并使用 audio-render 进行任何您需要做的分析。 (库本身有一些函数可以抓取数据)
myAudioStream
.pipe(Render(function (canvas) {
var data = this.getFloatTimeDomainData();
//draw volume, spectrum, spectrogram, waveform — any data you need
}))
.pipe(Speaker());