    def prepare_fairseq_model(self, model_cfg: dict) -> None:
        """
        Prepare the fairseq asr model

        Args:
            model_cfg: the specific model config dict must have: (1) ckpt_path, (2) dict_path
        """

        def download_file(url: str, cache_dir: Path):
            download_path = cache_dir / url.split("/")[-1]
            if not (cache_dir / url.split("/")[-1]).exists():
                with DownloadProgressBar(
                    unit="B", unit_scale=True, miniters=1, desc=url.split("/")[-1]
                ) as t:
                    cache_dir.mkdir(parents=True, exist_ok=True)
                    urllib.request.urlretrieve(
                        url, filename=download_path.as_posix(), reporthook=t.update_to
                    )
            else:
                print(f"'{url}' exists in {cache_dir}")

            return download_path.as_posix()

        try:
            ckpt_path = model_cfg["ckpt_path"]
            dict_path = model_cfg["dict_path"]
        except KeyError:
            raise KeyError(
                "Fairseq model cfg must provide (1) ckpt_path, (2) dict_path"
            )

        if re.search("^https", ckpt_path):
            ckpt_path = download_file(ckpt_path, self.cache_dirpath)
        if re.search("^https", dict_path):
            dict_path = download_file(dict_path, self.cache_dirpath)

        model, saved_cfg, _ = fairseq.checkpoint_utils.load_model_ensemble_and_task(
            [ckpt_path],
            arg_overrides={
                "task": "audio_finetuning",
                "data": self.cache_dirpath.as_posix(),
            },  # data must have dict in it
        )

        dict_lines = open(dict_path, "r").readlines()
        tokens = [l.split()[0] for l in dict_lines]
        # adding default fairseq special tokens
        tokens = ["<s>", "<pad>", "</s>", "<unk>"] + tokens

        self.model = model[0]
        self.tokens = tokens

        if "|" in tokens:
            self.sil_token = "|"
        else:
            self.sil_token = tokens[
                2
            ]  # use eos as silence token if | not presented e.g., Hok ASR model
        print(f"Inferring silence token from the dict: {self.sil_token}")
        self.blank_token = self.tokens[0]

        self.sampling_rate = saved_cfg.task.sample_rate
        self.normalize_input = saved_cfg.task.normalize
Prepare the fairseq asr model

Args:
model_cfg: the specific model config dict must have: (1) ckpt_path, (2) dict_path
examples/speech_to_speech/asr_bleu/utils.py