espnet3.systems.esp2_st.src.inference_runner.ESP2STInferenceRunner
About 1 min
espnet3.systems.esp2_st.src.inference_runner.ESP2STInferenceRunner
class espnet3.systems.esp2_st.src.inference_runner.ESP2STInferenceRunner(provider: EnvironmentProvider, idx_key: str = 'utt_id', hyp_key: str | Sequence[str] = 'hyp', ref_key: str | Sequence[str] = 'ref', **kwargs)
Bases: InferenceRunner
Adapt espnet2.bin.st_inference.Speech2Text to the contract.
Two departures from the default runner, both forced by that backend:
- it is
@typecheckedon a singlespeecharray and has nobatch_decode, so a list cannot be passed at all; - a multi-decoder model returns
(translations, transcripts)rather than one n-best list, and only the translation is this system’s output.
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)
Return the best translation as the contracted text field.
- Parameters:
- result – What
Speech2Textreturned: an n-best list of(text, token, token_int, hyp), or(translations, transcripts)for a multi-decoder model. - batched – Whether the call was a batch; always false here, since
prepare_model_inputs()refuses one.
- result – What
- Returns:
{"text": str}.Speech2Textleaves the textNonewhen it has no tokenizer, which is an empty string here.
####### Examples
>>> result = [("hallo welt", ["hallo"], [1], None)]
>>> ESP2STInferenceRunner.format_output(result, batched=False)
{'text': 'hallo welt'}static prepare_model_inputs(inputs)
Hand the backend the waveform it takes, rejecting a batch.
- Parameters:inputs – The backend’s keyword arguments;
speechholds anAudio. - Returns: A copy of
inputswhosespeechis the sample array. - Raises:ValueError – If
speechis a list, i.e. the stage was configured with a batch size. This runs beforeformat_output, so the batch is refused here with a message naming the setting rather than inside ESPnet2’s type check.
####### Examples
>>> import numpy as np
>>> audio = Audio(np.zeros(8000, dtype=np.float32), 16000)
>>> out = ESP2STInferenceRunner.prepare_model_inputs(
... {"speech": audio}
... )
>>> out["speech"].shape
(8000,)