Encode chunk. Args: speech: Speech audio tensor, shape (batch, time). speech_lengths: Length of each speech sample. cache: State cache dict for streaming inference. **kwargs: Additional keyword arguments.
(
self,
speech: torch.Tensor,
speech_lengths: torch.Tensor,
cache: dict = None,
**kwargs,
)
| 304 | return encoder_out, encoder_out_lens |
| 305 | |
| 306 | def encode_chunk( |
| 307 | self, |
| 308 | speech: torch.Tensor, |
| 309 | speech_lengths: torch.Tensor, |
| 310 | cache: dict = None, |
| 311 | **kwargs, |
| 312 | ) -> Tuple[torch.Tensor, torch.Tensor]: |
| 313 | """Encode chunk. |
| 314 | |
| 315 | Args: |
| 316 | speech: Speech audio tensor, shape (batch, time). |
| 317 | speech_lengths: Length of each speech sample. |
| 318 | cache: State cache dict for streaming inference. |
| 319 | **kwargs: Additional keyword arguments. |
| 320 | """ |
| 321 | if cache is None: |
| 322 | cache = {} |
| 323 | """Frontend + Encoder. Note that this method is used by asr_inference.py |
| 324 | Args: |
| 325 | speech: (Batch, Length, ...) |
| 326 | speech_lengths: (Batch, ) |
| 327 | ind: int |
| 328 | """ |
| 329 | with autocast(False): |
| 330 | |
| 331 | # Data augmentation |
| 332 | if self.specaug is not None and self.training: |
| 333 | speech, speech_lengths = self.specaug(speech, speech_lengths) |
| 334 | |
| 335 | # Normalization for feature: e.g. Global-CMVN, Utterance-CMVN |
| 336 | if self.normalize is not None: |
| 337 | speech, speech_lengths = self.normalize(speech, speech_lengths) |
| 338 | |
| 339 | # Forward encoder |
| 340 | encoder_out, encoder_out_lens, _ = self.encoder.forward_chunk( |
| 341 | speech, speech_lengths, cache=cache["encoder"] |
| 342 | ) |
| 343 | if isinstance(encoder_out, tuple): |
| 344 | encoder_out = encoder_out[0] |
| 345 | |
| 346 | return encoder_out, torch.tensor([encoder_out.size(1)]) |
| 347 | |
| 348 | def calc_predictor_chunk(self, encoder_out, encoder_out_lens, cache=None, **kwargs): |
| 349 | """Calc predictor chunk. |
no test coverage detected