当由NodeJS执行时,PocketSphinx无法从标准input读取数据
我试图从NodeJS传递一个数据stream到一个pocketsphinx_continuous进程。 我的想法是使用NodeJS的pipe道function将数据发送到pocketsphinx进程的标准inputstream。
如果我跑
pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18
在命令行上,然后pocketsphinx_continuous启动并耐心等待stdininput。
但是,当我补充
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”,第158行:无法打开文件“/ dev / stdin”进行读取:没有这样的设备或地址
我很努力地理解为什么我会在NodeJS下运行时得到这个错误,但是在正常运行时不会。
谢谢,
玩笑
我在nodejs GitHub上发现了一个问题 ,它回答了我的问题。
我已经调整了我的代码到以下,现在它的作品:
var ps = exec('cat | pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18', function(error, stdout, stderr) {});
通过catpipe道将NodeJS为subprocess创build的套接字标准input转换为允许/ dev / stdin工作的pipe道标准input。