def download_model(model_type, language):
    if language is None:
        print('Available languages to download for {}:'.format(model_type))
        for lang in list_available_languages(model_type):
            print(lang)
        return
    if model_type == 'acoustic':
        extension = AcousticModel.extension
        out_path = get_pretrained_acoustic_path(language)
    elif model_type == 'g2p':
        extension = G2PModel.extension
        out_path = get_pretrained_g2p_path(language)
    elif model_type == 'dictionary':
        extension = '.dict'
        out_path = get_dictionary_path(language)
    elif model_type == 'ivector':
        extension = IvectorExtractor.extension
        out_path = get_pretrained_ivector_path(language)
    else:
        raise NotImplementedError
    url = 'https://github.com/MontrealCorpusTools/mfa-models/raw/master/{}/{}{}'.format(
        model_type, language, extension)

    r = requests.get(url)
    with open(out_path, 'wb') as f:
        f.write(r.content)
Пример #2
0
def validate_args(args, downloaded_acoustic_models, download_dictionaries):
    if not os.path.exists(args.corpus_directory):
        raise ArgumentError('Could not find the corpus directory {}.'.format(
            args.corpus_directory))
    if not os.path.isdir(args.corpus_directory):
        raise ArgumentError(
            'The specified corpus directory ({}) is not a directory.'.format(
                args.corpus_directory))

    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())

    if not os.path.exists(args.dictionary_path):
        raise ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path))
    if not os.path.isfile(args.dictionary_path):
        raise ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path))

    if args.acoustic_model_path.lower() in downloaded_acoustic_models:
        args.acoustic_model_path = get_pretrained_acoustic_path(
            args.acoustic_model_path.lower())
    elif args.acoustic_model_path.lower().endswith(AcousticModel.extension):
        if not os.path.exists(args.acoustic_model_path):
            raise ArgumentError('The specified model path does not exist: ' +
                                args.acoustic_model_path)
    else:
        raise ArgumentError(
            'The language \'{}\' is not currently included in the distribution, '
            'please align via training or specify one of the following language names: {}.'
            .format(args.acoustic_model_path.lower(),
                    ', '.join(downloaded_acoustic_models)))
Пример #3
0
def validate(args, download_dictionaries=None):
    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())
    if not os.path.exists(args.dictionary_path):
        raise (ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path)))
    if not os.path.isfile(args.dictionary_path):
        raise (ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path)))
def validate_args(args, downloaded_acoustic_models, download_dictionaries,
                  downloaded_language_models):
    if not os.path.exists(args.corpus_directory):
        raise ArgumentError('Could not find the corpus directory {}.'.format(
            args.corpus_directory))
    if not os.path.isdir(args.corpus_directory):
        raise ArgumentError(
            'The specified corpus directory ({}) is not a directory.'.format(
                args.corpus_directory))

    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())
    if not os.path.exists(args.dictionary_path):
        raise ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path))
    if not os.path.isfile(args.dictionary_path):
        raise ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path))
    if args.corpus_directory == args.output_directory:
        raise ArgumentError(
            'Corpus directory and output directory cannot be the same folder.')

    if args.acoustic_model_path.lower() in downloaded_acoustic_models:
        args.acoustic_model_path = get_pretrained_acoustic_path(
            args.acoustic_model_path.lower())
    elif args.acoustic_model_path.lower().endswith(AcousticModel.extension):
        if not os.path.exists(args.acoustic_model_path):
            raise ArgumentError('The specified model path does not exist: ' +
                                args.acoustic_model_path)
    else:
        raise ArgumentError(
            'The acoustic model \'{}\' is not currently downloaded, '
            'please download a pretrained model, align via training or specify one of the following language names: {}.'
            .format(args.acoustic_model_path.lower(),
                    ', '.join(downloaded_acoustic_models)))

    if args.language_model_path.lower() in downloaded_language_models:
        args.language_model_path = get_pretrained_language_model_path(
            args.language_model_path.lower())
    elif args.language_model_path.lower().endswith(LanguageModel.extension) or \
            args.language_model_path.lower().endswith(FORMAT):
        if not os.path.exists(args.language_model_path):
            raise ArgumentError('The specified model path does not exist: ' +
                                args.language_model_path)
    else:
        raise ArgumentError(
            'The language model \'{}\' is not currently downloaded, '
            'please download, train a new model, or specify one of the following language names: {}.'
            .format(args.language_model_path.lower(),
                    ', '.join(downloaded_language_models)))
