class_docstr: DummyAgent operates in an offline mode.
  Waits until all source is read to run inference.
class_docstr_tok: ["DummyAgent","operates","in","an","offline","mode",".","Waits","until","all","source","is","read","to","run","inference","."]
code: def policy(self):
      # dummy offline policy
      if self.backend == "offline":
          if self.states.source_finished:
              results = self.speech2text(
                  torch.tensor(self.states.source)
              )
              if self.speech2text.st_model.use_multidecoder:
                  prediction = results[0][0][
                      0
                  ]  # multidecoder result is in this format
              else:
                  prediction = results[0][0]
              return WriteAction(prediction, finished=True)
          else:
              return ReadAction()
  
      # streaming policy. takes running beam search hyp as an incremental output
      else:
          unread_length = (
              len(self.states.source) - self.processed_index - 1
          )
          if self.n_chunks > 0:
              chunk_length = self.sim_chunk_length // self.chunk_decay
          else:
              chunk_length = self.sim_chunk_length
  
          if (
              unread_length >= chunk_length
              or self.states.source_finished
          ):
              print("chunk_length:", str(chunk_length))
              self.n_chunks += 1
  
              if self.recompute:
                  speech = torch.tensor(self.states.source)
              else:
                  speech = torch.tensor(
                      self.states.source[self.processed_index + 1 :]
                  )
              try:
                  results = self.speech2text(
                      speech=speech,
                      is_final=self.states.source_finished,
                  )
              except TooShortUttError:
                  print("skipping inference for too short input")
                  results = [[""]]
  
              self.processed_index = len(self.states.source) - 1
              if not self.states.source_finished:
                  if len(results) > 0:
                      prediction = results[0][0]
  
                  elif (
                      self.speech2text.beam_search.running_hyps
                      and len(
                          self.speech2text.beam_search.running_hyps.yseq[
                              0
                          ]
                      )
                      > self.maxlen
                  ):
                      prediction = self.speech2text.beam_search.running_hyps.yseq[
                          0
                      ][
                          1:
                      ]
                      prediction = (
                          self.speech2text.converter.ids2tokens(
                              prediction
                          )
                      )
                      prediction = (
                          self.speech2text.tokenizer.tokens2text(
                              prediction
                          )
                      )
                      self.maxlen = len(
                          self.speech2text.beam_search.running_hyps.yseq[
                              0
                          ]
                      )
                  else:
                      return ReadAction()
              else:
                  if len(results) > 0:
                      prediction = results[0][0]
                  else:
                      prediction = self.prev_prediction
  
              if (
                  prediction != self.prev_prediction
                  or self.states.source_finished
              ):
                  self.prev_prediction = prediction
                  prediction = MosesDetokenizer(self.lang)(
                      prediction.split(" ")
                  )
  
                  if (
                      self.token_delay
                      and not self.states.source_finished
                  ):
                      prediction = prediction.rsplit(" ", 1)
                      if len(prediction) == 1:
                          prediction = ""
                      else:
                          # token delay
                          print("token delay occurred:", prediction[-1])
                          if len(prediction) == 1:
                              prediction = ""
                          else:
                              prediction = prediction[0]
  
                  unwritten_length = len(prediction) - len(
                      "".join(self.states.target)
                  )
              else:
                  unwritten_length = 0
  
              if self.states.source_finished:
                  self.clean()
  
              if unwritten_length > 0:
                  ret = prediction[-unwritten_length:]
                  print(self.processed_index, ret)
                  return WriteAction(
                      ret, finished=self.states.source_finished
                  )
              elif self.states.source_finished:
                  return WriteAction(
                      "", finished=self.states.source_finished
                  )
  
          return ReadAction()
  
file_path: espnet/egs2/lrs3/asr1/pyscripts/utils/simuleval_agent.py
imports: import logging
  import random
  from typing import Any, List, Optional, Sequence, Tuple, Union
  import torch
  from mosestokenizer import MosesDetokenizer
  from simuleval.agents import SpeechToTextAgent
  from simuleval.agents.actions import ReadAction, WriteAction
  from simuleval.utils import entrypoint
  from espnet2.bin.st_inference import Speech2Text
  from espnet2.bin.st_inference_streaming import Speech2TextStreaming
  from espnet2.torch_utils.set_all_random_seed import set_all_random_seed
  from espnet2.utils.types import str2bool, str2triple_str, str_or_none
label_desc: Use image node_id 4 for calling the DummyAgent obj's underlying member method code with example usage: obj.policy() and returns: ReadAction, WriteAction, ReadAction, WriteAction, WriteAction, ReadAction