espnet3.systems.esp2_codec.src.inference_runner.CodecInferenceRunner
espnet3.systems.esp2_codec.src.inference_runner.CodecInferenceRunner
class espnet3.systems.esp2_codec.src.inference_runner.CodecInferenceRunner(provider: EnvironmentProvider, idx_key: str = 'utt_id', hyp_key: str | Sequence[str] = 'hyp', ref_key: str | Sequence[str] = 'ref', **kwargs)
Bases: InferenceRunner
Run espnet2.bin.gan_codec_inference.AudioCoding under the contract.
The contract hands the runner an Audio for speech; the backend takes the bare waveform as audio. The backend returns codes and resyn_audio; the contract declares one output, wav, so only the resynthesized waveform is kept, as a 1-D float32 array that the declared sample_rate of contract.outputs.wav turns into an Audio.
AudioCoding encodes one waveform per call, so the recipe runs with batch_size: null; a batched call is refused rather than mis-decoded.
######### Examples
>>> import torch
>>> CodecInferenceRunner.format_output(
... {"codes": torch.zeros(1, 2, 3), "resyn_audio": torch.zeros(4)},
... batched=False,
... )["wav"].shape
(4,)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)
Keep the resynthesized waveform as the declared wav output.
- Parameters:
- result – What
AudioCodingreturned: a mapping holdingresyn_audio(andcodes). - batched – Whether the call was a batch.
- result – What
- Returns:
{"wav": <1-D float32 array>}. - Raises:
- ValueError – If the call was batched.
- TypeError – If
resultis not a mapping. - KeyError – If
resulthas noresyn_audio.
######### Examples
>>> import torch
>>> out = CodecInferenceRunner.format_output(
... {"resyn_audio": torch.zeros(1, 240)}, batched=False
... )
>>> out["wav"].shape, out["wav"].dtype
((240,), dtype('float32'))static prepare_model_inputs(inputs)
Hand the backend the waveform of the checked speech as audio.
- Parameters:inputs – The backend’s keyword arguments;
speechholds theAudiothe contract produced. - Returns: A copy of
inputswithoutspeechand withaudio, the bare 1-D float32 waveform, which is the keywordAudioCoding.__call__takes. - Raises:ValueError – If
speechis a list, that is, the call is batched.
######### Examples
>>> speech = Audio(np.zeros(240, dtype=np.float32), 24000)
>>> out = CodecInferenceRunner.prepare_model_inputs({"speech": speech})
>>> sorted(out), out["audio"].shape
(['audio'], (240,))