class_docstr: Speech2Text class
  
  Examples:
      >>> import soundfile
      >>> speech2text = Speech2Text("st_config.yml", "st.pth")
      >>> audio, rate = soundfile.read("speech.wav")
      >>> speech2text(audio)
      [(text, token, token_int, hypothesis object), ...]
class_docstr_tok: ["Speech2Text","class","Examples",":",">",">",">","import","soundfile",">",">",">","speech2text","=","Speech2Text","(","``","st_config.yml","''",",","``","st.pth","''",")",">",">",">","audio",",","rate","=","soundfile.read","(","``","speech.wav","''",")",">",">",">","speech2text","(","audio",")","[","(","text",",","token",",","token_int",",","hypothesis","object",")",",","...","]"]
docstr: Inference
  
  Args:
      data: Input speech data
  Returns:
      text, token, token_int, hyp
docstr_tok: ["Inference","Args",":","data",":","Input","speech","data","Returns",":","text",",","token",",","token_int",",","hyp"]
code: def __call__(
      self, speech: Union[torch.Tensor, np.ndarray]
  ) -> List[
      Tuple[
          Optional[str],
          List[str],
          List[int],
          Union[Hypothesis, TransHypothesis],
      ]
  ]:
      """Inference
  
      Args:
          data: Input speech data
      Returns:
          text, token, token_int, hyp
  
      """
      assert check_argument_types()
  
      # Input as audio signal
      if isinstance(speech, np.ndarray):
          speech = torch.tensor(speech)
  
      # data: (Nsamples,) -> (1, Nsamples)
      speech = speech.unsqueeze(0).to(getattr(torch, self.dtype))
      # lengths: (1,)
      lengths = speech.new_full(
          [1], dtype=torch.long, fill_value=speech.size(1)
      )
      batch = {"speech": speech, "speech_lengths": lengths}
  
      # a. To device
      batch = to_device(batch, device=self.device)
  
      # b. Forward Encoder
      enc, _, asr_enc, _ = self.st_model.encode(
          **batch, return_int_enc=True
      )
      assert len(enc) == 1, len(enc)
      x = enc[0]
  
      # Multi-decoder ASR beam search
      if self.st_model.use_multidecoder:
          asr_nbest_hyps = self.asr_beam_search(
              x=asr_enc[0],
              maxlenratio=self.asr_maxlenratio,
              minlenratio=self.asr_minlenratio,
          )
  
          asr_results = []
          for hyp in asr_nbest_hyps:
              assert isinstance(hyp, Hypothesis), type(hyp)
  
              # remove sos/eos and get results
              if isinstance(hyp.hs, List):
                  asr_hs = torch.stack(hyp.hs)
              else:
                  asr_hs = hyp.hs
  
              src_token_int = hyp.yseq.tolist()
              src_token_int = list(
                  filter(
                      lambda x: x != self.st_model.src_sos,
                      src_token_int,
                  )
              )
              src_token_int = list(
                  filter(
                      lambda x: x != self.st_model.src_eos,
                      src_token_int,
                  )
              )
  
              # remove blank symbol id, which is assumed to be 0
              src_token_int = list(
                  filter(lambda x: x != 0, src_token_int)
              )
  
              # Change integer-ids to tokens
              src_token = self.src_converter.ids2tokens(src_token_int)
  
              if self.src_tokenizer is not None:
                  src_hyp_text = self.src_tokenizer.tokens2text(
                      src_token
                  )
              else:
                  src_hyp_text = None
              asr_results.append(
                  (src_hyp_text, src_token, src_token_int, hyp, asr_hs)
              )
  
          # Encode 1 best ASR result
          asr_hs = asr_results[0][-1].unsqueeze(0)
          asr_hs = to_device(asr_hs, device=self.device)
          asr_hs_lengths = asr_hs.new_full(
              [1], dtype=torch.long, fill_value=asr_hs.size(1)
          )
          md_enc, _, _ = self.st_model.md_encoder(
              asr_hs, asr_hs_lengths
          )
          x = md_enc[0]
          pre_x = enc[0]
  
      # c. Passed the encoder result and the beam search
      if self.ctc_greedy:
          from itertools import groupby
  
          lpz = self.st_model.st_ctc.argmax(enc)
          collapsed_indices = [x[0] for x in groupby(lpz[0])]
          hyp = [x for x in filter(lambda x: x != 0, collapsed_indices)]
          nbest_hyps = [
              {
                  "score": 0.0,
                  "yseq": [self.st_model.sos]
                  + hyp
                  + [self.st_model.eos],
              }
          ]
          nbest_hyps = [
              Hypothesis(
                  score=hyp["score"],
                  yseq=torch.tensor(hyp["yseq"]),
              )
              for hyp in nbest_hyps
          ]
      elif (
          self.st_model.use_multidecoder
          and self.st_model.use_speech_attn
      ):
          nbest_hyps = self.beam_search(
              x=x,
              maxlenratio=self.maxlenratio,
              minlenratio=self.minlenratio,
              pre_x=pre_x,
          )
      elif self.beam_search_transducer:
          logging.info("encoder output length: " + str(x.shape[0]))
          nbest_hyps = self.beam_search_transducer(x)
  
          best = nbest_hyps[0]
          logging.info(f"total log probability: {best.score:.2f}")
          logging.info(
              f"normalized log probability: {best.score / len(best.yseq):.2f}"
          )
          logging.info(
              "best hypo: "
              + "".join(self.converter.ids2tokens(best.yseq[1:]))
              + "\n"
          )
      else:
          nbest_hyps = self.beam_search(
              x=x,
              maxlenratio=self.maxlenratio,
              minlenratio=self.minlenratio,
          )
      nbest_hyps = nbest_hyps[: self.nbest]
  
      results = []
      for hyp in nbest_hyps:
          assert isinstance(hyp, (Hypothesis, TransHypothesis)), type(
              hyp
          )
  
          # remove sos/eos and get results
          last_pos = (
              None if self.st_model.st_use_transducer_decoder else -1
          )
          if isinstance(hyp.yseq, list):
              token_int = hyp.yseq[1:last_pos]
          else:
              token_int = hyp.yseq[1:last_pos].tolist()
  
          # remove blank symbol id, which is assumed to be 0
          token_int = list(filter(lambda x: x != 0, token_int))
  
          # Change integer-ids to tokens
          token = self.converter.ids2tokens(token_int)
  
          if self.tokenizer is not None:
              text = self.tokenizer.tokens2text(token)
          else:
              text = None
          results.append((text, token, token_int, hyp))
  
      if self.st_model.use_multidecoder:
          return (results, asr_results)
      assert check_return_type(results)
      return results
  
