code: def generate_vad_frame_pred(
      vad_model: EncDecClassificationModel,
      window_length_in_sec: float,
      shift_length_in_sec: float,
      manifest_vad_input: str,
      out_dir: str,
      use_feat: bool = False,
      record_fn: Callable = None,
  ) -> str:
      """
      Generate VAD frame level prediction and write to out_dir
      """
      time_unit = int(window_length_in_sec / shift_length_in_sec)
      trunc = int(time_unit / 2)
      trunc_l = time_unit - trunc
      all_len = 0
  
      data = []
      with open(manifest_vad_input, "r", encoding="utf-8") as fin:
          for line in fin.readlines():
              file = json.loads(line)["audio_filepath"].split("/")[-1]
              data.append(file.split(".wav")[0])
      logging.info(f"Inference on {len(data)} audio files/json lines!")
  
      status = get_vad_stream_status(data)
  
      with record_fn("vad_infer_loop"):
          for i, test_batch in enumerate(
              tqdm(
                  vad_model.test_dataloader(),
                  total=len(vad_model.test_dataloader()),
              )
          ):
              test_batch = [x.to(vad_model.device) for x in test_batch]
              with autocast():
                  with record_fn("vad_infer_model"):
                      if use_feat:
                          log_probs = vad_model(
                              processed_signal=test_batch[0],
                              processed_signal_length=test_batch[1],
                          )
                      else:
                          log_probs = vad_model(
                              input_signal=test_batch[0],
                              input_signal_length=test_batch[1],
                          )
  
                  with record_fn("vad_infer_other"):
                      probs = torch.softmax(log_probs, dim=-1)
                      if len(probs.shape) == 3:
                          # squeeze the batch dimension, since batch size is 1
                          probs = probs.squeeze(0)  # [1,T,C] -> [T,C]
                      pred = probs[:, 1]
  
                      if window_length_in_sec == 0:
                          to_save = pred
                      elif status[i] == "start":
                          to_save = pred[:-trunc]
                      elif status[i] == "next":
                          to_save = pred[trunc:-trunc_l]
                      elif status[i] == "end":
                          to_save = pred[trunc_l:]
                      else:
                          to_save = pred
  
                      to_save = to_save.cpu().tolist()
                      all_len += len(to_save)
  
                      outpath = os.path.join(
                          out_dir, data[i] + ".frame"
                      )
                      with open(outpath, "a", encoding="utf-8") as fout:
                          for p in to_save:
                              fout.write(f"{p:0.4f}\n")
  
                      del test_batch
                      if status[i] == "end" or status[i] == "single":
                          all_len = 0
      return out_dir
  
imports: import contextlib
  import json
  import os
  import time
  from dataclasses import dataclass, is_dataclass
  from pathlib import Path
  from typing import Callable, Optional
  import torch
  import yaml
  from omegaconf import DictConfig, OmegaConf
  from torch.profiler import ProfilerActivity, profile, record_function
  from tqdm import tqdm
  from nemo.collections.asr.data import feature_to_text_dataset
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.models import ASRModel, EncDecClassificationModel
  from nemo.collections.asr.parts.submodules import CTCDecodingConfig
  from nemo.collections.asr.parts.submodules.rnnt_decoding import RNNTDecodingConfig
  from nemo.collections.asr.parts.utils.manifest_utils import read_manifest, write_manifest
  from nemo.collections.asr.parts.utils.vad_utils import generate_overlap_vad_seq, generate_vad_segment_table, get_vad_stream_status, init_frame_vad_model, init_vad_model
  from nemo.core.config import hydra_runner
  from nemo.utils import logging
label_desc: Use image node_id 5 for calling a global function with example usage: generate_vad_frame_pred(vad_model, window_length_in_sec, shift_length_in_sec, manifest_vad_input, out_dir, use_feat, record_fn) and returns: out_dir