Skip to content

Add a stream_reset option to pocketsphinx_batch - #495

Open
lenzo-ka wants to merge 1 commit into
cmusphinx:mainfrom
lenzo-ka:batch_stream_reset
Open

Add a stream_reset option to pocketsphinx_batch#495
lenzo-ka wants to merge 1 commit into
cmusphinx:mainfrom
lenzo-ka:batch_stream_reset

Conversation

@lenzo-ka

@lenzo-ka lenzo-ka commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

With noise removal enabled, pocketsphinx_batch results depend on control-file order. One shared decoder processes every entry, and the spectral-subtraction noise estimate persists across entries: ps_start_utt() does not reset it, only ps_start_stream() does, and the batch tool never called it. Retaining the estimate is correct when a control file addresses segments of one continuous recording; batch entries are, however, routinely independent recordings, and the tool offered no way to choose.

Measured at v5.1.1 with the shipped en-us model (its feat.params enables noise removal; the effective configuration was confirmed in the run log) and shipped test audio, all through pocketsphinx_batch itself:

Listing goforward.raw twice in one control file, with other audio between, reports two different scores for identical input in a single run:

uttid score
gof_first -7226
gof_again -7407

Reversing a three-entry control file changes every score:

uttid forward reverse
gof -7226 -7324
num -10503 -10534
som -6391 -6199

Hypothesis strings did not change in these runs; the observed effect is score movement.

The new stream_reset option (default no, preserving current behavior) calls ps_start_stream() before each control-file entry when noise removal is effectively enabled. With -stream_reset yes, both constructions above produce identical per-utterance output regardless of position or order (gof -7226, num -10545, som -6199 in both orders).

The reset covers exactly the state ps_start_stream() controls: the noise-removal statistics. It does not make sample dithering position-independent — with -dither yes, dithering draws from a process-wide random sequence whose position depends on preceding audio, so entries can still differ by a few counts even with the reset. The measurements above were made with the en-us configuration, in which dithering is off (the config default; the model's feat.params does not enable it).

On the default: entries that name separate files carry an implicit independence claim, and order dependence violates it, so a case can be made for resetting by default in that mode, while control files that segment one continuous recording want retention. This patch keeps current behavior as the default and adds the choice; whether to flip the default is left to the maintainers.

The option is also listed in the pocketsphinx_batch manual page. The regression test test-batch-stream-reset.sh decodes a control file that lists the same recording twice under -stream_reset yes and asserts the repeated entries report identical hypothesis and score. The script asserts the tool run's exit status and removes any stale output first; it fails when the reset is not performed, and it uses only fixtures already shipped in the repository.

Fixes #498

Tested on macOS (Apple clang) and Linux x86-64 (GCC 13.3); full unit and regression suite passes on both.

With noise removal enabled, batch results depend on control-file
order: one shared decoder processes every entry, and the
spectral-subtraction noise estimate persists across entries because
ps_start_utt() does not reset it. Only ps_start_stream() resets it,
and the batch tool never called it. Retention is correct when a
control file addresses segments of one continuous recording, but
batch entries are routinely independent recordings, and the tool
offered no way to choose. The same audio file listed twice in one
control file can report two different scores in a single run.

The new stream_reset option (default no, preserving current
behavior) calls ps_start_stream() before each control-file entry
when noise removal is effectively enabled.

test-batch-stream-reset.sh decodes a control file that lists the
same recording twice, with other audio between, under
-stream_reset yes, and asserts the repeated entries report
identical hypothesis and score. It fails when the reset is not
performed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

pocketsphinx_batch scores depend on control-file order when noise removal is enabled

1 participant