コード例 #1
0
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)
コード例 #2
0
    parser.add_argument('-i',
                        '--input',
                        type=str,
                        required=True,
                        help='specify your input wav file')

    args = parser.parse_args()

    # check file format
    assert args.input.endswith(
        '.wav'
    ), " Error: Please use a wav file. other audio files can be converted to wav by sox"

    # download specified model automatically if no model exists
    if len(get_all_models()) == 0:
        download_model('latest')

    # resolve model's name
    model_name = resolve_model_name(args.model)
    if model_name == "none":
        print(
            "Model ", model_name,
            " does not exist. Please download this model or use an existing model in list_model"
        )
        exit(0)

    args.model = model_name

    # create recognizer
    recognizer = read_recognizer(args)