简体   繁体   English

是否可以从节点 js 中的 Windows CLI 实用程序获取数据流?

[英]Is it possible to get a data stream from windows CLI utility in node js?

I'd like to create a node app that records and parses audio from the system output device in my Windows 10. It looks like it's a real challenge because I've checked many npm packages but didn't find anything that allows audio recording from the output device.我想创建一个节点应用程序,用于记录和解析来自 Windows 10 中系统输出设备的音频。看起来这是一个真正的挑战,因为我检查了许多 npm 包,但没有找到任何允许从输出设备。 So I found a third-party CLI utility that works for Windows 10 I'm not sure that I should give its name because it could be threatened like marketing etc.所以我找到了一个适用于 Windows 10 的第三方 CLI 实用程序,我不确定我应该给出它的名字,因为它可能像营销等一样受到威胁。

so this CLI utility allows to record a loopback audion for the output device and save it to the WAV file.所以这个 CLI 实用程序允许为输出设备记录一个环回三音节并将其保存到 WAV 文件中。
I'm wondering if there exists some way to intercept the data stream that comes from this utility to the WAV file from my NODE.js app to handle it?我想知道是否存在某种方法来拦截来自该实用程序的数据流到来自我的 NODE.js 应用程序的 WAV 文件来处理它? or if the CLI utility doesn't provide some API to get this data it isn't possible?或者如果 CLI 实用程序没有提供一些 API 来获取这些数据,那是不可能的?

I also was thinking about the immediate opening of the WAV file and reading this file during the recording to get the recent data in the node.js app and handle it but I'm not sure that it's possible due to the write/read stream for the same file (from CLI - write, and from NODE - read)我也在考虑立即打开 WAV 文件并在录制期间读取此文件以获取 node.js 应用程序中的最新数据并处理它,但我不确定这是否可能由于写入/读取流同一个文件(来自 CLI - 写入,来自 NODE - 读取)

Thanks for any help or info!感谢您提供任何帮助或信息!

PS Sorry if my question is stupid. PS对不起,如果我的问题很愚蠢。 I'm not familiar with such low-level things我对这种低级的东西不熟悉

After a night of research, I managed to get the data in my particular situation.经过一夜的研究,我设法在我的特定情况下获得了数据。
I used a spawn from the node child process package to create a dedicated process where I executed the CLI utility with the appropriate arguments that send the recording data directly into the STDOUT.我使用节点子进程包中的一个子进程来创建一个专用进程,在该进程中我使用适当的参数执行 CLI 实用程序,将记录数据直接发送到 STDOUT。 Please, keep in mind that exec won't work in this particular task due to the buffer issue请记住,由于缓冲区问题exec将无法在此特定任务中工作

The most important thing here: Luckily the CLI utility has the possibility to send the recording data chunks to the STDOUT instead of the file.这里最重要的是:幸运的是,CLI 实用程序可以将记录数据块发送到 STDOUT 而不是文件。 However, I don't know what would I do if it couldn't.但是,如果不能,我不知道该怎么办。 I don't know if there is an existing way to intercept the data that writes directly into the output file so this answer isn't 100% fits the question.我不知道是否存在拦截直接写入输出文件的数据的现有方法,所以这个答案不是 100% 适合这个问题。 What to do if a CLI doesn't write the data into the STDOUT?如果 CLI 不将数据写入 STDOUT 怎么办? If someone knows about it: please, let me know, I'll appreciate it a lot如果有人知道:请告诉我,我将不胜感激

Here is the basic code example:这是基本的代码示例:

import { spawn } from 'node:child_process';

 const child = spawn('fmedia', ['--record', '--dev-loopback=0', '-o', '@stdout.wav']);
  child.stdout.on('data', data => {
    console.log('stdout data -> ', data);
  })
  child.stderr.on('data', data => {
    console.log('stderr data -> ', data);
  })
  child.on('close', code => {
    console.log('child process exited with code ' + code);
  });

Kind regards亲切的问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM