I'm trying to pass a stream of data from NodeJS to a pocketsphinx_continuous process. My idea of how to do this is to use NodeJS's pipe functionality to send my data to the stdin stream of the pocketsphinx process.
If I run
pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18
on the command line then pocketsphinx_continuous launches and waits patiently for stdin input.
However, when I add
var ps = exec('pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18', function(error, stdout, stderr) {});
to my NodeJS program, I get:
FATAL: "continuous.c", line 158: Failed to open file '/dev/stdin' for reading: No such device or address
I'm struggling to understand why I would get this error when running under NodeJS but not when running normally.
Thanks,
Josh
I found an issue on the nodejs GitHub which answered my question.
I've adjusted my code to the following and it now works:
var ps = exec('cat | pocketsphinx_continuous -infile /dev/stdin -nfft 2048 -samprate 44100 -keyphrase "hello computer" -kws_threshold 1e-18', function(error, stdout, stderr) {});
Piping through cat converts the socket stdin that NodeJS creates for child processes into a pipe stdin that allows /dev/stdin to work.