MCPcopy Create free account
hub / github.com/modelscope/FunASR / encode

Method encode

funasr/models/uniasr/model.py:381–409  ·  view source on GitHub ↗

Frontend + Encoder. Note that this method is used by asr_inference.py Args: speech: (Batch, Length, ...) speech_lengths: (Batch, )

(
        self,
        speech: torch.Tensor,
        speech_lengths: torch.Tensor,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

379 return {"feats": feats, "feats_lengths": feats_lengths}
380
381 def encode(
382 self,
383 speech: torch.Tensor,
384 speech_lengths: torch.Tensor,
385 **kwargs,
386 ):
387 """Frontend + Encoder. Note that this method is used by asr_inference.py
388 Args:
389 speech: (Batch, Length, ...)
390 speech_lengths: (Batch, )
391 """
392 ind = kwargs.get("ind", 0)
393 with autocast(False):
394 # Data augmentation
395 if self.specaug is not None and self.training:
396 speech, speech_lengths = self.specaug(speech, speech_lengths)
397
398 # Normalization for feature: e.g. Global-CMVN, Utterance-CMVN
399 if self.normalize is not None:
400 speech, speech_lengths = self.normalize(speech, speech_lengths)
401
402 speech_raw = speech.clone().to(speech.device)
403
404 # 4. Forward encoder
405 encoder_out, encoder_out_lens, _ = self.encoder(speech, speech_lengths, ind=ind)
406 if isinstance(encoder_out, tuple):
407 encoder_out = encoder_out[0]
408
409 return speech_raw, encoder_out, encoder_out_lens
410
411 def encode2(
412 self,

Callers 2

forwardMethod · 0.95
inferenceMethod · 0.95

Calls 2

autocastFunction · 0.90
normalizeMethod · 0.45

Tested by

no test coverage detected