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);
}