def validate_args(args: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ args.output_directory = args.output_directory.rstrip("/").rstrip("\\") args.corpus_directory = args.corpus_directory.rstrip("/").rstrip("\\") if not os.path.exists(args.corpus_directory): raise ArgumentError( f"Could not find the corpus directory {args.corpus_directory}.") if not os.path.isdir(args.corpus_directory): raise ArgumentError( f"The specified corpus directory ({args.corpus_directory}) is not a directory." ) if args.corpus_directory == args.output_directory: raise ArgumentError( "Corpus directory and output directory cannot be the same folder.")
def validate_args(args: Namespace) -> None: # pragma: no cover """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ args.output_directory = args.output_directory.rstrip("/").rstrip("\\") args.corpus_directory = args.corpus_directory.rstrip("/").rstrip("\\") if args.cluster and not args.num_speakers: raise ArgumentError( "If using clustering, num_speakers must be specified") if not os.path.exists(args.corpus_directory): raise ArgumentError( f"Could not find the corpus directory {args.corpus_directory}.") if not os.path.isdir(args.corpus_directory): raise ArgumentError( f"The specified corpus directory ({args.corpus_directory}) is not a directory." ) if args.corpus_directory == args.output_directory: raise ArgumentError( "Corpus directory and output directory cannot be the same folder.") args.ivector_extractor_path = validate_model_arg( args.ivector_extractor_path, "ivector")
def validate_args(args: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ try: args.speaker_characters = int(args.speaker_characters) except ValueError: pass 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( f"Could not find the corpus directory {args.corpus_directory}.")) if not os.path.isdir(args.corpus_directory): raise (ArgumentError( f"The specified corpus directory ({args.corpus_directory}) is not a directory." )) args.dictionary_path = validate_model_arg(args.dictionary_path, "dictionary") if args.acoustic_model_path: args.acoustic_model_path = validate_model_arg(args.acoustic_model_path, "acoustic")
def validate_args(args: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ try: args.speaker_characters = int(args.speaker_characters) except ValueError: pass args.output_directory = args.output_directory.rstrip("/").rstrip("\\") args.corpus_directory = args.corpus_directory.rstrip("/").rstrip("\\") if not os.path.exists(args.corpus_directory): raise ArgumentError( f"Could not find the corpus directory {args.corpus_directory}.") if not os.path.isdir(args.corpus_directory): raise ArgumentError( f"The specified corpus directory ({args.corpus_directory}) is not a directory." ) args.dictionary_path = validate_model_arg(args.dictionary_path, "dictionary") args.acoustic_model_path = validate_model_arg(args.acoustic_model_path, "acoustic")
def validate(args): 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, 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): 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.config_path and not os.path.exists(args.config_path): raise (ArgumentError('Could not find the config file {}.'.format( args.config_path)))
def validate_args(args): 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 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): 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.corpus_directory == args.output_directory: raise ArgumentError( 'Corpus directory and output directory cannot be the same folder.')
def validate_args(args): args.model_type = args.model_type.lower() if args.model_type not in ['acoustic', 'g2p', 'dictionary', 'ivector']: raise ArgumentError( "model_type must be one of 'acoustic', 'g2p', 'dictionary', or 'ivector" ) if args.language is not None: available_languages = list_available_languages(args.model_type) if args.language not in available_languages: possible = ', '.join(available_languages) raise ArgumentError( 'Could not find {}, ' 'possible languages for download are: {}'.format( args.language, possible))
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, 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)))
def validate(args, pretrained_languages): if not args.g2p_model_path: args.g2p_model_path = None elif args.g2p_model_path in pretrained_languages: args.g2p_model_path = get_pretrained_g2p_path(args.g2p_model_path) if args.g2p_model_path and not os.path.exists(args.g2p_model_path): raise (ArgumentError('Could not find the G2P model file {}.'.format( args.g2p_model_path))) if args.g2p_model_path and (not os.path.isfile(args.g2p_model_path) or not args.g2p_model_path.endswith('.zip')): raise (ArgumentError( 'The specified G2P model path ({}) is not a zip file.'.format( args.g2p_model_path))) if not os.path.exists(args.input_path): raise (ArgumentError('Could not find the input path {}.'.format( args.input_path)))
def validate_args(args, downloaded_acoustic_models, download_dictionaries): 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)) 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)))
def validate_args(args): 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 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: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ try: args.speaker_characters = int(args.speaker_characters) except ValueError: pass args.output_directory = None if not args.output_model_path: args.output_model_path = None output_paths = args.output_paths if len(output_paths) > 2: raise ArgumentError(f"Got more arguments for output_paths than 2: {output_paths}") for path in output_paths: if path.endswith(".zip"): args.output_model_path = path else: args.output_directory = path.rstrip("/").rstrip("\\") args.corpus_directory = args.corpus_directory.rstrip("/").rstrip("\\") if args.corpus_directory == args.output_directory: raise ArgumentError("Corpus directory and output directory cannot be the same folder.") if not os.path.exists(args.corpus_directory): raise (ArgumentError(f'Could not find the corpus directory "{args.corpus_directory}".')) if not os.path.isdir(args.corpus_directory): raise ( ArgumentError( f'The specified corpus directory "{args.corpus_directory}" is not a directory.' ) ) args.dictionary_path = validate_model_arg(args.dictionary_path, "dictionary")
def validate_args(args, downloaded_ivector_extractors): if args.cluster and not args.num_speakers: raise ArgumentError( 'If using clustering, num_speakers must be specified') 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.corpus_directory == args.output_directory: raise ArgumentError( 'Corpus directory and output directory cannot be the same folder.') if args.ivector_extractor_path.lower() in downloaded_ivector_extractors: args.ivector_extractor_path = get_pretrained_ivector_path( args.ivector_extractor_path.lower()) elif args.ivector_extractor_path.lower().endswith( IvectorExtractor.extension): if not os.path.exists(args.ivector_extractor_path): raise ArgumentError('The specified model path does not exist: ' + args.ivector_extractor_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.ivector_extractor_path.lower(), ', '.join(downloaded_ivector_extractors)))
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)))
def validate_args(args: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ args.source_path = args.source_path.rstrip("/").rstrip("\\") if args.dictionary_path: args.dictionary_path = validate_model_arg(args.dictionary_path, "dictionary") if not args.source_path.endswith(".arpa"): if not os.path.exists(args.source_path): raise (ArgumentError( f"Could not find the corpus directory {args.source_path}.")) if not os.path.isdir(args.source_path): raise (ArgumentError( f"The specified corpus directory ({args.source_path}) is not a directory." )) else: if not os.path.exists(args.source_path): raise (ArgumentError( f"Could not find the source file {args.source_path}.")) if args.config_path and not os.path.exists(args.config_path): raise (ArgumentError( f"Could not find the config file {args.config_path}.")) if args.model_path and not os.path.exists(args.model_path): raise ( ArgumentError(f"Could not find the model file {args.model_path}."))
def validate_dictionary_args(args: Namespace) -> None: """ Validate the command line arguments Parameters ---------- args: :class:`~argparse.Namespace` Parsed command line arguments Raises ------ :class:`~montreal_forced_aligner.exceptions.ArgumentError` If there is a problem with any arguments """ if sys.platform == "win32": raise ArgumentError( "Cannot validate dictionaries on native Windows, please use Windows Subsystem for Linux." ) args.dictionary_path = validate_model_arg(args.dictionary_path, "dictionary") if args.g2p_model_path: args.g2p_model_path = validate_model_arg(args.g2p_model_path, "g2p")