imports: import argparse
  import logging
  import sys
  from pathlib import Path
  from typing import Any, List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  from typeguard import check_argument_types, check_return_type
  from espnet2.asr.transducer.beam_search_transducer import BeamSearchTransducer
  from espnet2.asr.transducer.beam_search_transducer import Hypothesis
  from espnet2.fileio.datadir_writer import DatadirWriter
  from espnet2.tasks.enh_s2t import EnhS2TTask
  from espnet2.tasks.lm import LMTask
  from espnet2.tasks.st import STTask
  from espnet2.text.build_tokenizer import build_tokenizer
  from espnet2.text.token_id_converter import TokenIDConverter
  from espnet2.text.whisper_token_id_converter import OpenAIWhisperTokenIDConverter
  from espnet2.torch_utils.device_funcs import to_device
  from espnet2.torch_utils.set_all_random_seed import set_all_random_seed
  from espnet2.utils import config_argparse
  from espnet2.utils.types import str2bool, str2triple_str, str_or_none
  from espnet.nets.batch_beam_search import BatchBeamSearch
  from espnet.nets.beam_search import BeamSearch, Hypothesis
  from espnet.nets.pytorch_backend.transformer.subsampling import TooShortUttError
  from espnet.nets.scorer_interface import BatchScorerInterface
  from espnet.nets.scorers.ctc import CTCPrefixScorer
  from espnet.nets.scorers.length_bonus import LengthBonus
  from espnet.utils.cli_utils import get_commandline_args
label_desc: Use image node_id 2 for calling the Speech2Text obj's underlying member method code with example usage: obj.__call__(speech) and returns: results, results,  asr_results