We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
vad_infer.py script fails with `IndexError` if option `--dont_auto_split` is not set
**Describe the bug**

`NeMo/examples/asr/vad_infer.py` script fails with `IndexError` if option `--dont_auto_split` is not set and at least 1 `.wav` file is long enough so that `nemo.collections.asr.parts.utils.vad_utils.prepare_manifest()` function split the `.wav` file.

**Steps/Code to reproduce bug**

```
mkdir -p ~/debug_data
wget http://i13pc106.ira.uka.de/~jniehues/IWSLT-SLT/data/eval/en-de/IWSLT-SLT.tst2019.en-de.tgz -O ~/debug_data/IWSLT-SLT.tst2019.en-de.tgz
tar xzf ~/debug_data/IWSLT-SLT.tst2019.en-de.tgz -C ~/debug_data/
cd ~/NeMo/examples/asr/
wget https://raw.githubusercontent.com/NVIDIA/NeMo/feat/asr/iwslt_audio_to_nemo_format/scripts/dataset_processing/prepare_iwslt_audio_data.py
python prepare_iwslt_audio_data.py -a ~/debug_data/IWSLT.tst2019/wavs/ -t ~/debug_data/IWSLT.tst2019/IWSLT.TED.tst2019.en-de.en.xml -o ~/debug_data/IWSLT.tst2019/manifest.json
python vad_infer.py --dataset ~/debug_data/IWSLT.tst2019/manifest.json --out_dir ~/debug_data/IWSLT.tst2019/vad --vad_model vad_marblenet
```


**Expected behavior**

No errors

**Environment overview (please complete the following information)**

 - Environment location: Bare-metal
 - Method of NeMo install: pip install nemo_toolkit[all]

**Environment details**

