def read_recognizer(inference_config_or_name='latest'): # download specified model automatically if no model exists if len(get_all_models()) == 0: download_model('latest') # create default config if input is the model's name if isinstance(inference_config_or_name, str): model_name = resolve_model_name(inference_config_or_name) inference_config = Namespace(model=model_name, device_id=-1, lang='ipa', approximate=False) else: assert isinstance(inference_config_or_name, Namespace) inference_config = inference_config_or_name model_path = Path(__file__).parent / 'pretrained' / inference_config.model if inference_config.model == 'latest' and not model_path.exists(): download_model(inference_config) assert model_path.exists(), f"{inference_config.model} is not a valid model" # create pm (pm stands for preprocess model: audio -> feature etc..) pm = read_pm(model_path, inference_config) # create am (acoustic model: feature -> logits ) am = read_am(model_path, inference_config) # create lm (language model: logits -> phone) lm = read_lm(model_path, inference_config) return Recognizer(pm, am, lm, inference_config)
def read_recognizer(inference_config): model_path = Path(__file__).parent / 'pretrained' / inference_config.model if inference_config.model == 'latest' and not model_path.exists(): download_model(inference_config) assert model_path.exists( ), f"{inference_config.model} is not a valid model" # create pm (pm stands for preprocess model: audio -> feature etc..) pm = read_pm(model_path, inference_config) # create am (acoustic model: feature -> logits ) am = read_am(model_path, inference_config) # create lm (language model: logits -> phone) lm = read_lm(model_path, inference_config) return Recognizer(pm, am, lm, inference_config)