问题
I have been tinkering around with the CMUSphinx/Pocketsphinx and Node.js. What I'd like to do is spawn pocketsphinx_continuous in the background and then use node as a traffic control layer on top.
However, pocketsphinx seems to ignore stdout completely. Does anyone know if that is by design? If I run it via CLI I will see out put like:
READY....
Listening...
INFO: ngram_search.c(467): Resized score stack to 200000 entries INFO: ngram_search.c(459): Resized backpointer table to 10000 entries
The INFO and error outputs can be seen from stderror. AFAICT the READY, Listening and any successful word recognition cannot be seen and are not being sent to stdout.
My node is really simple and works fine on a test bash script doing a Hello World like echo:
if(ps == null) {
//'-logfn','/dev/null',
//sudo pocketsphinx_continuous -dict lm/8531.dic -lm lm/8531.lm -kws words.kws -kws_threshold 1e-40 -logfn /dev/null -inmic yes
//console.log(process.stdout.write(''));
ps = spawn('pocketsphinx_continuous', ['-nfft','2048', '-hmm','/usr/local/share/pocketsphinx/model/en-us/en-us', '-dict','lm/8531.dic', '-lm','lm/8531.lm', '-kws','words.kws', '-kws_threshold','1e-40', '-inmic', 'yes']);
//ps = spawn('bash',['test.sh']);
//ps.stderr.pipe(process.stdout);
//console.log(ps.stdout.write(''));
ps.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ps.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
}
Is this info only available via GStreamer or the like? Thanks in advance.
回答1:
However, pocketsphinx seems to ignore stdout completely. Does anyone know if that is by design?
Yes, we did not flush stdout by default. You need to run pocketsphinx under PTY or wait for the program to finish to get output.
In revision 13156 we fixed this, you can just update, then you should get messages as soon as they decoded.
What I'd like to do is spawn pocketsphinx_continuous in the background and then use node as a traffic control layer on top.
It is better to use node bindings directly instead of spawn:
https://github.com/cmusphinx/node-pocketsphinx
回答2:
Use unbuffer
from the expect package
Here is my example of it working
$> mkfifo pipe
$> unbuffer pocketsphinx_continuous -inmic yes -keyphrase "ok dag knee" -kws_threshold "\1e-15" -logfn /dev/null > pipe
In another terminal
&> cat < pipe
It works as expected...
READY....
Listening...
Just call unbuffer in the spwan
and pass pocketsphinx_continuous
as an argument
来源:https://stackoverflow.com/questions/30601701/does-pocketsphinx-flush-stdout