2

I have a command that outputs the following:

READY
Listening....
HELLO
READY
Listening....
TEST

It is speech recognition from pocketsphinx_continuous.

I need that output redirected to a file, and it does not seem to be comming from stdout or stderr because I have tried adding 1>log.txt and 2>log.txt and every time they are blank.

Here is the kicker: when I add 1>log.txt to the command, there is no longer any output to the console, but log.txt is still blank.

Also, when I add | tee log.txt it does not show up in the console and the file is still blank.

Is this output coming from stdout, if so, why is it not being redirected to the file?

This question is related to my other question here: Redirect Output of Pocketsphinx_continuous to a file

Pocketsphinx is weird and using it's arguments to redirect output is not possible for me, in this question I just want to know where this output is coming from sdtout or sdterr or some other place, and how to redirect that output.

EDIT

ls -l /proc/PID/fd/ returns:

lrwx------ 1 pi pi 64 Jan  4 04:12 0 -> /dev/pts/2
lrwx------ 1 pi pi 64 Jan  4 04:12 1 -> /dev/pts/2
lrwx------ 1 pi pi 64 Jan  4 04:11 2 -> /dev/pts/2
lrwx------ 1 pi pi 64 Jan  4 04:12 4 -> /dev/snd/pcmC0D0c
  • 1
    It would probably be good to note the other question for context, and explain why this one isn't a duplicate. – Michael Homer Jan 4 '16 at 4:37
  • 1
    You might be able to capture the output with the script command (unless this was a message, say, sent from the kernel to all console devices). – Thomas Dickey Jan 4 '16 at 9:00
  • Alternately, the program might detect if its output is redirected. Someone with a pocketSphinx needs to do some investigation to see where the output goes. – Thomas Dickey Jan 4 '16 at 9:25
  • 1
    ls -l /proc/<PID>/fd/ – pawel7318 Jan 4 '16 at 9:28
  • @pawel7318 - or just /dev/fd/ – mikeserv Jan 4 '16 at 9:38
2

The hideous command:

script -q -f -c "pocketsphinx_continuous -samprate 48000 -nfft 2048 -hmm /usr/local/share/pocketsphinx/model/en-us/en-us -lm 9745.lm -dict 9745.dic -inmic yes -logfn /dev/null" words.txt &

works for me, it logs:

READY....
Listening...
HELLO

to the file, and it is easy to weed out the unwanted stuff.

EDIT: If anyone is doing this themselves in the future, remove the & at the end of that command if you are executing it in a console, if you are executing it via Python or another language, keep the & at the end.

1

The linux manual pages say

the standard input and output streams are fully buffered if and only if the streams do not refer to an interactive device.

So you may need to generate a lot of output (4096 bytes) before something shows up in the output.

If there is a regular way to stop pocketsphinx, and if it is implemented correctly, it should flush the buffers to the output file when you stop it. This would at least prove the buffering theory, but of course it would not help you yet in getting the output in time.

This answer or others for the respective question may help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.