Пример #5
0
def validate_args(args, download_dictionaries=None):
    if args.dictionary_path is not None and args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(args.dictionary_path.lower())
    if not args.source_path.endswith('.arpa'):
        if not os.path.exists(args.source_path):
            raise (ArgumentError('Could not find the corpus directory {}.'.format(args.source_path)))
        if not os.path.isdir(args.source_path):
            raise (ArgumentError('The specified corpus directory ({}) is not a directory.'.format(args.source_path)))
    else:
        if not os.path.exists(args.source_path):
            raise (ArgumentError('Could not find the source file {}.'.format(args.source_path)))
    if args.config_path and not os.path.exists(args.config_path):
        raise (ArgumentError('Could not find the config file {}.'.format(args.config_path)))
    if args.model_path and not os.path.exists(args.model_path):
        raise (ArgumentError('Could not find the model file {}.'.format(args.model_path)))
def validate_args(args, download_dictionaries):
    if args.corpus_directory == args.output_directory:
        raise Exception(
            'Corpus directory and output directory cannot be the same folder.')
    if not os.path.exists(args.corpus_directory):
        raise (ArgumentError('Could not find the corpus directory {}.'.format(
            args.corpus_directory)))
    if not os.path.isdir(args.corpus_directory):
        raise (ArgumentError(
            'The specified corpus directory ({}) is not a directory.'.format(
                args.corpus_directory)))

    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())
    if not os.path.exists(args.dictionary_path):
        raise (ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path)))
    if not os.path.isfile(args.dictionary_path):
        raise (ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path)))
Пример #7
0
def validate_args(args, download_dictionaries=None):
    if args.test_transcriptions and args.ignore_acoustics:
        raise ArgumentError(
            'Cannot test transcriptions without acoustic feature generation.')
    if not os.path.exists(args.corpus_directory):
        raise (ArgumentError('Could not find the corpus directory {}.'.format(
            args.corpus_directory)))
    if not os.path.isdir(args.corpus_directory):
        raise (ArgumentError(
            'The specified corpus directory ({}) is not a directory.'.format(
                args.corpus_directory)))

    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())
    if not os.path.exists(args.dictionary_path):
        raise (ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path)))
    if not os.path.isfile(args.dictionary_path):
        raise (ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path)))
Пример #8
0
def validate_args(args, download_dictionaries=None):
    if args.config_path and not os.path.exists(args.config_path):
        raise (ArgumentError('Could not find the config file {}.'.format(
            args.config_path)))

    if not os.path.exists(args.corpus_directory):
        raise (ArgumentError('Could not find the corpus directory {}.'.format(
            args.corpus_directory)))
    if not os.path.isdir(args.corpus_directory):
        raise (ArgumentError(
            'The specified corpus directory ({}) is not a directory.'.format(
                args.corpus_directory)))

    if args.dictionary_path.lower() in download_dictionaries:
        args.dictionary_path = get_dictionary_path(
            args.dictionary_path.lower())
    if not os.path.exists(args.dictionary_path):
        raise (ArgumentError('Could not find the dictionary file {}'.format(
            args.dictionary_path)))
    if not os.path.isfile(args.dictionary_path):
        raise (ArgumentError(
            'The specified dictionary path ({}) is not a text file.'.format(
                args.dictionary_path)))