code: def perform_streaming(
      asr_model,
      streaming_buffer,
      compare_vs_offline=False,
      debug_mode=False,
      pad_and_drop_preencoded=False,
  ):
      batch_size = len(streaming_buffer.streams_length)
      if compare_vs_offline:
          # would pass the whole audio at once through the model like offline mode in order to compare the results with the stremaing mode
          # the output of the model in the offline and streaming mode should be exactly the same
          with torch.inference_mode():
              with autocast():
                  (
                      processed_signal,
                      processed_signal_length,
                  ) = streaming_buffer.get_all_audios()
                  with torch.no_grad():
                      (
                          pred_out_offline,
                          transcribed_texts,
                          cache_last_channel_next,
                          cache_last_time_next,
                          cache_last_channel_len,
                          best_hyp,
                      ) = asr_model.conformer_stream_step(
                          processed_signal=processed_signal,
                          processed_signal_length=processed_signal_length,
                          return_transcription=True,
                      )
          final_offline_tran = extract_transcriptions(transcribed_texts)
          logging.info(
              f" Final offline transcriptions:   {final_offline_tran}"
          )
      else:
          final_offline_tran = None
  
      (
          cache_last_channel,
          cache_last_time,
          cache_last_channel_len,
      ) = asr_model.encoder.get_initial_cache_state(
          batch_size=batch_size
      )
  
      previous_hypotheses = None
      streaming_buffer_iter = iter(streaming_buffer)
      pred_out_stream = None
      for step_num, (chunk_audio, chunk_lengths) in enumerate(
          streaming_buffer_iter
      ):
          with torch.inference_mode():
              with autocast():
                  # keep_all_outputs needs to be True for the last step of streaming when model is trained with att_context_style=regular
                  # otherwise the last outputs would get dropped
  
                  with torch.no_grad():
                      (
                          pred_out_stream,
                          transcribed_texts,
                          cache_last_channel,
                          cache_last_time,
                          cache_last_channel_len,
                          previous_hypotheses,
                      ) = asr_model.conformer_stream_step(
                          processed_signal=chunk_audio,
                          processed_signal_length=chunk_lengths,
                          cache_last_channel=cache_last_channel,
                          cache_last_time=cache_last_time,
                          cache_last_channel_len=cache_last_channel_len,
                          keep_all_outputs=streaming_buffer.is_buffer_empty(),
                          previous_hypotheses=previous_hypotheses,
                          previous_pred_out=pred_out_stream,
                          drop_extra_pre_encoded=calc_drop_extra_pre_encoded(
                              asr_model,
                              step_num,
                              pad_and_drop_preencoded,
                          ),
                          return_transcription=True,
                      )
  
          if debug_mode:
              logging.info(
                  f"Streaming transcriptions: {extract_transcriptions(transcribed_texts)}"
              )
  
      final_streaming_tran = extract_transcriptions(transcribed_texts)
      logging.info(
          f"Final streaming transcriptions: {final_streaming_tran}"
      )
  
      if compare_vs_offline:
          # calculates and report the differences between the predictions of the model in offline mode vs streaming mode
          # Normally they should be exactly the same predictions for streaming models
          pred_out_stream_cat = torch.cat(pred_out_stream)
          pred_out_offline_cat = torch.cat(pred_out_offline)
          if pred_out_stream_cat.size() == pred_out_offline_cat.size():
              diff_num = (
                  torch.sum(pred_out_stream_cat != pred_out_offline_cat)
                  .cpu()
                  .numpy()
              )
              logging.info(
                  f"Found {diff_num} differences in the outputs of the model in streaming mode vs offline mode."
              )
          else:
              logging.info(
                  f"The shape of the outputs of the model in streaming mode ({pred_out_stream_cat.size()}) is different from offline mode ({pred_out_offline_cat.size()})."
              )
  
      return final_streaming_tran, final_offline_tran
  
file_path: NeMo/examples/asr/asr_cache_aware_streaming/speech_to_text_cache_aware_streaming_infer.py
imports: import contextlib
  import json
  import os
  import time
  from argparse import ArgumentParser
  import torch
  from omegaconf import open_dict
  import nemo.collections.asr
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.parts.utils.rnnt_utils import Hypothesis
  from nemo.collections.asr.parts.utils.streaming_utils import CacheAwareStreamingAudioBuffer
  from nemo.utils import logging
label_desc: Use image node_id 3 for calling a global function with example usage: perform_streaming(asr_model, streaming_buffer, compare_vs_offline, debug_mode, pad_and_drop_preencoded) and returns: final_streaming_tran,  final_offline_tran