3

I have an ugly command:

pocketsphinx_continuous -samprate 48000 -nfft 2048 -hmm /usr/local/share/pocketsphinx/model/en-us/en-us -lm 9745.lm -dict 9745.dic -inmic yes

Breakdown: It listens for any noise and when it detects some, it listens to it, and then performs speech recognition on it.

Now, the command output has a bunch of junk in it, and one line that matters. Here is the output of one speech recognition:

READY....
Listening...
INFO: cmn_prior.c(131): cmn_prior_update: from < 21.18 -11.87  6.18  0.77  4.42 -0.76  1.99  8.43  2.83 -1.46  3.80  6.19  3.71 >
INFO: cmn_prior.c(149): cmn_prior_update: to   < 23.28 -5.11  8.81 -0.28  0.06 -0.83  0.94  6.68  0.42  1.07  4.00  7.34  4.32 >
INFO: ngram_search_fwdtree.c(1553):      814 words recognized (9/fr)
INFO: ngram_search_fwdtree.c(1555):    60871 senones evaluated (684/fr)
INFO: ngram_search_fwdtree.c(1559):    37179 channels searched (417/fr), 6846 1st, 21428 last
INFO: ngram_search_fwdtree.c(1562):     1415 words for which last channels evaluated (15/fr)
INFO: ngram_search_fwdtree.c(1564):     2626 candidate words for entering last phone (29/fr)
INFO: ngram_search_fwdtree.c(1567): fwdtree 0.66 CPU 0.742 xRT
INFO: ngram_search_fwdtree.c(1570): fwdtree 3.36 wall 3.780 xRT
INFO: ngram_search_fwdflat.c(302): Utterance vocabulary contains 21 words
INFO: ngram_search_fwdflat.c(948):      655 words recognized (7/fr)
INFO: ngram_search_fwdflat.c(950):    40095 senones evaluated (451/fr)
INFO: ngram_search_fwdflat.c(952):    31447 channels searched (353/fr)
INFO: ngram_search_fwdflat.c(954):     1794 words searched (20/fr)
INFO: ngram_search_fwdflat.c(957):     1006 word transitions (11/fr)
INFO: ngram_search_fwdflat.c(960): fwdflat 0.29 CPU 0.326 xRT
INFO: ngram_search_fwdflat.c(963): fwdflat 0.30 wall 0.333 xRT
INFO: ngram_search.c(1253): lattice start node <s>.0 end node </s>.70
INFO: ngram_search.c(1279): Eliminated 1 nodes before end node
INFO: ngram_search.c(1384): Lattice has 127 nodes, 473 links
INFO: ps_lattice.c(1380): Bestpath score: -2298
INFO: ps_lattice.c(1384): Normalizer P(O) = alpha(</s>:70:87) = -132973
INFO: ps_lattice.c(1441): Joint P(O,S) = -156371 P(S|O) = -23398
INFO: ngram_search.c(875): bestpath 0.01 CPU 0.011 xRT
INFO: ngram_search.c(878): bestpath 0.00 wall 0.005 xRT
HELLO

That HELLO is the only thing that matters, and I want that to be output into a file somehow.

I have already tried adding >foo.txt to the end of the command, which works, except it outputs everything except for HELLO to the file and HELLO never even makes it to the command line.

I've tried adding &> foo.txt 2> foo.txt >> foo.txt and all of them cause the output to go where it says except every time it also causes READY....,Listening..., and HELLO to disappear.

How can I direct HELLO to a file, in any way, I don't care if other stuff comes with it, I can cut the other stuff out.

Patrick Cook
  • 251
  • 3
  • 11

2 Answers2

1

Try this:

pocketsphinx_continuous -samprate 48000 -nfft 2048 -hmm \
/usr/local/share/pocketsphinx/model/en-us/en-us -lm 9745.lm -dict 9745.dic \
-inmic yes 2>&1 | tee ./full-output.log | grep -v --line-buffered '^INFO:'

This will log everything to ./full-output.log, but hide any output from the console that begins with INFO:. 2>&1 redirects Standard Error to Standard Output so that all output is forced through the series of pipes, rather than just Standard Output.

If you wanted to hide other lines that do not contain INFO:, you could use | in extended-grep syntax:

egrep -v --line-buffered '^INFO:|^ERROR:'

The --line-buffered option will prevent grep from waiting until the output from pocketsphinx_continuous is completely finished.

Edit

It's also possible that pocketsphinx_continuous is already putting everything you want on Standard Output and everything you don't want on Standard Error. So, you might try just doing:

pocketsphinx_continuous -samprate 48000 -nfft 2048 -hmm \
/usr/local/share/pocketsphinx/model/en-us/en-us -lm 9745.lm -dict 9745.dic \
-inmic yes 2>./unwanted-stuff.log | tee ./words.log

This would log everything coming out on Standard Error to ./unwanted-stuff.log and everything on Standard Output to ./words.log.

Will
  • 2,664
  • 18
  • 26
  • 1
    I'll try this in the morning, thanks for the answer! – Patrick Cook Jan 03 '16 at 08:44
  • No problem! Let me know if you run into issues. – Will Jan 03 '16 at 08:45
  • No dice, still just everything in the command line except for `READY` `Listening....` and `HELLO` nothing showed up in `./full-output.log` – Patrick Cook Jan 03 '16 at 23:13
  • Ok, I think I know what's going on! See my edit to the original command at the top of the post, as well as the alternate solution in my edit at the bottom. This is due to some output being on Standard Output and some being on Standard Error. This has the potential to actually make things easier, if everything we don't want is on Standard Error :) – Will Jan 03 '16 at 23:25
  • Everything except `HELLO` is in `unwanted-stuff.log` but `words.log` is empty. I made sure the command is working by running it without the extra stuff, and the command is working fine. – Patrick Cook Jan 04 '16 at 00:15
  • `full-output.log` contains everything but `HELLO`. I really appreciate all of your help though. – Patrick Cook Jan 04 '16 at 00:18
  • It seems that when anything is added to the end of the command `HELLO` stops being output altogether. – Patrick Cook Jan 04 '16 at 00:22
  • I've found that pocketsphinx ignores stdout as of this question http://stackoverflow.com/questions/30601701/does-pocketsphinx-ignore-stdout Would there be a way to make it not ignore stdout? – Patrick Cook Jan 04 '16 at 00:25
  • Ah, wow, it does indeed! https://stackoverflow.com/questions/31491536/pocketsphinx-capturing-real-time-output-of-inmic-yes-to-txt has a bit more info as well. You can TRY `-logfn - ` or `-logfn /dev/stdout`, but you might have to patch the code as suggested in the post I just linked. But, still, my first approach at the top should work, as `2>&1` redirects `stderr` to `stdout`. – Will Jan 04 '16 at 03:56
  • `-logfn` redirects everything except `HELLO` which might work for me, and your first approach just outputs everything except `HELLO` to the file, and for some reason causes the `HELLO` to stop showing up in the console. – Patrick Cook Jan 04 '16 at 04:02
  • The problem was that pocketsphinx did not flush new results, you can update to latest version to fix it. I still recommend to use bindings instead of spawn the process. – Nikolay Shmyrev Jan 06 '16 at 01:42
0

Nice and clear output:

 pocketsphinx_continuous  -samprate 48000 -nfft 2048 -inmic yes 2>/dev/null

Python module may be a better interface for these class-full objects.

PaSe
  • 11
  • 1