espnet3.systems.esp2_asr.inference.ASRInferenceRunner
About 1 min
espnet3.systems.esp2_asr.inference.ASRInferenceRunner
class espnet3.systems.esp2_asr.inference.ASRInferenceRunner(provider: EnvironmentProvider, idx_key: str = 'utt_id', hyp_key: str | Sequence[str] = 'hyp', ref_key: str | Sequence[str] = 'ref', **kwargs)
Bases: InferenceRunner
Convert ESPnet2 ASR n-best results to the contracted text field.
Initialize the inference runner with output key settings.
- Parameters:
- provider – Environment provider that supplies dataset/model/env.
- idx_key – Output dict key used as the sample identifier written in the first column of each SCP line. This ties each inference result back to its dataset sample. Defaults to
"utt_id". - hyp_key – Hypothesis key or keys expected in the output dict.
- ref_key – Reference key or keys expected in the output dict.
- **kwargs – Forwarded to
BaseRunner.
static format_output(result, , batched)
Format best text hypotheses before the shared contract checks.
- Parameters:
- result – The n-best results of
Speech2Text(a list of them for a batch). - batched – Whether the call was a batch.
- result – The n-best results of
- Returns:
{"text": ...}for one call, or a list of them for a batch.
####### Examples
>>> result = [("hello", ["h"], [1], None)]
>>> ASRInferenceRunner.format_output(result, batched=False)
{'text': 'hello'}static prepare_model_inputs(inputs)
Pass all channels to ESPnet2 in its samples-first array layout.
- Parameters:inputs – The backend’s keyword arguments;
speechholds anAudio(a list of them for a batch). - Returns: A copy of
inputswhosespeechis a(samples, channels)array for stereo audio, or a 1-D array for mono.
####### Examples
>>> import numpy as np
>>> audio = Audio(np.zeros((2, 8000), dtype=np.float32), 16000)
>>> out = ASRInferenceRunner.prepare_model_inputs({"speech": audio})
>>> out["speech"].shape
(8000, 2)