NodeJS 执行时 PocketSphinx 无法从 stdin 读取

PocketSphinx can't read from stdin when executed by NodeJS

我正在尝试将数据流从 NodeJS 传递到 pocketsphinx_continuous 进程。我的想法是使用 NodeJS 的管道功能将我的数据发送到 pocketsphinx 进程的标准输入流。

如果我运行

pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18

在命令行上,然后 pocketsphinx_continuous 启动并耐心等待 stdin 输入。

但是,当我添加

var ps = exec('pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18', function(error, stdout, stderr) {});

我的 NodeJS 程序,我得到:

FATAL: "continuous.c", line 158: Failed to open file '/dev/stdin' for reading: No such device or address

我很难理解为什么在 NodeJS 下 运行ning 时会出现此错误,而在正常 运行ning 时却不会。

谢谢,

乔什

我在 nodejs GitHub 上找到了 an issue,它回答了我的问题。

我已将我的代码调整为以下内容,现在可以使用了:

var ps = exec('cat | pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18', function(error, stdout, stderr) {});

通过 cat 的管道将 NodeJS 为子进程创建的套接字标准输入转换为允许 /dev/stdin 工作的管道标准输入。