If NVIDIA docker image is used you don't need to specify these.
Otherwise, please provide:
- OS version: Ubuntu 20.04.2 LTS
- PyTorch version: 1.8.1
- Python version: 3.8.10



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `examples/asr/vad_infer.py`
Content:
```
1 # Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """
16 During inference, we perform frame-level prediction by two approaches: 
17     1) shift the window of length time_length (e.g. 0.63s) by shift_length (e.g. 10ms) to generate the frame and use the prediction of the window to represent the label for the frame;
18        [this script demonstrate how to do this approach]
19     2) generate predictions with overlapping input segments. Then a smoothing filter is applied to decide the label for a frame spanned by multiple segments. 
20        [get frame level prediction by this script and use vad_overlap_posterior.py in NeMo/scripts/voice_activity_detection
21        One can also find posterior about converting frame level prediction 
22        to speech/no-speech segment in start and end times format in that script.]
23        
24        Image https://raw.githubusercontent.com/NVIDIA/NeMo/main/tutorials/asr/images/vad_post_overlap_diagram.png 
25        will help you understand this method.
26    
27 Usage:
28 python vad_infer.py  --vad_model="vad_marblenet" --dataset=<FULL PATH OF MANIFEST TO BE PERFORMED INFERENCE ON> --out_dir='frame/demo' --time_length=0.63
29 
30 """
31 
32 
33 import json
34 import logging
35 import os
36 from argparse import ArgumentParser
37 
38 import torch
39 
40 from nemo.collections.asr.models import EncDecClassificationModel
41 from nemo.collections.asr.parts.utils.vad_utils import get_vad_stream_status, prepare_manifest
42 from nemo.utils import logging
43 
44 try:
45     from torch.cuda.amp import autocast
46 except ImportError:
47     from contextlib import contextmanager
48 
49     @contextmanager
50     def autocast(enabled=None):
51         yield
52 
53 
54 device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
55 
56 
57 def main():
58     parser = ArgumentParser()
59     parser.add_argument(
60         "--vad_model", type=str, default="MatchboxNet-VAD-3x2", required=False, help="Pass: 'MatchboxNet-VAD-3x2'"
61     )
62     parser.add_argument(
63         "--dataset",
64         type=str,
65         required=True,
66         help="Path of json file of evaluation data. Audio files should have unique names.",
67     )
68     parser.add_argument("--out_dir", type=str, default="vad_frame", help="Dir of your vad outputs")
69     parser.add_argument("--time_length", type=float, default=0.63)
70     parser.add_argument("--shift_length", type=float, default=0.01)
71     parser.add_argument("--normalize_audio", type=bool, default=False)
72     parser.add_argument("--num_workers", type=float, default=20)
73     parser.add_argument("--split_duration", type=float, default=400)
74     parser.add_argument(
75         "--dont_auto_split",
76         default=False,
77         action='store_true',
78         help="Whether to automatically split manifest entry by split_duration to avoid potential CUDA out of memory issue.",
79     )
80 
81     args = parser.parse_args()
82 
83     torch.set_grad_enabled(False)
84 
85     if args.vad_model.endswith('.nemo'):
86         logging.info(f"Using local VAD model from {args.vad_model}")
87         vad_model = EncDecClassificationModel.restore_from(restore_path=args.vad_model)
88     else:
89         logging.info(f"Using NGC cloud VAD model {args.vad_model}")
90         vad_model = EncDecClassificationModel.from_pretrained(model_name=args.vad_model)
91 
92     if not os.path.exists(args.out_dir):
93         os.mkdir(args.out_dir)
94 
95     # Prepare manifest for streaming VAD
96     manifest_vad_input = args.dataset
97     if not args.dont_auto_split:
98         logging.info("Split long audio file to avoid CUDA memory issue")
99         logging.debug("Try smaller split_duration if you still have CUDA memory issue")
100         config = {
101             'manifest_filepath': manifest_vad_input,
102             'time_length': args.time_length,
103             'split_duration': args.split_duration,
104             'num_workers': args.num_workers,
105         }
106         manifest_vad_input = prepare_manifest(config)
107     else:
108         logging.warning(
109             "If you encounter CUDA memory issue, try splitting manifest entry by split_duration to avoid it."
110         )
111 
112     # setup_test_data
113     vad_model.setup_test_data(
114         test_data_config={
115             'vad_stream': True,
116             'sample_rate': 16000,
117             'manifest_filepath': manifest_vad_input,
118             'labels': ['infer',],
119             'num_workers': args.num_workers,
120             'shuffle': False,
121             'time_length': args.time_length,
122             'shift_length': args.shift_length,
123             'trim_silence': False,
124             'normalize_audio': args.normalize_audio,
125         }
126     )
127 
128     vad_model = vad_model.to(device)
129     vad_model.eval()
130 
131     time_unit = int(args.time_length / args.shift_length)
132     trunc = int(time_unit / 2)
133     trunc_l = time_unit - trunc
134     all_len = 0
135 
136     data = []
137     for line in open(args.dataset, 'r'):
138         file = json.loads(line)['audio_filepath'].split("/")[-1]
139         data.append(file.split(".wav")[0])
140     logging.info(f"Inference on {len(data)} audio files/json lines!")
141 
142     status = get_vad_stream_status(data)
143     for i, test_batch in enumerate(vad_model.test_dataloader()):
144         test_batch = [x.to(device) for x in test_batch]
145         with autocast():
146             log_probs = vad_model(input_signal=test_batch[0], input_signal_length=test_batch[1])
147             probs = torch.softmax(log_probs, dim=-1)
148             pred = probs[:, 1]
149 
150             if status[i] == 'start':
151                 to_save = pred[:-trunc]
152             elif status[i] == 'next':
153                 to_save = pred[trunc:-trunc_l]
154             elif status[i] == 'end':
155                 to_save = pred[trunc_l:]
156             else:
157                 to_save = pred
158 
159             all_len += len(to_save)
160             outpath = os.path.join(args.out_dir, data[i] + ".frame")
161             with open(outpath, "a") as fout:
162                 for f in range(len(to_save)):
163                     fout.write('{0:0.4f}\n'.format(to_save[f]))
164         del test_batch
165         if status[i] == 'end' or status[i] == 'single':
166             logging.debug(f"Overall length of prediction of {data[i]} is {all_len}!")
167             all_len = 0
168 
169 
170 if __name__ == '__main__':
171     main()
172
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/examples/asr/vad_infer.py b/examples/asr/vad_infer.py
--- a/examples/asr/vad_infer.py
+++ b/examples/asr/vad_infer.py
@@ -134,7 +134,7 @@
     all_len = 0
 
     data = []
-    for line in open(args.dataset, 'r'):
+    for line in open(manifest_vad_input, 'r'):
         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!")

{"golden_diff": "diff --git a/examples/asr/vad_infer.py b/examples/asr/vad_infer.py\n--- a/examples/asr/vad_infer.py\n+++ b/examples/asr/vad_infer.py\n@@ -134,7 +134,7 @@\n     all_len = 0\n \n     data = []\n-    for line in open(args.dataset, 'r'):\n+    for line in open(manifest_vad_input, 'r'):\n         file = json.loads(line)['audio_filepath'].split(\"/\")[-1]\n         data.append(file.split(\".wav\")[0])\n     logging.info(f\"Inference on {len(data)} audio files/json lines!\")\n", "issue": "vad_infer.py script fails with `IndexError` if option `--dont_auto_split` is not set\n**Describe the bug**\r\n\r\n`NeMo/examples/asr/vad_infer.py` script fails with `IndexError` if option `--dont_auto_split` is not set and at least 1 `.wav` file is long enough so that `nemo.collections.asr.parts.utils.vad_utils.prepare_manifest()` function split the `.wav` file.\r\n\r\n**Steps/Code to reproduce bug**\r\n\r\n```\r\nmkdir -p ~/debug_data\r\nwget http://i13pc106.ira.uka.de/~jniehues/IWSLT-SLT/data/eval/en-de/IWSLT-SLT.tst2019.en-de.tgz -O ~/debug_data/IWSLT-SLT.tst2019.en-de.tgz\r\ntar xzf ~/debug_data/IWSLT-SLT.tst2019.en-de.tgz -C ~/debug_data/\r\ncd ~/NeMo/examples/asr/\r\nwget https://raw.githubusercontent.com/NVIDIA/NeMo/feat/asr/iwslt_audio_to_nemo_format/scripts/dataset_processing/prepare_iwslt_audio_data.py\r\npython prepare_iwslt_audio_data.py -a ~/debug_data/IWSLT.tst2019/wavs/ -t ~/debug_data/IWSLT.tst2019/IWSLT.TED.tst2019.en-de.en.xml -o ~/debug_data/IWSLT.tst2019/manifest.json\r\npython vad_infer.py --dataset ~/debug_data/IWSLT.tst2019/manifest.json --out_dir ~/debug_data/IWSLT.tst2019/vad --vad_model vad_marblenet\r\n```\r\n\r\n\r\n**Expected behavior**\r\n\r\nNo errors\r\n\r\n**Environment overview (please complete the following information)**\r\n\r\n - Environment location: Bare-metal\r\n - Method of NeMo install: pip install nemo_toolkit[all]\r\n\r\n**Environment details**\r\n\r\nIf NVIDIA docker image is used you don't need to specify these.\r\nOtherwise, please provide:\r\n- OS version: Ubuntu 20.04.2 LTS\r\n- PyTorch version: 1.8.1\r\n- Python version: 3.8.10\r\n\r\n\n", "before_files": [{"content": "# Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nDuring inference, we perform frame-level prediction by two approaches: \n    1) shift the window of length time_length (e.g. 0.63s) by shift_length (e.g. 10ms) to generate the frame and use the prediction of the window to represent the label for the frame;\n       [this script demonstrate how to do this approach]\n    2) generate predictions with overlapping input segments. Then a smoothing filter is applied to decide the label for a frame spanned by multiple segments. \n       [get frame level prediction by this script and use vad_overlap_posterior.py in NeMo/scripts/voice_activity_detection\n       One can also find posterior about converting frame level prediction \n       to speech/no-speech segment in start and end times format in that script.]\n       \n       Image https://raw.githubusercontent.com/NVIDIA/NeMo/main/tutorials/asr/images/vad_post_overlap_diagram.png \n       will help you understand this method.\n   \nUsage:\npython vad_infer.py  --vad_model=\"vad_marblenet\" --dataset=<FULL PATH OF MANIFEST TO BE PERFORMED INFERENCE ON> --out_dir='frame/demo' --time_length=0.63\n\n\"\"\"\n\n\nimport json\nimport logging\nimport os\nfrom argparse import ArgumentParser\n\nimport torch\n\nfrom nemo.collections.asr.models import EncDecClassificationModel\nfrom nemo.collections.asr.parts.utils.vad_utils import get_vad_stream_status, prepare_manifest\nfrom nemo.utils import logging\n\ntry:\n    from torch.cuda.amp import autocast\nexcept ImportError:\n    from contextlib import contextmanager\n\n    @contextmanager\n    def autocast(enabled=None):\n        yield\n\n\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n\n\ndef main():\n    parser = ArgumentParser()\n    parser.add_argument(\n        \"--vad_model\", type=str, default=\"MatchboxNet-VAD-3x2\", required=False, help=\"Pass: 'MatchboxNet-VAD-3x2'\"\n    )\n    parser.add_argument(\n        \"--dataset\",\n        type=str,\n        required=True,\n        help=\"Path of json file of evaluation data. Audio files should have unique names.\",\n    )\n    parser.add_argument(\"--out_dir\", type=str, default=\"vad_frame\", help=\"Dir of your vad outputs\")\n    parser.add_argument(\"--time_length\", type=float, default=0.63)\n    parser.add_argument(\"--shift_length\", type=float, default=0.01)\n    parser.add_argument(\"--normalize_audio\", type=bool, default=False)\n    parser.add_argument(\"--num_workers\", type=float, default=20)\n    parser.add_argument(\"--split_duration\", type=float, default=400)\n    parser.add_argument(\n        \"--dont_auto_split\",\n        default=False,\n        action='store_true',\n        help=\"Whether to automatically split manifest entry by split_duration to avoid potential CUDA out of memory issue.\",\n    )\n\n    args = parser.parse_args()\n\n    torch.set_grad_enabled(False)\n\n    if args.vad_model.endswith('.nemo'):\n        logging.info(f\"Using local VAD model from {args.vad_model}\")\n        vad_model = EncDecClassificationModel.restore_from(restore_path=args.vad_model)\n    else:\n        logging.info(f\"Using NGC cloud VAD model {args.vad_model}\")\n        vad_model = EncDecClassificationModel.from_pretrained(model_name=args.vad_model)\n\n    if not os.path.exists(args.out_dir):\n        os.mkdir(args.out_dir)\n\n    # Prepare manifest for streaming VAD\n    manifest_vad_input = args.dataset\n    if not args.dont_auto_split:\n        logging.info(\"Split long audio file to avoid CUDA memory issue\")\n        logging.debug(\"Try smaller split_duration if you still have CUDA memory issue\")\n        config = {\n            'manifest_filepath': manifest_vad_input,\n            'time_length': args.time_length,\n            'split_duration': args.split_duration,\n            'num_workers': args.num_workers,\n        }\n        manifest_vad_input = prepare_manifest(config)\n    else:\n        logging.warning(\n            \"If you encounter CUDA memory issue, try splitting manifest entry by split_duration to avoid it.\"\n        )\n\n    # setup_test_data\n    vad_model.setup_test_data(\n        test_data_config={\n            'vad_stream': True,\n            'sample_rate': 16000,\n            'manifest_filepath': manifest_vad_input,\n            'labels': ['infer',],\n            'num_workers': args.num_workers,\n            'shuffle': False,\n            'time_length': args.time_length,\n            'shift_length': args.shift_length,\n            'trim_silence': False,\n            'normalize_audio': args.normalize_audio,\n        }\n    )\n\n    vad_model = vad_model.to(device)\n    vad_model.eval()\n\n    time_unit = int(args.time_length / args.shift_length)\n    trunc = int(time_unit / 2)\n    trunc_l = time_unit - trunc\n    all_len = 0\n\n    data = []\n    for line in open(args.dataset, 'r'):\n        file = json.loads(line)['audio_filepath'].split(\"/\")[-1]\n        data.append(file.split(\".wav\")[0])\n    logging.info(f\"Inference on {len(data)} audio files/json lines!\")\n\n    status = get_vad_stream_status(data)\n    for i, test_batch in enumerate(vad_model.test_dataloader()):\n        test_batch = [x.to(device) for x in test_batch]\n        with autocast():\n            log_probs = vad_model(input_signal=test_batch[0], input_signal_length=test_batch[1])\n            probs = torch.softmax(log_probs, dim=-1)\n            pred = probs[:, 1]\n\n            if status[i] == 'start':\n                to_save = pred[:-trunc]\n            elif status[i] == 'next':\n                to_save = pred[trunc:-trunc_l]\n            elif status[i] == 'end':\n                to_save = pred[trunc_l:]\n            else:\n                to_save = pred\n\n            all_len += len(to_save)\n            outpath = os.path.join(args.out_dir, data[i] + \".frame\")\n            with open(outpath, \"a\") as fout:\n                for f in range(len(to_save)):\n                    fout.write('{0:0.4f}\\n'.format(to_save[f]))\n        del test_batch\n        if status[i] == 'end' or status[i] == 'single':\n            logging.debug(f\"Overall length of prediction of {data[i]} is {all_len}!\")\n            all_len = 0\n\n\nif __name__ == '__main__':\n    main()\n", "path": "examples/asr/vad_infer.py"}], "after_files": [{"content": "# Copyright (c) 2020, NVIDIA CORPORATION.  All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"\nDuring inference, we perform frame-level prediction by two approaches: \n    1) shift the window of length time_length (e.g. 0.63s) by shift_length (e.g. 10ms) to generate the frame and use the prediction of the window to represent the label for the frame;\n       [this script demonstrate how to do this approach]\n    2) generate predictions with overlapping input segments. Then a smoothing filter is applied to decide the label for a frame spanned by multiple segments. \n       [get frame level prediction by this script and use vad_overlap_posterior.py in NeMo/scripts/voice_activity_detection\n       One can also find posterior about converting frame level prediction \n       to speech/no-speech segment in start and end times format in that script.]\n       \n       Image https://raw.githubusercontent.com/NVIDIA/NeMo/main/tutorials/asr/images/vad_post_overlap_diagram.png \n       will help you understand this method.\n   \nUsage:\npython vad_infer.py  --vad_model=\"vad_marblenet\" --dataset=<FULL PATH OF MANIFEST TO BE PERFORMED INFERENCE ON> --out_dir='frame/demo' --time_length=0.63\n\n\"\"\"\n\n\nimport json\nimport logging\nimport os\nfrom argparse import ArgumentParser\n\nimport torch\n\nfrom nemo.collections.asr.models import EncDecClassificationModel\nfrom nemo.collections.asr.parts.utils.vad_utils import get_vad_stream_status, prepare_manifest\nfrom nemo.utils import logging\n\ntry:\n    from torch.cuda.amp import autocast\nexcept ImportError:\n    from contextlib import contextmanager\n\n    @contextmanager\n    def autocast(enabled=None):\n        yield\n\n\ndevice = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n\n\ndef main():\n    parser = ArgumentParser()\n    parser.add_argument(\n        \"--vad_model\", type=str, default=\"MatchboxNet-VAD-3x2\", required=False, help=\"Pass: 'MatchboxNet-VAD-3x2'\"\n    )\n    parser.add_argument(\n        \"--dataset\",\n        type=str,\n        required=True,\n        help=\"Path of json file of evaluation data. Audio files should have unique names.\",\n    )\n    parser.add_argument(\"--out_dir\", type=str, default=\"vad_frame\", help=\"Dir of your vad outputs\")\n    parser.add_argument(\"--time_length\", type=float, default=0.63)\n    parser.add_argument(\"--shift_length\", type=float, default=0.01)\n    parser.add_argument(\"--normalize_audio\", type=bool, default=False)\n    parser.add_argument(\"--num_workers\", type=float, default=20)\n    parser.add_argument(\"--split_duration\", type=float, default=400)\n    parser.add_argument(\n        \"--dont_auto_split\",\n        default=False,\n        action='store_true',\n        help=\"Whether to automatically split manifest entry by split_duration to avoid potential CUDA out of memory issue.\",\n    )\n\n    args = parser.parse_args()\n\n    torch.set_grad_enabled(False)\n\n    if args.vad_model.endswith('.nemo'):\n        logging.info(f\"Using local VAD model from {args.vad_model}\")\n        vad_model = EncDecClassificationModel.restore_from(restore_path=args.vad_model)\n    else:\n        logging.info(f\"Using NGC cloud VAD model {args.vad_model}\")\n        vad_model = EncDecClassificationModel.from_pretrained(model_name=args.vad_model)\n\n    if not os.path.exists(args.out_dir):\n        os.mkdir(args.out_dir)\n\n    # Prepare manifest for streaming VAD\n    manifest_vad_input = args.dataset\n    if not args.dont_auto_split:\n        logging.info(\"Split long audio file to avoid CUDA memory issue\")\n        logging.debug(\"Try smaller split_duration if you still have CUDA memory issue\")\n        config = {\n            'manifest_filepath': manifest_vad_input,\n            'time_length': args.time_length,\n            'split_duration': args.split_duration,\n            'num_workers': args.num_workers,\n        }\n        manifest_vad_input = prepare_manifest(config)\n    else:\n        logging.warning(\n            \"If you encounter CUDA memory issue, try splitting manifest entry by split_duration to avoid it.\"\n        )\n\n    # setup_test_data\n    vad_model.setup_test_data(\n        test_data_config={\n            'vad_stream': True,\n            'sample_rate': 16000,\n            'manifest_filepath': manifest_vad_input,\n            'labels': ['infer',],\n            'num_workers': args.num_workers,\n            'shuffle': False,\n            'time_length': args.time_length,\n            'shift_length': args.shift_length,\n            'trim_silence': False,\n            'normalize_audio': args.normalize_audio,\n        }\n    )\n\n    vad_model = vad_model.to(device)\n    vad_model.eval()\n\n    time_unit = int(args.time_length / args.shift_length)\n    trunc = int(time_unit / 2)\n    trunc_l = time_unit - trunc\n    all_len = 0\n\n    data = []\n    for line in open(manifest_vad_input, 'r'):\n        file = json.loads(line)['audio_filepath'].split(\"/\")[-1]\n        data.append(file.split(\".wav\")[0])\n    logging.info(f\"Inference on {len(data)} audio files/json lines!\")\n\n    status = get_vad_stream_status(data)\n    for i, test_batch in enumerate(vad_model.test_dataloader()):\n        test_batch = [x.to(device) for x in test_batch]\n        with autocast():\n            log_probs = vad_model(input_signal=test_batch[0], input_signal_length=test_batch[1])\n            probs = torch.softmax(log_probs, dim=-1)\n            pred = probs[:, 1]\n\n            if status[i] == 'start':\n                to_save = pred[:-trunc]\n            elif status[i] == 'next':\n                to_save = pred[trunc:-trunc_l]\n            elif status[i] == 'end':\n                to_save = pred[trunc_l:]\n            else:\n                to_save = pred\n\n            all_len += len(to_save)\n            outpath = os.path.join(args.out_dir, data[i] + \".frame\")\n            with open(outpath, \"a\") as fout:\n                for f in range(len(to_save)):\n                    fout.write('{0:0.4f}\\n'.format(to_save[f]))\n        del test_batch\n        if status[i] == 'end' or status[i] == 'single':\n            logging.debug(f\"Overall length of prediction of {data[i]} is {all_len}!\")\n            all_len = 0\n\n\nif __name__ == '__main__':\n    main()\n", "path": "examples/asr/vad_infer.py"}]}