Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pocketsphinx: Capturing real-time output of -inmic yes to .txt

I'm using pocketsphinx_continuous on Windows. Redirecting output to a text file works with the "-infile" argument, but fails with "-inmic yes".

As noted in the question Does pocketsphinx flush stdout? pocketsphinx ignores stdout (at least when using -inmic).

Is there any way I can save the words recognized by pocketsphinx_continuous with "-inmic yes" to a text file?

Specifically, I want my Java program to run pocketsphinx_continuous.exe and get the words recognized from microphone input.

Solution

Using -backtrace with -logfn as suggested by Alexander Solovets indeed saves the results along with the log in the specified file. However, the log is not saved as frequently as the results are sent to the terminal. I wanted the results output to a file as fast as possible, so I built pocketsphinx_continuous.exe from source with the following changes to continous.c.

In continuous.c:

hyp = ps_get_hyp(ps, NULL );
if (hyp != NULL)
{
    printf("%s\n", hyp);
    FILE * fp;
    fp = fopen("file.txt", "a+");
    fprintf(fp, hyp);
    fprintf(fp, "\r\n");
    fclose(fp);
}
like image 560
sjw Avatar asked Jul 18 '15 13:07

sjw


2 Answers

There is no dedicated option to save only results to a file. However, you can use -backtrace to tell pocketsphinx to save results and backtraces to the log file, which you can specify with -logfn.

like image 115
Alexander Solovets Avatar answered Dec 28 '22 08:12

Alexander Solovets


Since revision 13156 pocketsphinx should flush stdout on every message thus interactive applications should work.

You can update your version.

like image 20
Nikolay Shmyrev Avatar answered Dec 28 '22 07:12

Nikolay Shmyrev