Testing API

Public API for model testing and evaluation operations.

pstrain.api.testing.check_pocketsphinx()[source]

Check if PocketSphinx is available.

Returns:

Tuple of (available, message)

Return type:

tuple[bool, str]

pstrain.api.testing.create_report(result, title=None, corpus_name='', test_set_name='')[source]

Create a test report from a TestResult.

Parameters:
  • result (TestResult) – TestResult from test_model()

  • title (str | None) – Report title (default: auto-generated)

  • corpus_name (str) – Name of the corpus tested on

  • test_set_name (str) – Name of the test set

Returns:

TestReport instance

Return type:

TestReport

pstrain.api.testing.load_transcripts(transcript_file)[source]

Load transcripts from a Sphinx-format transcription file.

Format: <s> word word word </s> (utterance_id)

Parameters:

transcript_file (Path) – Path to transcription file

Returns:

Dict mapping utterance_id to transcript text

Return type:

dict[str, str]

pstrain.api.testing.test_model(model_dir, test_audio_dir, test_transcripts, dict_file, filler_dict=None, lm=None, verbose=False, compute_cer=False, jobs=None)[source]

Test an acoustic model and calculate all WER metrics.

Parameters:
  • model_dir (Path) – Path to acoustic model directory

  • test_audio_dir (Path) – Directory containing test audio files

  • test_transcripts (dict[str, str]) – Dict mapping utterance_id to reference transcript

  • dict_file (Path) – Path to pronunciation dictionary

  • filler_dict (Path | None) – Optional filler dictionary

  • lm (Path | None) – Optional language model (ARPA format)

  • verbose (bool) – Store per-utterance results

  • compute_cer (bool) – Also compute Character Error Rate

  • jobs (int | None) – Decoder worker processes. None auto-selects up to 12.

Returns:

TestResult with all jiwer metrics

Raises:
Return type:

TestResult