def test_align_multilingual( multilingual_ipa_corpus_dir, english_uk_mfa_dictionary, generated_dir, temp_dir, basic_align_config_path, english_mfa_acoustic_model, ): command = [ "align", multilingual_ipa_corpus_dir, english_uk_mfa_dictionary, english_mfa_acoustic_model, os.path.join(generated_dir, "multilingual"), "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", "--output_format", "short_textgrid", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown)
def main(): mp.freeze_support() args = parser.parse_args() fix_path() if args.subcommand == 'align': run_align_corpus(args, acoustic_languages) elif args.subcommand == 'train': run_train_corpus(args) elif args.subcommand == 'g2p': run_g2p(args, g2p_languages) elif args.subcommand == 'train_g2p': run_train_g2p(args) elif args.subcommand == 'validate': run_validate_corpus(args) elif args.subcommand == 'download': run_download(args) elif args.subcommand == 'train_lm': run_train_lm(args) elif args.subcommand == 'train_ivector': run_train_ivector_extractor(args) elif args.subcommand == 'annotator': run_annotator(args) elif args.subcommand == 'thirdparty': run_thirdparty(args) elif args.subcommand == 'transcribe': run_transcribe_corpus(args) unfix_path()
def test_align_opus( opus_corpus_dir, generated_dir, english_dictionary, temp_dir, basic_align_config_path, english_acoustic_model, ): output_dir = os.path.join(generated_dir, "opus_output") command = [ "align", opus_corpus_dir, english_dictionary, english_acoustic_model, output_dir, "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown) tg = tgio.openTextgrid(os.path.join(output_dir, "13697_11991_000000.TextGrid"), includeEmptyIntervals=False) assert len(tg.tierNameList) == 2
def test_align_split( basic_split_dir, english_us_mfa_dictionary, generated_dir, temp_dir, basic_align_config_path, english_acoustic_model, english_mfa_acoustic_model, ): audio_dir, text_dir = basic_split_dir command = [ "align", text_dir, english_us_mfa_dictionary, english_mfa_acoustic_model, os.path.join(generated_dir, "multilingual"), "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", "--audio_directory", audio_dir, ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown)
def test_align_evaluation( basic_corpus_dir, english_us_mfa_dictionary, generated_dir, temp_dir, basic_align_config_path, english_mfa_acoustic_model, basic_reference_dir, eval_mapping_path, ): command = [ "align", basic_corpus_dir, english_us_mfa_dictionary, english_mfa_acoustic_model, os.path.join(generated_dir, "align_eval_output"), "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", "--reference_directory", basic_reference_dir, "--custom_mapping_path", eval_mapping_path, ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown)
def test_align_multilingual_tg_speaker_dict( multilingual_ipa_tg_corpus_dir, mfa_speaker_dict_path, generated_dir, temp_dir, basic_align_config_path, english_mfa_acoustic_model, ): command = [ "align", multilingual_ipa_tg_corpus_dir, mfa_speaker_dict_path, english_mfa_acoustic_model, os.path.join(generated_dir, "multilingual_speaker_dict_tg"), "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", "--include_original_text", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown)
def test_train_dict( basic_corpus_dir, english_dictionary, english_acoustic_model, generated_dir, temp_dir, basic_align_config_path, ): output_path = os.path.join(generated_dir, "trained_dict") command = [ "train_dictionary", basic_corpus_dir, english_dictionary, english_acoustic_model, output_path, "-t", temp_dir, "-q", "--clean", "--debug", "--silence_probabilities", "--config_path", basic_align_config_path, "--use_mp", ] args, unknown = parser.parse_known_args(command) run_train_dictionary(args) dict_path = os.path.join(output_path, "english_us_arpa.dict") assert os.path.exists(output_path) textgrid_output = os.path.join(generated_dir, "trained_dict_output") command = [ "align", basic_corpus_dir, dict_path, english_acoustic_model, textgrid_output, "-t", temp_dir, "-q", "--clean", "--debug", "--config_path", basic_align_config_path, ] args, unknown = parser.parse_known_args(command) run_align_corpus(args)
def test_align_basic(basic_corpus_dir, sick_dict_path, generated_dir, large_dataset_dictionary, temp_dir, basic_align_config, english_acoustic_model): command = [ 'align', basic_corpus_dir, sick_dict_path, 'english', os.path.join(generated_dir, 'basic_output'), '-t', temp_dir, '-c', basic_align_config, '-q', '--clean', '-d' ] args, unknown = parser.parse_known_args(command) with pytest.raises(PronunciationAcousticMismatchError): run_align_corpus(args, unknown) command = [ 'align', basic_corpus_dir, large_dataset_dictionary, 'english', os.path.join(generated_dir, 'basic_output'), '-t', temp_dir, '-c', basic_align_config, '-q', '--clean', '-d' ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown)
def test_acoustic_g2p_model( basic_corpus_dir, acoustic_model_dir, dict_dir, generated_dir, temp_dir, basic_align_config_path, ): if sys.platform == "win32": pytest.skip("G2P not enabled") model_path = os.path.join(acoustic_model_dir, "acoustic_g2p_output_model.zip") dict_path = os.path.join(dict_dir, "acoustic_g2p_dictionary.yaml") output_directory = os.path.join(generated_dir, "acoustic_g2p_output") command = [ "align", basic_corpus_dir, dict_path, model_path, output_directory, "-t", temp_dir, "--config_path", basic_align_config_path, "--clean", "--debug", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown) assert os.path.exists(output_directory) output_paths = [ os.path.join(output_directory, "michael", "acoustic corpus.TextGrid"), os.path.join(output_directory, "michael", "acoustic_corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold_corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold corpus3.TextGrid"), os.path.join(output_directory, "sickmichael", "cold_corpus3.TextGrid"), ] for path in output_paths: assert os.path.exists(path)
def test_align_basic(basic_corpus_dir, sick_dict_path, generated_dir, large_dataset_dictionary, temp_dir, basic_align_config, english_acoustic_model): args = DummyArgs() args.acoustic_model_path = 'english' args.corpus_directory = basic_corpus_dir args.dictionary_path = sick_dict_path args.output_directory = os.path.join(generated_dir, 'basic_output') args.quiet = True args.clean = True args.temp_directory = temp_dir args.config_path = basic_align_config with pytest.raises(PronunciationAcousticMismatchError): run_align_corpus(args) args.acoustic_model_path = 'english' args.corpus_directory = basic_corpus_dir args.dictionary_path = large_dataset_dictionary args.output_directory = os.path.join(generated_dir, 'basic_output') run_align_corpus(args)
def test_align_basic( basic_corpus_dir, generated_dir, english_dictionary, temp_dir, basic_align_config_path, english_acoustic_model, ): output_directory = os.path.join(generated_dir, "basic_align_output") command = [ "align", basic_corpus_dir, english_dictionary, english_acoustic_model, output_directory, "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown) assert os.path.exists(output_directory) output_paths = [ os.path.join(output_directory, "michael", "acoustic corpus.TextGrid"), os.path.join(output_directory, "michael", "acoustic_corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold_corpus.TextGrid"), os.path.join(output_directory, "sickmichael", "cold corpus3.TextGrid"), os.path.join(output_directory, "sickmichael", "cold_corpus3.TextGrid"), ] for path in output_paths: assert os.path.exists(path)
def test_swedish_mfa( swedish_dir, generated_dir, swedish_cv_dictionary, temp_dir, basic_align_config_path, swedish_cv_acoustic_model, ): output_dir = os.path.join(generated_dir, "swedish_mfa_output") command = [ "align", swedish_dir, swedish_cv_dictionary, swedish_cv_acoustic_model, output_dir, "-t", temp_dir, "--config_path", basic_align_config_path, "-q", "--clean", "--debug", ] args, unknown = parser.parse_known_args(command) run_align_corpus(args, unknown) output_speaker_dir = os.path.join(output_dir, "se10x016") assert os.path.exists(output_speaker_dir) for file in [ "se10x016-08071999-1334_u0016001", "se10x016-08071999-1334_u0016002", "se10x016-08071999-1334_u0016003", "se10x016-08071999-1334_u0016004", ]: tg_path = os.path.join(output_speaker_dir, file + ".TextGrid") assert os.path.exists(tg_path) tg = tgio.openTextgrid(tg_path, includeEmptyIntervals=False) assert len(tg.tierNameList) == 2
def main() -> None: """ Main function for the MFA command line interface """ check_third_party() hooks = ExitHooks() hooks.hook() atexit.register(hooks.history_save_handler) from colorama import init init() parser = create_parser() mp.freeze_support() args, unknown = parser.parse_known_args() for short in ["-c", "-d"]: if short in unknown: print( f"Due to the number of options that `{short}` could refer to, it is not accepted. " "Please specify the full argument", file=sys.stderr, ) sys.exit(1) try: if args.subcommand in ["g2p", "train_g2p"]: try: import pynini # noqa except ImportError: print( "There was an issue importing Pynini, please ensure that it is installed. If you are on Windows, " "please use the Windows Subsystem for Linux to use g2p functionality.", file=sys.stderr, ) sys.exit(1) if args.subcommand == "align": run_align_corpus(args, unknown) elif args.subcommand == "adapt": run_adapt_model(args, unknown) elif args.subcommand == "train": run_train_acoustic_model(args, unknown) elif args.subcommand == "g2p": run_g2p(args, unknown) elif args.subcommand == "train_g2p": run_train_g2p(args, unknown) elif args.subcommand == "validate": run_validate_corpus(args, unknown) elif args.subcommand == "validate_dictionary": run_validate_dictionary(args, unknown) elif args.subcommand in ["model", "models"]: run_model(args) elif args.subcommand == "train_lm": run_train_lm(args, unknown) elif args.subcommand == "train_dictionary": run_train_dictionary(args, unknown) elif args.subcommand == "train_ivector": run_train_ivector_extractor(args, unknown) elif args.subcommand == "classify_speakers": # pragma: no cover run_classify_speakers(args, unknown) elif args.subcommand in ["annotator", "anchor"]: run_anchor() elif args.subcommand == "transcribe": run_transcribe_corpus(args, unknown) elif args.subcommand == "create_segments": run_create_segments(args, unknown) elif args.subcommand == "configure": update_global_config(args) global GLOBAL_CONFIG GLOBAL_CONFIG = load_global_config() elif args.subcommand == "history": print_history(args) elif args.subcommand == "version": from montreal_forced_aligner.utils import get_mfa_version print(get_mfa_version()) elif args.subcommand == "thirdparty": # Deprecated command raise DeprecationWarning( "Necessary thirdparty executables are now installed via conda. Please refer to the installation docs for the updated commands." ) elif args.subcommand == "download": # Deprecated command raise DeprecationWarning( "Downloading models is now run through the `mfa model download` command, please use that instead." ) except MFAError as e: if getattr(args, "debug", False): raise print(e, file=sys.stderr) sys.exit(1)
def main(): mp.freeze_support() args, unknown = parser.parse_known_args() fix_path() if args.subcommand in ['align', 'train', 'train_ivector']: from montreal_forced_aligner.thirdparty.kaldi import validate_alignment_binaries if not validate_alignment_binaries(): print( "There was an issue validating Kaldi binaries, please ensure you've downloaded them via the " "'mfa thirdparty download' command. See 'mfa thirdparty validate' for more detailed information " "on why this check failed.") sys.exit(1) elif args.subcommand in ['transcribe']: from montreal_forced_aligner.thirdparty.kaldi import validate_transcribe_binaries if not validate_transcribe_binaries(): print( "There was an issue validating Kaldi binaries, please ensure you've downloaded them via the " "'mfa thirdparty download' command. See 'mfa thirdparty validate' for more detailed information " "on why this check failed. If you are on MacOS, please note that the thirdparty binaries available " "via the download command do not contain the transcription ones. To get this functionality working " "for the time being, please build kaldi locally and follow the instructions for running the " "'mfa thirdparty kaldi' command.") sys.exit(1) elif args.subcommand in ['train_dictionary']: from montreal_forced_aligner.thirdparty.kaldi import validate_train_dictionary_binaries if not validate_train_dictionary_binaries(): print( "There was an issue validating Kaldi binaries, please ensure you've downloaded them via the " "'mfa thirdparty download' command. See 'mfa thirdparty validate' for more detailed information " "on why this check failed. If you are on MacOS, please note that the thirdparty binaries available " "via the download command do not contain the train_dictionary ones. To get this functionality working " "for the time being, please build kaldi locally and follow the instructions for running the " "'mfa thirdparty kaldi' command.") sys.exit(1) elif args.subcommand in ['g2p', 'train_g2p']: try: import pynini except ImportError: print( "There was an issue importing Pynini, please ensure that it is installed. If you are on Windows, " "please use the Windows Subsystem for Linux to use g2p functionality." ) sys.exit(1) if args.subcommand == 'align': run_align_corpus(args, unknown, acoustic_languages) elif args.subcommand == 'train': run_train_corpus(args) elif args.subcommand == 'g2p': run_g2p(args, g2p_languages) elif args.subcommand == 'train_g2p': run_train_g2p(args) elif args.subcommand == 'validate': run_validate_corpus(args) elif args.subcommand == 'download': run_download(args) elif args.subcommand == 'train_lm': run_train_lm(args) elif args.subcommand == 'train_dictionary': run_train_dictionary(args) elif args.subcommand == 'train_ivector': run_train_ivector_extractor(args) elif args.subcommand == 'classify_speakers': run_classify_speakers(args) elif args.subcommand == 'annotator': from montreal_forced_aligner.command_line.annotator import run_annotator run_annotator(args) elif args.subcommand == 'thirdparty': run_thirdparty(args) elif args.subcommand == 'transcribe': run_transcribe_corpus(args) elif args.subcommand == 'create_segments': run_create_segments(args, unknown) elif args.subcommand == 'version': print(__version__) unfix_path()