Spaces:
Build error
Build error
Upload 82 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributes+4
- assets/f0/.gitattributesAdded
- assets/languages/en-US.jsonAdded+809
- assets/languages/vi-VN.jsonAdded+809
- assets/logs/mute/f0/mute.wav.npyAdded+3
- assets/logs/mute/f0_voiced/mute.wav.npyAdded+3
- assets/logs/mute/sliced_audios/mute32000.wavAdded+3
- assets/logs/mute/sliced_audios/mute40000.wavAdded+3
- assets/logs/mute/sliced_audios/mute44100.wavAdded+3
- assets/logs/mute/sliced_audios/mute48000.wavAdded+3
- assets/logs/mute/sliced_audios_16k/mute.wavAdded
- assets/logs/mute/v1_extracted/mute.npyAdded+3
- assets/logs/mute/v2_extracted/mute.npyAdded+3
- assets/models/embedders/.gitattributesAdded
- assets/models/predictors/.gitattributesAdded
- assets/models/pretrained_custom/.gitattributesAdded
- assets/models/pretrained_v1/.gitattributesAdded
- assets/models/pretrained_v2/.gitattributesAdded
- assets/models/uvr5/.gitattributesAdded
- assets/presets/.gitattributesAdded
- assets/weights/.gitattributesAdded
- audios/.gitattributesAdded
- dataset/.gitattributesAdded
- main/app/app.pyAdded
- main/app/tensorboard.pyAdded+30
- main/configs/config.jsonAdded+31
- main/configs/config.pyAdded+70
- main/configs/decrypt.binAdded+3
- main/configs/v1/32000.jsonAdded+46
- main/configs/v1/40000.jsonAdded+46
- main/configs/v1/44100.jsonAdded+46
- main/configs/v1/48000.jsonAdded+46
- main/configs/v2/32000.jsonAdded+42
- main/configs/v2/40000.jsonAdded+42
- main/configs/v2/44100.jsonAdded+42
- main/configs/v2/48000.jsonAdded+42
- main/inference/audio_effects.pyAdded+180
- main/inference/convert.pyAdded+680
- main/inference/create_dataset.pyAdded+240
- main/inference/create_index.pyAdded+100
- main/inference/extract.pyAdded+400
- main/inference/preprocess.pyAdded+270
- main/inference/separator_music.pyAdded+310
- main/inference/train.pyAdded+980
- main/library/algorithm/commons.pyAdded+60
- main/library/algorithm/modules.pyAdded+70
- main/library/algorithm/mrf_hifigan.pyAdded+170
- main/library/algorithm/onnx_export.pyAdded+40
- main/library/algorithm/refinegan.pyAdded+190
- main/library/algorithm/residuals.pyAdded+140
33 unmodified lines34353633 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/miku.png filter=lfs diff=lfs merge=lfs -text33 unmodified lines3435363738394033 unmodified lines*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/miku.png filter=lfs diff=lfs merge=lfs -textassets/logs/mute/sliced_audios/mute32000.wav filter=lfs diff=lfs merge=lfs -textassets/logs/mute/sliced_audios/mute40000.wav filter=lfs diff=lfs merge=lfs -textassets/logs/mute/sliced_audios/mute44100.wav filter=lfs diff=lfs merge=lfs -textassets/logs/mute/sliced_audios/mute48000.wav filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809{
"set_lang": "Display language set to {lang}.",
"no_support_gpu": "Unfortunately, no compatible GPU is available to support your training.",
"text": "text",
"upload_success": "File {name} uploaded successfully.",
"download_url": "Download from the link",
"download_from_csv": "Download from the CSV model repository",
"search_models": "Search models",
"upload": "Upload",
"option_not_valid": "Invalid option!",
"list_model": "Model list",
"success": "Completed!",
"index": "index",
"model": "model",
"zip": "compress",
"search": "search",
"provide_file": "Please provide a valid {filename} file!",
"start": "Starting {start}...",
"not_found": "Not found {name}.",
"found": "Found {results} results!",
"download_music": "download music",
"download": "download",
"provide_url": "Please provide a url.",
"provide_name_is_save": "Please provide a model name to save.",
"not_support_url": "Your model url is not supported.",
"error_occurred": "An error occurred: {e}.",
"not_model": "The file you uploaded is not a model file!",
"unable_analyze_model": "Unable to analyze the model!",
"download_pretrain": "Downloading pre-trained model...",
"provide_pretrain": "Please provide a pre-trained model url {dg}.",
"provide_hubert": "Please provide a url to the embedding model.",
"sr_not_same": "The sample rates of the two models are not the same.",
"architectures_not_same": "Cannot merge models. The architectures are not the same.",
"fushion_model": "model fusion",
"model_fushion_info": "The model {name} is fused from {pth_1} and {pth_2} with a ratio of {ratio}.",
"not_found_create_time": "Creation time not found.",
"format_not_valid": "Invalid format.",
"read_info": "Models trained on different applications may produce different information or may not be readable!",
"epoch": "epoch.",
"step": "step",
"sr": "Sample rate",
"f0": "pitch training",
"version": "version.",
"not_f0": "Pitch training not performed",
"trained_f0": "Pitch training performed",
"model_info": "Model Name: {model_name}\n\n Model Creator: {model_author}\n\nEpoch: {epochs}\n\nSteps: {steps}\n\nVersion: {version}\n\nSample Rate: {sr}\n\nPitch Training: {pitch_guidance}\n\nHash (ID): {model_hash}\n\nCreation Time: {creation_date_str}\n\nVocoder: {vocoder}\n",
"input_not_valid": "Please provide valid input!",
"output_not_valid": "Please provide valid output!",
"apply_effect": "apply effect",
"enter_the_text": "Please enter the text to speech!",
"choose_voice": "Please choose a voice!",
"convert": "Converting {name}...",
"separator_music": "music separation",
"notfound": "Not found",
"turn_on_use_audio": "Please enable using separated audio to proceed",
"turn_off_convert_backup": "Disable backup voice conversion to use the original voice",
"turn_off_merge_backup": "Disable merging backup voice to use the original voice",
"not_found_original_vocal": "Original vocal not found!",
"convert_vocal": "Converting voice...",
"convert_success": "Voice conversion completed!",
"convert_backup": "Converting backup voice...",
"convert_backup_success": "Backup voice conversion completed!",
"merge_backup": "Merging main voice with backup voice...",
"merge_success": "Merge completed.",
"is_folder": "Input is a folder: Converting all audio files in the folder...",
"not_found_in_folder": "No audio files found in the folder!",
"batch_convert": "Batch conversion in progress...",
"batch_convert_success": "Batch conversion successful!",
"create": "create",
"provide_name": "Please provide a model name.",
"not_found_data": "Data not found",
"not_found_data_preprocess": "Processed audio data not found, please reprocess.",
"not_found_data_extract": "Extracted audio data not found, please re-extract.",
"provide_pretrained": "Please provide pre-trained {dg}.",
"download_pretrained": "Download pre-trained {dg}{rvc_version} original",
"not_found_pretrain": "Pre-trained {dg} not found",
"not_use_pretrain": "No pre-trained model will be used",
"training": "training",
"display_title": "<h1> 🎵 Voice conversion and training interface created by Anh 🎵 <h1>",
"rick_roll": "Click here if you want to be Rick Roll :) ---> [RickRoll]({rickroll})",
"terms_of_use": "**Please do not use the project for any unethical, illegal, or harmful purposes to individuals or organizations...**",
"exemption": "**In cases where users do not comply with the terms or violate them, I will not be responsible for any claims, damages, or liabilities, whether in contract, negligence, or other causes arising from, outside of, or related to the software, its use, or other transactions associated with it.**",
"separator_tab": "Music Separation",
"4_part": "A simple music separation system can separate into 4 parts: Instruments, Vocals, Main vocals, Backup vocals",
"clear_audio": "Clean audio",
"separator_backing": "Separate backup vocals",
"denoise_mdx": "Denoise MDX separation",
"use_mdx": "Use MDX",
"dereveb_audio": "Remove vocal reverb",
"dereveb_backing": "Remove backup reverb",
"separator_model": "Music separation model",
"separator_backing_model": "Backup separation model",
"shift": "Shift",
"shift_info": "Higher is better quality but slower and uses more resources",
"segments_size": "Segments Size",
"segments_size_info": "Higher is better quality but uses more resources",
"batch_size": "Batch size",
"batch_size_info": "Number of samples processed simultaneously in one training cycle. Higher can cause memory overflow",
"mdx_batch_size_info": "Number of samples processed at a time. Batch processing optimizes calculations. Large batches can cause memory overflow; small batches reduce resource efficiency",
"overlap": "Overlap",
"overlap_info": "Overlap amount between prediction windows",
"export_format": "Export format",
"export_info": "The export format to export the audio file in",
"output_separator": "Separated output",
"hop_length_info": "Analyzing the time transfer window when performing transformations is allowed. The detailed value is compact but requires more calculation",
"drop_audio": "Drop audio here",
"drop_text": "Drop text file here",
"use_url": "YouTube link",
"url_audio": "Link audio",
"downloads": "Downloads",
"clean_strength": "Audio cleaning strength",
"clean_strength_info": "Strength of the audio cleaner for filtering vocals during export",
"input_output": "Audio input, output",
"audio_path": "Input audio path",
"refesh": "Refresh",
"output_folder": "Output audio folder path",
"output_folder_info": "Enter the folder path where the audio will be exported",
"input_audio": "Audio input",
"instruments": "Instruments",
"original_vocal": "Original vocal",
"main_vocal": "Main vocal",
"backing_vocal": "Backup vocal",
"convert_audio": "Convert Audio",
"convert_info": "Convert audio using a trained voice model",
"autotune": "Auto-tune",
"use_audio": "Use separated audio",
"convert_original": "Convert original voice",
"convert_backing": "Convert backup voice",
"not_merge_backing": "Do not merge backup voice",
"merge_instruments": "Merge instruments",
"pitch": "Pitch",
"pitch_info": "Recommendation: set to 12 to change male voice to female and vice versa",
"model_accordion": "Model and index",
"model_name": "Model file",
"index_path": "Index file",
"index_strength": "Index strength",
"index_strength_info": "Higher values increase strength. However, lower values may reduce artificial effects in the audio",
"output_path": "Audio output path",
"output_path_info": "Enter the output path (leave it as .wav format; it will auto-correct during conversion)",
"setting": "General settings",
"f0_method": "Extraction method",
"f0_method_info": "Method used for data extraction",
"f0_method_hybrid": "HYBRID extraction method",
"f0_method_hybrid_info": "Combination of two or more different types of extracts",
"hubert_model": "Embedding model",
"hubert_info": "Pre-trained model to assist embedding",
"modelname": "Model name",
"modelname_info": "If you have your own model, just upload it and input the name here",
"split_audio": "Split audio",
"autotune_rate": "Auto-tune rate",
"autotune_rate_info": "Level of auto-tuning adjustment",
"resample": "Resample",
"resample_info": "Resample post-processing to the final sample rate; 0 means no resampling, NOTE: SOME FORMATS DO NOT SUPPORT SPEEDS OVER 48000",
"filter_radius": "Filter radius",
"filter_radius_info": "If greater than three, median filtering is applied. The value represents the filter radius and can reduce breathiness or noise.",
"volume_envelope": "Volume envelope",
"volume_envelope_info": "Use the input volume envelope to replace or mix with the output volume envelope. The closer to 1, the more the output envelope is used",
"protect": "Consonant protection",
"protect_info": "Protect distinct consonants and breathing sounds to prevent audio tearing and other artifacts. Increasing this value provides comprehensive protection. Reducing it may reduce protection but also minimize indexing effects",
"output_convert": "Converted audio",
"main_convert": "Convert main voice",
"main_or_backing": "Main voice + Backup voice",
"voice_or_instruments": "Voice + Instruments",
"convert_text": "Convert Text",
"convert_text_markdown": "## Convert Text to Speech",
"convert_text_markdown_2": "Convert text to speech and read aloud using the trained voice model",
"input_txt": "Input data from a text file (.txt)",
"text_to_speech": "Text to read",
"voice_speed": "Reading speed",
"voice_speed_info": "Speed of the voice",
"tts_1": "1. Convert Text to Speech",
"tts_2": "2. Convert Speech",
"voice": "Voices by country",
"output_tts": "Output speech path",
"output_tts_convert": "Converted speech output path",
"tts_output": "Enter the output path",
"output_tts_markdown": "Unconverted and converted audio",
"output_text_to_speech": "Generated speech from text-to-speech conversion",
"output_file_tts_convert": "Speech converted using the model",
"output_audio": "Audio output",
"provide_output": "Enter the output path",
"audio_effects": "Audio Effects",
"apply_audio_effects": "## Add Additional Audio Effects",
"audio_effects_edit": "Add effects to audio",
"reverb": "Reverb effect",
"chorus": "Chorus effect",
"delay": "Delay effect",
"more_option": "Additional options",
"phaser": "Phaser effect",
"compressor": "Compressor effect",
"apply": "Apply",
"reverb_freeze": "Freeze mode",
"reverb_freeze_info": "Create a continuous echo effect when this mode is enabled",
"room_size": "Room size",
"room_size_info": "Adjust the room space to create reverberation",
"damping": "Damping",
"damping_info": "Adjust the level of absorption to control the amount of reverberation",
"wet_level": "Reverb signal level",
"wet_level_info": "Adjust the level of the reverb signal effect",
"dry_level": "Original signal level",
"dry_level_info": "Adjust the level of the signal without effects",
"width": "Audio width",
"width_info": "Adjust the width of the audio space",
"chorus_depth": "Chorus depth",
"chorus_depth_info": "Adjust the intensity of the chorus to create a wider sound",
"chorus_rate_hz": "Frequency",
"chorus_rate_hz_info": "Adjust the oscillation speed of the chorus effect",
"chorus_mix": "Mix signals",
"chorus_mix_info": "Adjust the mix level between the original and the processed signal",
"chorus_centre_delay_ms": "Center delay (ms)",
"chorus_centre_delay_ms_info": "The delay time between stereo channels to create the chorus effect",
"chorus_feedback": "Feedback",
"chorus_feedback_info": "Adjust the amount of the effect signal fed back into the original signal",
"delay_seconds": "Delay time",
"delay_seconds_info": "Adjust the delay time between the original and the processed signal",
"delay_feedback": "Delay feedback",
"delay_feedback_info": "Adjust the amount of feedback signal, creating a repeating effect",
"delay_mix": "Delay signal mix",
"delay_mix_info": "Adjust the mix level between the original and delayed signal",
"fade": "Fade effect",
"bass_or_treble": "Bass and treble",
"limiter": "Threshold limiter",
"distortion": "Distortion effect",
"gain": "Audio gain",
"bitcrush": "Bit reduction effect",
"clipping": "Clipping effect",
"fade_in": "Fade-in effect (ms)",
"fade_in_info": "Time for the audio to gradually increase from 0 to normal level",
"fade_out": "Fade-out effect (ms)",
"fade_out_info": "the time it takes for the sound to fade from normal to zero",
"bass_boost": "Bass boost level (dB)",
"bass_boost_info": "amount of bass boost in audio track",
"bass_frequency": "Low-pass filter cutoff frequency (Hz)",
"bass_frequency_info": "frequencies are reduced. Low frequencies make the bass clearer",
"treble_boost": "Treble boost level (dB)",
"treble_boost_info": "high level of sound reinforcement in the audio track",
"treble_frequency": "High-pass filter cutoff frequency (Hz)",
"treble_frequency_info": "The frequency will be filtered out. The higher the frequency, the higher the sound will be retained.",
"limiter_threashold_db": "Limiter threshold",
"limiter_threashold_db_info": "Limit the maximum audio level to prevent it from exceeding the threshold",
"limiter_release_ms": "Release time",
"limiter_release_ms_info": "Time for the audio to return after being limited (Mili Seconds)",
"distortion_info": "Adjust the level of distortion to create a noisy effect",
"gain_info": "Adjust the volume level of the signal",
"clipping_threashold_db": "Clipping threshold",
"clipping_threashold_db_info": "Trim signals exceeding the threshold, creating a distorted sound",
"bitcrush_bit_depth": "Bit depth",
"bitcrush_bit_depth_info": "Reduce audio quality by decreasing bit depth, creating a distorted effect",
"phaser_depth": "Phaser depth",
"phaser_depth_info": "Adjust the depth of the effect, impacting its intensity",
"phaser_rate_hz": "Frequency",
"phaser_rate_hz_info": "Adjust the frequency of the phaser effect",
"phaser_mix": "Mix signal",
"phaser_mix_info": "Adjust the mix level between the original and processed signals",
"phaser_centre_frequency_hz": "Center frequency",
"phaser_centre_frequency_hz_info": "The center frequency of the phaser effect, affecting the adjusted frequencies",
"phaser_feedback": "Feedback",
"phaser_feedback_info": "Adjust the feedback level of the effect, creating a stronger or lighter phaser feel",
"compressor_threashold_db": "Compressor threshold",
"compressor_threashold_db_info": "The threshold level above which the audio will be compressed",
"compressor_ratio": "Compression ratio",
"compressor_ratio_info": "Adjust the level of audio compression when exceeding the threshold",
"compressor_attack_ms": "Attack time (ms)",
"compressor_attack_ms_info": "Time for compression to start taking effect after the audio exceeds the threshold",
"compressor_release_ms": "Release time",
"compressor_release_ms_info": "Time for the audio to return to normal after being compressed",
"create_dataset_url": "Link to audio (use commas for multiple links)",
"createdataset": "Create dataset",
"create_dataset_markdown": "## Create Dataset training from YouTube",
"create_dataset_markdown_2": "Process and create training datasets using YouTube links",
"denoise": "Denoise",
"skip": "Skip",
"model_ver": "Voice separation version",
"model_ver_info": "The model version for separating vocals",
"create_dataset_info": "Dataset creation information",
"output_data": "Dataset output",
"output_data_info": "Output data after creation",
"skip_start": "Skip beginning",
"skip_start_info": "Skip the initial seconds of the audio; use commas for multiple audios",
"skip_end": "Skip end",
"skip_end_info": "Skip the final seconds of the audio; use commas for multiple audios",
"training_model": "Train Model",
"training_markdown": "Train and build a voice model with a set of voice data",
"training_model_name": "Name of the model during training (avoid special characters or spaces)",
"sample_rate": "Sample rate",
"sample_rate_info": "Sample rate of the model",
"training_version": "Model version",
"training_version_info": "Version of the model during training",
"training_pitch": "Pitch Guidance",
"upload_dataset": "Upload dataset",
"preprocess_effect": "Post processing",
"clear_dataset": "Clean dataset",
"preprocess_info": "Preprocessing information",
"preprocess_button": "1. Processing",
"extract_button": "2. Extract",
"extract_info": "Data extraction information",
"total_epoch": "Total epochs",
"total_epoch_info": "Total training epochs",
"save_epoch": "Save frequency",
"save_epoch_info": "Frequency of saving the model during training to allow retraining",
"create_index": "Create index",
"index_algorithm": "Index algorithm",
"index_algorithm_info": "Algorithm for creating the index",
"custom_dataset": "Custom dataset folder",
"custom_dataset_info": "Custom dataset folder for training data",
"overtraining_detector": "Overtraining detector",
"overtraining_detector_info": "Check for overtraining during model training",
"cleanup_training": "Clean Up",
"cleanup_training_info": "Only enable if you need to retrain the model from scratch.",
"cache_in_gpu": "Cache in GPU",
"cache_in_gpu_info": "Store the model in GPU cache memory",
"dataset_folder": "Folder containing dataset",
"threshold": "Overtraining threshold",
"setting_cpu_gpu": "CPU/GPU settings",
"gpu_number": "Number of GPUs used",
"gpu_number_info": "Number of GPUs used during training",
"save_only_latest": "Save only the latest",
"save_only_latest_info": "Save only the latest D and G models",
"save_every_weights": "Save all models",
"save_every_weights_info": "Save all models after each epoch",
"gpu_info": "GPU information",
"gpu_info_2": "Information about the GPU used during training",
"cpu_core": "Number of CPU cores available",
"cpu_core_info": "Number of CPU cores used during training",
"not_use_pretrain_2": "Do not use pretraining",
"not_use_pretrain_info": "Do not use pre-trained models",
"custom_pretrain": "Custom pretraining",
"custom_pretrain_info": "Customize pre-training settings",
"pretrain_file": "Pre-trained model file {dg}",
"train_info": "Training information",
"export_model": "5. Export Model",
"zip_model": "2. Compress model",
"output_zip": "Output file after compression",
"model_path": "Model path",
"model_ratio": "Model ratio",
"model_ratio_info": "Adjusting towards one side will make the model more like that side",
"output_model_path": "Model output path",
"fushion": "Model Fusion",
"fushion_markdown": "## Fushion Two Models",
"fushion_markdown_2": "Combine two voice models into a single model",
"read_model": "Read Information",
"read_model_markdown": "## Read Model Information",
"read_model_markdown_2": "Retrieve recorded information within the model",
"drop_model": "Drop model here",
"readmodel": "Read model",
"model_path_info": "Enter the path to the model file",
"modelinfo": "Model Information",
"download_markdown": "## Download Model",
"download_markdown_2": "Download voice models, pre-trained models, and embedding models",
"model_download": "Download voice model",
"model_url": "Link to the model",
"15s": "Please wait about 15 seconds. The system will restart automatically!",
"model_download_select": "Choose a model download method",
"model_warehouse": "Model repository",
"get_model": "Retrieve model",
"name_to_search": "Name to search",
"search_2": "Search",
"select_download_model": "Choose a searched model (Click to select)",
"download_pretrained_2": "Download pre-trained model",
"only_huggingface": "Supports only huggingface.co",
"pretrained_url": "Pre-trained model link {dg}",
"select_pretrain": "Choose pre-trained model",
"select_pretrain_info": "Choose a pre-trained model to download",
"pretrain_sr": "Model sample rate",
"drop_pretrain": "Drop pre-trained model {dg} here",
"hubert_download": "Download embedding model",
"hubert_url": "Link to embedding model",
"drop_hubert": "Drop embedding model here",
"settings": "Settings",
"settings_markdown": "## Additional Settings",
"settings_markdown_2": "Customize additional features of the project",
"lang": "Language",
"lang_restart": "The display language in the project (When changing the language, the system will automatically restart after 15 seconds to update)",
"change_lang": "Change Language",
"theme": "Theme",
"theme_restart": "Theme type displayed in the interface (When changing the theme, the system will automatically restart after 15 seconds to update)",
"theme_button": "Change Theme",
"change_light_dark": "Switch Light/Dark Mode",
"tensorboard_url": "Tensorboard URL",
"errors_loading_audio": "Error loading audio: {e}",
"apply_error": "An error occurred while applying effects: {e}",
"indexpath": "Index path",
"split_total": "Total parts split",
"process_audio_error": "An error occurred while processing the audio",
"merge_error": "An error occurred while merging audio",
"not_found_convert_file": "Processed file not found",
"convert_batch": "Batch conversion...",
"found_audio": "Found {audio_files} audio files for conversion.",
"not_found_audio": "No audio files found!",
"error_convert": "An error occurred during audio conversion: {e}",
"error_convert_batch": "An error occurred during the conversion of audio segments: {e}",
"error_convert_batch_2": "An error occurred during batch audio conversion: {e}",
"convert_batch_success": "Batch conversion completed successfully in {elapsed_time} seconds. {output_path}",
"convert_audio_success": "File {input_path} converted successfully in {elapsed_time} seconds. {output_path}",
"hybrid_methods": "Estimating f0 pitch using methods {methods}",
"method_not_valid": "Invalid method",
"read_faiss_index_error": "An error occurred while reading the FAISS index: {e}",
"read_model_error": "Failed to load model: {e}",
"starting_download": "Starting download",
"version_not_valid": "Invalid vocal separation version",
"skip<audio": "Cannot skip as skip time is less than audio file length",
"skip>audio": "Cannot skip as skip time is greater than audio file length",
"=<0": "Skip time is less than or equal to 0 and has been skipped",
"skip_warning": "Skip duration ({seconds} seconds) exceeds audio length ({total_duration} seconds). Skipping.",
"download_success": "Download completed successfully",
"create_dataset_error": "An error occurred while creating the training dataset",
"create_dataset_success": "Training dataset creation completed in {elapsed_time} seconds",
"skip_start_audio": "Successfully skipped start of audio: {input_file}",
"skip_end_audio": "Successfully skipped end of audio: {input_file}",
"merge_audio": "Merged all parts containing audio",
"separator_process": "Separating vocals: {input}...",
"not_found_main_vocal": "Main vocal not found!",
"not_found_backing_vocal": "Backup vocal not found!",
"not_found_instruments": "Instruments not found",
"merge_instruments_process": "Merging vocals with instruments...",
"dereverb": "Removing vocal reverb",
"dereverb_success": "Successfully removed vocal reverb",
"save_index": "Index file saved",
"create_index_error": "An error occurred while creating the index",
"sr_not_16000": "Sample rate must be 16000",
"gpu_not_valid": "Invalid GPU index. Switching to CPU.",
"extract_file_error": "An error occurred while extracting the file",
"extract_f0_method": "Starting pitch extraction using {num_processes} cores with method {f0_method}...",
"extract_f0": "Pitch Extraction",
"extract_f0_success": "Pitch extraction completed in {elapsed_time} seconds.",
"NaN": "contains NaN values and will be ignored.",
"start_extract_hubert": "Starting Embedding extraction...",
"not_found_audio_file": "Audio file not found. Please ensure you provided the correct audio.",
"process_error": "An error occurred during processing",
"extract_hubert_success": "Embedding extraction completed in {elapsed_time} seconds.",
"export_process": "Model path",
"extract_error": "An error occurred during data extraction",
"extract_success": "Data extraction successful",
"min_length>=min_interval>=hop_size": "min_length must be greater than or equal to min_interval and hop_size",
"max_sil_kept>=hop_size": "max_sil_kept must be greater than or equal to hop_size",
"start_preprocess": "Starting data preprocessing with {num_processes} cores...",
"not_integer": "Voice ID folder must be an integer; instead got",
"preprocess_success": "Preprocessing completed in {elapsed_time} seconds.",
"preprocess_model_success": "Preprocessing data for the model completed successfully",
"turn_on_dereverb": "Reverb removal for backup vocals requires enabling reverb removal",
"turn_on_separator_backing": "Backup vocal separation requires enabling vocal separation",
"backing_model_ver": "Backup vocal separation model version",
"clean_audio_success": "Audio cleaned successfully!",
"separator_error": "An error occurred during music separation",
"separator_success": "Music separation completed in {elapsed_time} seconds",
"separator_process_2": "Processing music separation",
"separator_success_2": "Music separation successful!",
"separator_process_backing": "Processing backup vocal separation",
"separator_process_backing_success": "Backup vocal separation successful!",
"process_original": "Processing original vocal reverb removal...",
"process_original_success": "Original vocal reverb removal successful!",
"process_main": "Processing main vocal reverb removal...",
"process_main_success": "Main vocal reverb removal successful!",
"process_backing": "Processing backup vocal reverb removal...",
"process_backing_success": "Backup vocal reverb removal successful!",
"save_every_epoch": "Save model after: ",
"total_e": "Total epochs: ",
"dorg": "Pre-trained G: {pretrainG} | Pre-trained D: {pretrainD}",
"training_f0": "Pitch Guidance",
"not_gpu": "No GPU detected, reverting to CPU (not recommended)",
"not_found_checkpoint": "Checkpoint file not found: {checkpoint_path}",
"save_checkpoint": "Reloaded checkpoint '{checkpoint_path}' (epoch {checkpoint_dict})",
"save_model": "Saved model '{checkpoint_path}' (epoch {iteration})",
"sr_does_not_match": "{sample_rate} Sample rate does not match target {sample_rate2} Sample rate",
"spec_error": "An error occurred while retrieving specifications from {spec_filename}: {e}",
"time_or_speed_training": "time={current_time} | training speed={elapsed_time_str}",
"savemodel": "Saved model '{model_dir}' (epoch {epoch} and step {step})",
"model_author": "Credit model to {model_author}",
"unregistered": "Model unregistered",
"not_author": "Model not credited",
"training_author": "Model creator name",
"training_author_info": "To credit the model, enter your name here",
"extract_model_error": "An error occurred while extracting the model",
"start_training": "Starting training",
"import_pretrain": "Loaded pre-trained model ({dg}) '{pretrain}'",
"not_using_pretrain": "No pre-trained model ({dg}) will be used",
"training_warning": "WARNING: Generated loss is lower than the lower threshold loss for the next epoch.",
"overtraining_find": "Overtraining detected at epoch {epoch} with smoothed generator loss {smoothed_value_gen} and smoothed discriminator loss {smoothed_value_disc}",
"best_epoch": "New best epoch {epoch} with smoothed generator loss {smoothed_value_gen} and smoothed discriminator loss {smoothed_value_disc}",
"success_training": "Training completed with {epoch} epochs, {global_step} steps, and {loss_gen_all} total generator loss.",
"training_info": "Lowest generator loss: {lowest_value_rounded} at epoch {lowest_value_epoch}, step {lowest_value_step}",
"model_training_info": "{model_name} | epoch={epoch} | step={global_step} | {epoch_recorder} | lowest value={lowest_value_rounded} (epoch {lowest_value_epoch} and step {lowest_value_step}) | remaining epochs for overtraining: g/total: {remaining_epochs_gen} d/total: {remaining_epochs_disc} | smoothed generator loss={smoothed_value_gen} | smoothed discriminator loss={smoothed_value_disc}",
"model_training_info_2": "{model_name} | epoch={epoch} | step={global_step} | {epoch_recorder} | lowest value={lowest_value_rounded} (epoch {lowest_value_epoch} and step {lowest_value_step})",
"model_training_info_3": "{model_name} | epoch={epoch} | step={global_step} | {epoch_recorder}",
"training_error": "An error occurred while training the model:",
"separator_info": "Initializing with output path: {output_dir}, output format: {output_format}",
"output_dir_is_none": "Output folder not specified. Using current working directory.",
">0or=1": "Normalization threshold must be greater than 0 and less than or equal to 1.",
"output_single": "Single root output requested; only one file ({output_single_stem}) will be written",
"step2": "The second step will be reversed using spectrogram instead of waveform. This may improve quality but is slightly slower.",
"name_ver": "Version {name}",
"os": "Operating System",
"platform_info": "System: {system_info} Name: {node} Release: {release} Machine: {machine} Processor: {processor}",
"none_ffmpeg": "FFmpeg is not installed. Please install FFmpeg to use this package.",
"install_onnx": "ONNX Runtime package {pu} installed with version",
"running_in_cpu": "Unable to configure hardware acceleration, running in CPU mode",
"running_in_cuda": "CUDA available in Torch, setting Torch device to CUDA",
"onnx_have": "ONNXruntime available {have}, enabling acceleration",
"onnx_not_have": "{have} not available in ONNXruntime; acceleration will NOT be enabled",
"python_not_install": "Python package: {package_name} is not installed",
"hash": "Calculating hash for model file {model_path}",
"ioerror": "IOError while seeking -10 MB or reading model file to compute hash: {e}",
"cancel_download": "File already exists at {output_path}, skipping download",
"download_model": "Downloading file from {url} to {output_path} with a timeout of 300 seconds",
"download_error": "Failed to download file from {url}, response code: {status_code}",
"vip_model": "Model: '{model_friendly_name}' is a premium model intended by Anjok07 only for paid subscriber access.",
"vip_print": "Hey there, if you haven't subscribed, please consider supporting UVR's developer, Anjok07, by subscribing here: https://patreon.com/uvr",
"search_model": "Searching for model {model_filename} in the list of supported models in the group",
"load_download_json": "Downloaded model list loaded",
"single_model": "Identified single model file: {model_friendly_name}",
"not_found_model": "Model not found in the UVR repository, attempting to download from the audio model separation repository...",
"single_model_path": "Returning path for single model file: {model_path}",
"find_model": "Input file name {model_filename} found in multi-file model: {model_friendly_name}",
"find_models": "Identified multi-file model: {model_friendly_name}, iterating through files to download",
"find_path": "Attempting to determine download PATH for config pair",
"not_found_model_warehouse": "Model not found in the UVR repository, attempting to download from the audio model separation repository...",
"yaml_warning": "The model name you specified, {model_filename}, is actually a model config file rather than a model file.",
"yaml_warning_2": "We found a model matching this config file: {config_key}, so we'll use that model file for this run.",
"yaml_warning_3": "To avoid confusing/inconsistent behavior in the future, specify the actual model file name instead.",
"yaml_debug": "Config YAML model file not found in UVR repository, attempting to download from the audio model separation repository...",
"download_model_friendly": "All files downloaded for model {model_friendly_name}, returning original path {model_path}",
"not_found_model_2": "Model file {model_filename} not found in the supported files",
"load_yaml": "Loading model data from YAML at path {model_data_yaml_filepath}",
"load_yaml_2": "Model data loaded from YAML file: {model_data}",
"hash_md5": "Computing MD5 hash for model file to identify model parameters from UVR data...",
"model_hash": "Model {model_path} has hash {model_hash}",
"mdx_data": "MDX model data path set to {mdx_model_data_path}",
"load_mdx": "Loading MDX model parameters from UVR model data file...",
"model_not_support": "Unsupported model file: no parameters found for MD5 hash {model_hash} in UVR model data for MDX vault.",
"uvr_json": "Model data loaded from UVR JSON with hash {model_hash}: {model_data}",
"loading_model": "Loading model {model_filename}...",
"download_model_friendly_2": "Downloaded model, friendly name: {model_friendly_name}, Model path: {model_path}",
"model_type_not_support": "Unsupported model type: {model_type}",
"demucs_not_support_python<3.10": "Demucs models require Python version 3.10 or higher.",
"import_module": "Importing module for model type",
"initialization": "Initializing separator class for model type",
"loading_model_success": "Model loading completed.",
"loading_model_duration": "Model loading duration",
"starting_separator": "Starting separation process for audio file path",
"normalization": "Normalization threshold set to {normalization_threshold}, waveform will be scaled down to this maximum amplitude to prevent clipping.",
"loading_separator_model": "Downloading model {model_filename}...",
"separator_success_3": "Separation process completed.",
"separator_duration": "Separation duration",
"downloading_model": "Downloaded model, type: {model_type}, friendly name: {model_friendly_name}, Model path: {model_path}, Model data: {model_data_dict_size} items",
"demucs_info": "Demucs parameters: Segment size = {segment_size}, Segment size active = {segments_enabled}",
"demucs_info_2": "Demucs parameters: Number of predictions = {shifts}, Overlap = {overlap}",
"start_demucs": "Demucs Separator initialization completed",
"start_separator": "Starting separation process...",
"prepare_mix": "Preparing mixture...",
"demix": "Mixture prepared for demixing. Shape: {shape}",
"cancel_mix": "Loading model for demixing...",
"model_review": "Model loaded and set to evaluation mode.",
"del_gpu_cache_after_demix": "Cleared model and GPU cache after demixing.",
"process_output_file": "Processing output file...",
"source_length": "Processing source array, source length is {source_length}",
"process_ver": "Processing source version...",
"set_map": "Set source map to {part} parts...",
"process_all_part": "Processing for all root parts...",
"skip_part": "Skipping root part {stem_name} as out_single_stem is set to {output_single_stem}...",
"starting_demix_demucs": "Starting the demix process in demix_demucs...",
"model_infer": "Running model inference...",
"name_not_pretrained": "{name} is not a pre-trained model or a model bundle.",
"invalid_checksum": "Invalid checksum for file {path}, expected {checksum} but got {actual_checksum}",
"mdx_info": "MDX parameters: Batch size = {batch_size}, Segment size = {segment_size}",
"mdx_info_2": "MDX parameters: Overlap = {overlap}, Hop_length = {hop_length}, Denoising enabled = {enable_denoise}",
"mdx_info_3": "MDX parameters",
"load_model_onnx": "Loading ONNX model for inference...",
"load_model_onnx_success": "Successfully loaded model using ONNXruntime inference session.",
"onnx_to_pytorch": "Model converted from ONNX to PyTorch due to mismatched segment size with dim_t, processing may be slower.",
"stft": "Inverse STFT applied. Returning result with shape",
"no_denoise": "Model running on spectrum without denoising.",
"mix": "Preparing mix for input audio file {audio_file_path}...",
"normalization_demix": "Normalizing mix prior to demixing...",
"mix_success": "Mix preparation completed.",
"primary_source": "Normalizing primary source...",
"secondary_source": "Producing secondary source: Mixing in compatible mode",
"invert_using_spec": "Inverting secondary stem using spectrum when invert_USE_spec is set to True",
"invert_using_spec_2": "Inverting secondary stem by subtracting transformed stem from the initial transformed mix",
"enable_denoise": "Model running on both positive and negative spectrums for denoising.",
"is_match_mix": "is_match_mix: Predicted spectrum obtained directly from STFT output.",
"save_secondary_stem_output_path": "Saving secondary stem {stem_name} to {stem_output_path}...",
"starting_model": "Initializing model settings...",
"input_info": "Model input parameters",
"model_settings": "Model settings",
"initialize_mix": "Initializing mix with is_ckpt = {is_ckpt}. Initial mix shape: {shape}",
"!=2": "Expected 2-channel audio signal but got {shape} channels",
"process_check": "Processing in checkpoint mode...",
"stft_2": "STFT applied to mix. Spectrum shape: {shape}",
"cache": "Computed padding",
"shape": "Mix shape after padding: {shape}, Number of parts: {num_chunks}",
"process_no_check": "Processing in no-checkpoint mode...",
"n_sample_or_pad": "Number of samples: {n_sample}, Computed padding: {pad}",
"shape_2": "Mix shape after padding",
"process_part": "Processed part {mix_waves}: Start {i}, End {ii}",
"mix_waves_to_tensor": "Converted mix_waves to tensor. Tensor shape: {shape}",
"mix_match": "Mix mode Match; applying compensation factor.",
"tar_waves": "tar_waves. Shape",
"normalization_2": "Normalizing result by dividing it by divisor.",
"mix_wave": "Processing mix_wave batch",
"mix_or_batch": "Mix parts into batches. Number of batches",
"demix_is_match_mix": "Starting demix process with is_match_mix,",
"mix_shape": "Root mix parts stored. Shape",
"chunk_size_or_overlap": "Chunk size for compatible mixing: {chunk_size}, Overlap: {overlap}",
"chunk_size_or_overlap_standard": "Standard chunk size: {chunk_size}, Overlap: {overlap}",
"calc_size": "Generated size calculated",
"window": "Window applied to this segment.",
"process_part_2": "Processing segment {total}/{total_chunks}: Start {start}, End {end}",
"all_process_part": "Total segments to process",
"step_or_overlap": "Step size to process parts: {step} with overlap set to {overlap}.",
"mix_cache": "Mix prepared with padding. Mix shape",
"dims": "Cannot use sin/cos position encoding with odd dimensions (dim={dims})",
"activation": "activation must be relu/gelu, not {activation}",
"length_or_training_length": "Provided length {length} exceeds training duration {training_length}",
"type_not_valid": "Invalid type for",
"del_parameter": "Removing non-existent parameter ",
"info": "Common parameters: Model name = {model_name}, Model path = {model_path}",
"info_2": "Common parameters: Output path = {output_dir}, Output format = {output_format}",
"info_3": "Common parameters: Normalization threshold = {normalization_threshold}",
"info_4": "Common parameters: Denoising enabled = {enable_denoise}, Single stem output = {output_single_stem}",
"info_5": "Common parameters: Inversion using specs = {invert_using_spec}, Sample rate = {sample_rate}",
"info_6": "Common parameters: Primary root name = {primary_stem_name}, Secondary root name = {secondary_stem_name}",
"info_7": "Common parameters: Karaoke mode = {is_karaoke}, BV model = {is_bv_model}, BV model rebalancing = {bv_model_rebalance}",
"success_process": "Completed processing root {stem_name} and writing audio...",
"load_audio": "Loading audio from file",
"load_audio_success": "Audio loaded. Sample rate: {sr}, Audio shape: {shape}",
"convert_mix": "Converting provided mix array.",
"convert_shape": "Converted mix shape: {shape}",
"audio_not_valid": "Audio file {audio_path} is empty or invalid",
"audio_valid": "Audio file is valid and contains data.",
"mix_single": "Mix is mono. Converting to stereo.",
"convert_mix_audio": "Converted to stereo mix.",
"mix_success_2": "Mix preparation completed.",
"duration": "Audio duration is {duration_hours} hours ({duration_seconds} seconds).",
"write": "Using {name} to write.",
"write_audio": "Writing {name} with root path:",
"original_not_valid": "Warning: Original source array is nearly silent or empty.",
"shape_audio": "Audio data shape before processing",
"convert_data": "Data type before conversion",
"original_source_to_int16": "Converted original_source to int16.",
"shape_audio_2": "Interleaved audio data shape",
"create_audiosegment": "Successfully created AudioSegment.",
"create_audiosegment_error": "Specific error while creating AudioSegment",
"export_error": "Error exporting audio file",
"export_success": "Successfully exported audio file to",
"clean": "Running garbage collection...",
"clean_cache": "Clearing {name} cache...",
"del_path": "Deleting path, source, and root of input audio file...",
"not_success": "Process was not successful: ",
"resample_error": "Error during resampling",
"shapes": "Shapes",
"wav_resolution": "Resolution type",
"warnings": "Warning: Extremely aggressive values detected",
"warnings_2": "Warning: NaN or infinite values detected in wave input. Shape",
"process_file": "Processing file... \n",
"save_instruments": "Saving reverse track...",
"assert": "Audio files must have the same shape - Mix: {mixshape}, Inst: {instrumentalshape}",
"rubberband": "Rubberband CLI cannot be executed. Please ensure Rubberband-CLI is installed.",
"rate": "Rate must be strictly positive",
"gdown_error": "Could not retrieve the public link for the file. You may need to change its permissions to 'Anyone with the link' or there may already be excessive access permissions.",
"to": "To:",
"gdown_value_error": "A path or ID must be specified",
"missing_url": "URL is missing",
"mac_not_match": "MAC does not match",
"file_not_access": "File is not accessible",
"int_resp==-3": "Request failed, retrying",
"search_separate": "Search for separate files...",
"found_choice": "Found {choice}",
"separator==0": "No separate files found!",
"select_separate": "Select separate files",
"start_app": "Starting interface...",
"provide_audio": "Enter the path to the audio file",
"set_torch_mps": "Set Torch device to MPS",
"googletts": "Convert text using Google",
"pitch_info_2": "Pitch adjustment for text-to-speech converter",
"waveform": "Waveform must have the shape (# frames, # channels)",
"freq_mask_smooth_hz": "freq_mask_smooth_hz must be at least {hz}Hz",
"time_mask_smooth_ms": "time_mask_smooth_ms must be at least {ms}ms",
"x": "x must be greater",
"xn": "xn must be greater",
"not_found_pid": "No processes found!",
"end_pid": "Process terminated!",
"clean_audios": "Starting audio cleanup...",
"clean_audios_success": "Audio file cleanup complete!",
"clean_separate": "Starting cleanup of separation model...",
"clean_separate_success": "Separation model cleanup complete!",
"clean_model": "Starting model cleanup...",
"clean_model_success": "Model file cleanup complete!",
"clean_index": "Starting index cleanup...",
"clean_index_success": "Index file cleanup complete!",
"clean_pretrain": "Starting pretrained model cleanup...",
"clean_pretrain_success": "Pretrained model cleanup complete!",
"clean_all_audios": "Starting cleanup of all audio files...",
"clean_all_audios_success": "All audio file cleanup complete!",
"not_found_separate_model": "No separation model files found!",
"clean_all_separate_model": "Starting cleanup of all separation model files...",
"clean_all_separate_model_success": "All separation model files cleanup complete!",
"clean_all_models_success": "All model files cleanup complete",
"not_found_pretrained": "No pretrained model files found!",
"clean_all_pretrained": "Starting cleanup of all pretrained model files...",
"clean_all_pretrained_success": "All pretrained model cleanup complete!",
"not_found_log": "No log files found!",
"clean_all_log": "Starting cleanup of all log files...",
"clean_all_log_success": "Log file cleanup complete!",
"not_found_predictors": "No predictor model files found!",
"clean_all_predictors": "Starting cleanup of all predictor model files...",
"clean_all_predictors_success": "Predictor model cleanup complete!",
"not_found_embedders": "No embedder model files found!",
"clean_all_embedders": "Starting cleanup of all embedder model files...",
"clean_all_embedders_success": "Embedder model cleanup complete!",
"provide_folder": "Please provide a valid folder!",
"empty_folder": "The data folder is empty!",
"clean_dataset": "Starting dataset folder cleanup...",
"clean_dataset_success": "Dataset folder cleanup complete!",
"vocoder": "Vocoder",
"vocoder_info": "A vocoder analyzes and synthesizes human speech signals for voice transformation.",
"code_error": "Error: Received status code",
"json_error": "Error: Unable to parse response.",
"requests_error": "Request failed: {e}",
"memory_efficient_training": "Using memory-efficient training",
"not_use_pretrain_error_download": "Will not use pretrained models due to missing files",
"start_clean_model": "Starting cleanup of all models...",
"provide_file_settings": "Please provide a preset settings file!",
"load_presets": "Loaded preset file {presets}",
"provide_filename_settings": "Please provide a preset file name!",
"choose1": "Please select one to export!",
"export_settings": "Exported preset file {name}",
"use_presets": "Using preset file",
"file_preset": "Preset file",
"load_file": "Load file",
"export_file": "Export preset file",
"save_clean": "Save cleanup",
"save_autotune": "Save autotune",
"save_pitch": "Save pitch",
"save_index_2": "Save index impact",
"save_resample": "Save resampling",
"save_filter": "Save median filter",
"save_envelope": "Save sound envelope",
"save_protect": "Save sound protection",
"save_split": "Save sound split",
"filename_to_save": "File name to save",
"upload_presets": "Upload preset file",
"stop": "Stop process",
"stop_separate": "Stop Music Separation",
"stop_convert": "Stop Conversion",
"stop_create_dataset": "Stop Dataset Creation",
"stop_training": "Stop Training",
"stop_extract": "Stop Data Processing",
"stop_preprocess": "Stop Data Extraction",
"cleaner": "Cleaner",
"clean_audio": "Clean audio files",
"clean_all": "Clean all",
"clean_file": "Clean file",
"clean_models": "Clean model files",
"clean_pretrained": "Clean pretrained model files",
"clean_separated": "Clean separated model files",
"clean_presets": "Clean preset files",
"clean_datasets": "Clean training dataset folder",
"clean_dataset_folder": "Clean dataset folder",
"clean_log": "Clean log files",
"clean_predictors": "Clean predictor models",
"clean_embed": "Clean embedder models",
"clean_presets_2": "Starting cleanup of preset files...",
"clean_presets_success": "Preset file cleanup complete!",
"not_found_presets": "No preset files found in the folder!",
"clean_all_presets": "Starting cleanup of all preset files...",
"clean_all_presets_success": "All preset file cleanup complete!",
"port": "Port {port} is unavailable! Lowering port by one...",
"empty_json": "{file}: Corrupted or empty",
"thank": "Thank you for reporting the issue, and apologies for any inconvenience caused!",
"error_read_log": "An error occurred while reading log files!",
"error_send": "An error occurred while sending the report! Please contact me on Discord: pham_huynh_anh!",
"report_bugs": "Report Bugs",
"agree_log": "Agree to provide all log files",
"error_info": "Error description",
"error_info_2": "Provide more information about the error",
"report_bug_info": "Report bugs encountered during program usage",
"sr_info": "NOTE: SOME FORMATS DO NOT SUPPORT RATES ABOVE 48000",
"report_info": "If possible, agree to provide log files to help with debugging.\n\nIf log files are not provided, please describe the error in detail, including when and where it occurred.\n\nIf this reporting system also fails, you can reach out via [ISSUE]({github}) or Discord: `pham_huynh_anh`",
"default_setting": "An error occurred during separation, resetting all settings to default...",
"dataset_folder1": "Please enter the data folder name",
"checkpointing_err": "Pretrained model parameters such as sample rate or architecture do not match the selected model.",
"start_onnx_export": "Start converting model to onnx",
"convert_model": "Convert Model",
"pytorch2onnx": "Converting PYTORCH Model to ONNX Model",
"pytorch2onnx_markdown": "Convert RVC model from pytorch to onnx to optimize audio conversion",
"error_readfile": "An error occurred while reading the file!",
"read_sf": "Read audio file using soundfile...",
"read_librosa": "Read audio files using librosa as soundfile is not supported...",
"f0_onnx_mode": "F0 ONNX Mode",
"f0_onnx_mode_info": "Extracting pitch using the ONNX model can help improve speed",
"formantshift": "Pitch and Formant Shift",
"formant_qfrency": "Frequency for Formant Shift",
"formant_timbre": "Timbre for Formant Transformation",
"time_frames": "Time (Frames)",
"Frequency": "Frequency (Hz)",
"f0_extractor_tab": "F0 Extraction",
"f0_extractor_markdown": "## Pitch Extraction",
"f0_extractor_markdown_2": "F0 pitch extraction is intended for use in audio conversion inference",
"start_extract": "Starting extraction process...",
"extract_done": "Extraction process completed!",
"f0_file": "Use pre-extracted F0 file",
"upload_f0": "Upload F0 file",
"f0_file_2": "F0 File",
"clean_f0_file": "Clean up F0 file",
"start_clean_f0": "Starting F0 file cleanup...",
"clean_f0_done": "F0 file cleanup completed!",
"embed_onnx": "Embedders ONNX Mode",
"embed_onnx_info": "Embedded extraction using the ONNX model can help improve speed"
}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809{
"set_lang": "Đã đặt ngôn ngữ hiển thị là {lang}",
"no_support_gpu": "Thật không may, không có GPU tương thích để hỗ trợ việc đào tạo của bạn.",
"text": "văn bản",
"upload_success": "Đã tải lên tệp {name} hoàn tất.",
"download_url": "Tải từ đường dẫn liên kết",
"download_from_csv": "Tải từ kho mô hình csv",
"search_models": "Tìm kiếm mô hình",
"upload": "Tải lên",
"option_not_valid": "Tùy chọn không hợp lệ!",
"list_model": "Danh sách mô hình",
"success": "Hoàn tất!",
"index": "chỉ mục",
"model": "mô hình",
"zip": "nén",
"search": "tìm kiếm",
"provide_file": "Vui lòng cung cấp tệp {filename} hợp lệ!",
"start": "Bắt đầu {start}...",
"not_found": "Không tìm thấy {name}",
"found": "Đã tìm thấy {results} kết quả!",
"download_music": "tải nhạc",
"download": "tải xuống",
"provide_url": "Vui lòng cung cấp đường dẫn liên kết.",
"provide_name_is_save": "Vui lòng cung cấp tên mô hình để lưu.",
"not_support_url": "Liên kết mô hình của bạn không được hỗ trợ.",
"error_occurred": "Đã xảy ra lỗi: {e}",
"not_model": "Tệp bạn vừa tải lên không phải là tệp mô hình!",
"unable_analyze_model": "Không phân tích được mô hình!",
"download_pretrain": "Tải xuống huấn luyện trước...",
"provide_pretrain": "Vui lòng cung cấp đường dẫn mô hình huấn luyện trước {dg}.",
"provide_hubert": "Vui lòng đưa đường dẫn liên kết đến mô hình nhúng",
"sr_not_same": "Tốc độ lấy mẫu của hai mô hình không giống nhau",
"architectures_not_same": "Không thể hợp nhất các mô hình. Các kiến trúc mô hình không giống nhau.",
"fushion_model": "dung hợp mô hình",
"model_fushion_info": "Mô hình được {name} được dung hợp từ {pth_1} và {pth_2} với ratio {ratio}.",
"not_found_create_time": "Không tìm thấy thời gian tạo.",
"format_not_valid": "Định dạng không hợp lệ.",
"read_info": "Các mô hình được huấn luyện trên các ứng dụng khác nhau có thể đem lại các thông tin khác nhau hoặc không thể đọc!",
"epoch": "kỷ nguyên.",
"step": "bước",
"sr": "Tốc độ lấy mẫu",
"f0": "huấn luyện cao độ",
"version": "phiên bản.",
"not_f0": "Không được huấn luyện cao độ",
"trained_f0": "Được huấn luyện cao độ",
"model_info": "Tên mô hình: {model_name}\n\n Người tạo mô hình: {model_author}\n\nKỷ nguyên: {epochs}\n\nSố bước: {steps}\n\nPhiên bản của mô hình: {version}\n\nTốc độ lấy mẫu: {sr}\n\nHuấn luyện cao độ: {pitch_guidance}\n\nHash (ID): {model_hash}\n\nThời gian tạo: {creation_date_str}\n\nBộ mã hóa: {vocoder}\n",
"input_not_valid": "Vui lòng nhập đầu vào hợp lệ!",
"output_not_valid": "Vui lòng nhập đầu ra hợp lệ!",
"apply_effect": "áp dụng hiệu ứng",
"enter_the_text": "Vui lòng nhập văn bản để chuyển!",
"choose_voice": "Vui lòng chọn giọng!",
"convert": "Chuyển đổi {name}...",
"separator_music": "tách nhạc",
"notfound": "Không tìm thấy",
"turn_on_use_audio": "Vui lòng bật sử dụng âm thanh vừa tách để sử dụng",
"turn_off_convert_backup": "Tắt chuyển đổi giọng bè để có thể sử dụng giọng gốc",
"turn_off_merge_backup": "Tắt không kết hợp giọng bè để có thể sử dụng giọng gốc",
"not_found_original_vocal": "Không tìm thấy giọng gốc!",
"convert_vocal": "Đang chuyển đổi giọng nói...",
"convert_success": "Đã hoàn tất chuyển đổi giọng nói!",
"convert_backup": "Đang chuyển đổi giọng bè...",
"convert_backup_success": "Đã Hoàn tất chuyển đổi giọng bè!",
"merge_backup": "Kết hợp giọng với giọng bè...",
"merge_success": "Kết hợp Hoàn tất.",
"is_folder": "Đầu vào là một thư mục: Chuyển đổi tất cả tệp âm thanh trong thư mục...",
"not_found_in_folder": "Không tìm thấy tệp âm thanh trong thư mục!",
"batch_convert": "Đang chuyển đổi hàng loạt...",
"batch_convert_success": "Chuyển đổi hàng loạt hoàn tất!",
"create": "tạo",
"provide_name": "Vui lòng cung cấp tên mô hình.",
"not_found_data": "Không tìm thấy dữ liệu",
"not_found_data_preprocess": "Không tìm thấy dữ liệu được xử lý, vui lòng xử lý lại âm thanh",
"not_found_data_extract": "Không tìm thấy dữ liệu được trích xuất, vui lòng trích xuất lại âm thanh",
"provide_pretrained": "Vui lòng nhập huấn luyện {dg}",
"download_pretrained": "Tải xuống huấn luyện trước {dg}{rvc_version} gốc",
"not_found_pretrain": "Không tìm thấy huấn luyện trước {dg}",
"not_use_pretrain": "Sẽ không có huấn luyện trước được sử dụng",
"training": "huấn luyện",
"display_title": "<h1> 🎵 Giao diện chuyển đổi và huấn luyện mô hình giọng nói được tạo bởi Anh 🎵 <h1>",
"rick_roll": "Bấm vào đây nếu bạn muốn bị Rick Roll:) ---> [RickRoll]({rickroll})",
"terms_of_use": "**Vui lòng không sử dụng Dự án với bất kỳ mục đích nào vi phạm đạo đức, pháp luật, hoặc gây tổn hại đến cá nhân, tổ chức...**",
"exemption": "**Trong trường hợp người sử dụng không tuân thủ các điều khoản hoặc vi phạm, tôi sẽ không chịu trách nhiệm về bất kỳ khiếu nại, thiệt hại, hay trách nhiệm pháp lý nào, dù là trong hợp đồng, do sơ suất, hay các lý do khác, phát sinh từ, ngoài, hoặc liên quan đến phần mềm, việc sử dụng phần mềm hoặc các giao dịch khác liên quan đến phần mềm.**",
"separator_tab": "Tách Nhạc",
"4_part": "Một hệ thống tách nhạc đơn giản có thể tách được 4 phần: Nhạc, giọng, giọng chính, giọng bè",
"clear_audio": "Làm sạch âm thanh",
"separator_backing": "Tách giọng bè",
"denoise_mdx": "Khữ tách MDX",
"use_mdx": "Sử dụng MDX",
"dereveb_audio": "Tách vang",
"dereveb_backing": "Tách vang bè",
"separator_model": "Mô hình tách nhạc",
"separator_backing_model": "Mô hình tách bè",
"shift": "Số lượng dự đoán",
"shift_info": "Càng cao chất lượng càng tốt nhưng lâu nhưng tốn tài nguyên",
"segments_size": "Kích Thước Phân Đoạn",
"segments_size_info": "Càng cao chất lượng càng tốt nhưng tốn tài nguyên",
"batch_size": "Kích thước lô",
"batch_size_info": "Số lượng mẫu xử lý đồng thời trong một lần huấn luyện. Cao có thể gây tràn bộ nhớ",
"mdx_batch_size_info": "Số lượng mẫu được xử lý cùng một lúc. Việc chia thành các lô giúp tối ưu hóa quá trình tính toán. Lô quá lớn có thể làm tràn bộ nhớ, khi lô quá nhỏ sẽ làm giảm hiệu quả dùng tài nguyên",
"overlap": "Chồng chéo",
"overlap_info": "Số lượng chồng chéo giữa các cửa sổ dự đoán",
"export_format": "Định dạng âm thanh",
"export_info": "Định dạng âm thanh khi xuất tệp âm thanh ra",
"output_separator": "Âm thanh đã được tách",
"hop_length_info": "Khoảng thời gian chuyển cửa sổ phân tích khi thực hiện phép biến đổi. Giá trị nhỏ độ chi tiết cao nhưng cần tính toán nhiều hơn",
"drop_audio": "Thả âm thanh vào đây",
"drop_text": "Thả tệp văn bản vào đây",
"use_url": "Sử dụng đường dẫn youtube",
"url_audio": "Đường dẫn liên kết đến âm thanh",
"downloads": "Tải Xuống",
"clean_strength": "Mức độ làm sạch âm thanh",
"clean_strength_info": "Mức độ của bộ làm sạch âm thanh để lọc giọng hát khi xuất",
"input_output": "Đầu vào, đầu ra âm thanh",
"audio_path": "Đường dẫn đầu vào âm thanh",
"refesh": "Tải lại",
"output_folder": "Đường dẫn thư mục đầu ra âm thanh",
"output_folder_info": "Nhập đường dẫn thư mục âm thanh sẽ xuất ra ở đó",
"input_audio": "Đầu vào âm thanh",
"instruments": "Nhạc nền",
"original_vocal": "Giọng gốc",
"main_vocal": "Giọng chính",
"backing_vocal": "Giọng bè",
"convert_audio": "Chuyển Đổi Âm Thanh",
"convert_info": "Chuyển đổi âm thanh bằng mô hình giọng nói đã được huấn luyện",
"autotune": "Tự động điều chỉnh",
"use_audio": "Sử dụng âm thanh vừa tách",
"convert_original": "Chuyển đổi giọng gốc",
"convert_backing": "Chuyển đổi giọng bè",
"not_merge_backing": "Không kết hợp giọng bè",
"merge_instruments": "Kết hợp nhạc nền",
"pitch": "Cao độ",
"pitch_info": "Khuyến cáo: chỉnh lên 12 để chuyển giọng nam thành nữ và ngược lại",
"model_accordion": "Mô hình và chỉ mục",
"model_name": "Tệp mô hình",
"index_path": "Tệp chỉ mục",
"index_strength": "Ảnh hưởng của chỉ mục",
"index_strength_info": "Càng cao ảnh hưởng càng lớn. Tuy nhiên, việc chọn giá trị thấp hơn có thể giảm hiện tượng giả trong âm thanh",
"output_path": "Đường dẫn đầu ra âm thanh",
"output_path_info": "Nhập đường dẫn đầu ra(cứ để định dạng .wav khi chuyển đổi nó tự sửa)",
"setting": "Cài đặt chung",
"f0_method": "Phương pháp trích xuất",
"f0_method_info": "Phương pháp để trích xuất dữ liệu",
"f0_method_hybrid": "Phương pháp trích xuất HYBRID",
"f0_method_hybrid_info": "Sự kết hợp của hai hoặc nhiều loại trích xuất khác nhau",
"hubert_model": "Mô hình nhúng",
"hubert_info": "Mô hình được huấn luyện trước để giúp nhúng",
"modelname": "Tên của mô hình",
"modelname_info": "Nếu bạn có mô hình riêng chỉ cần tải và nhập tên của mô hình vào đây",
"split_audio": "Cắt âm thanh",
"autotune_rate": "Mức độ điều chỉnh",
"autotune_rate_info": "Mức độ điều chỉnh tự động",
"resample": "Lấy mẫu lại",
"resample_info": "Lấy mẫu lại sau xử lý đến tốc độ lấy mẫu cuối cùng, 0 có nghĩa là không lấy mẫu lại, LƯU Ý: MỘT SỐ ĐỊNH DẠNG KHÔNG HỖ TRỢ TỐC ĐỘ TRÊN 48000",
"filter_radius": "Lọc trung vị",
"filter_radius_info": "Nếu giá trị lớn hơn ba sẽ áp dụng tính năng lọc trung vị. Giá trị đại diện cho bán kính bộ lọc và có thể làm giảm hơi thở hoặc tắt thở.",
"volume_envelope": "Đường bao âm thanh",
"volume_envelope_info": "Sử dụng đường bao âm lượng của đầu vào để thay thế hoặc trộn với đường bao âm lượng của đầu ra. Càng gần 1 thì đường bao đầu ra càng được sử dụng nhiều",
"protect": "Bảo vệ phụ âm",
"protect_info": "Bảo vệ các phụ âm riêng biệt và âm thanh thở ngăn chặn việc rách điện âm và các hiện tượng giả khác. Việc chỉnh tối đa sẽ bảo vệ toàn diện. Việc giảm giá trị này có thể giảm độ bảo vệ, đồng thời có khả năng giảm thiểu hiệu ứng lập chỉ mục",
"output_convert": "Âm thanh đã được chuyển đổi",
"main_convert": "Chuyển đổi giọng chính",
"main_or_backing": "Giọng chính + Giọng bè",
"voice_or_instruments": "Giọng + Nhạc nền",
"convert_text": "Chuyển Đổi Văn Bản",
"convert_text_markdown": "## Chuyển Đổi Văn Bản Thành Giọng Nói",
"convert_text_markdown_2": "Chuyển văn bản thành giọng nói và đọc lại bằng mô hình giọng nói được huấn luyện",
"input_txt": "Nhập dữ liệu từ tệp văn bản txt",
"text_to_speech": "Văn bản cần đọc",
"voice_speed": "Tốc độ đọc",
"voice_speed_info": "Tốc độ đọc của giọng nói",
"tts_1": "1. Chuyển Đổi Văn Bản",
"tts_2": "2. Chuyển Đổi Giọng Nói",
"voice": "Giọng nói của các nước",
"output_tts": "Đường dẫn đầu ra giọng nói",
"output_tts_convert": "Đường dẫn đầu ra giọng chuyển đổi",
"tts_output": "Nhập đường dẫn đầu ra",
"output_tts_markdown": "Âm thanh chưa được chuyển đổi và âm thanh đã được chuyển đổi",
"output_text_to_speech": "Giọng được tạo bởi chuyển đổi văn bản thành giọng nói",
"output_file_tts_convert": "Giọng được chuyển đổi bởi mô hình",
"output_audio": "Đầu ra âm thanh",
"provide_output": "Nhập đường dẫn đầu ra",
"audio_effects": "Hiệu Ứng Âm Thanh",
"apply_audio_effects": "## Áp Dụng Thêm Hiệu Ứng Cho Âm Thanh",
"audio_effects_edit": "Chỉnh sửa thêm hiệu ứng cho âm thanh",
"reverb": "Hiệu ứng vọng âm",
"chorus": "Hiệu ứng hòa âm",
"delay": "Hiệu ứng độ trễ",
"more_option": "Tùy chọn thêm",
"phaser": "Hiệu ứng xoay pha",
"compressor": "Hiệu ứng nén",
"apply": "Áp dụng",
"reverb_freeze": "Chế độ đóng băng",
"reverb_freeze_info": "Tạo hiệu ứng vang liên tục khi bật chế độ này",
"room_size": "Kích thước phòng",
"room_size_info": "Điều chỉnh không gian của phòng để tạo độ vang",
"damping": "Giảm âm",
"damping_info": "Điều chỉnh độ hút âm, kiểm soát mức độ vang",
"wet_level": "Mức độ tín hiệu vang",
"wet_level_info": "Điều chỉnh mức độ của tín hiệu có hiệu ứng vọng âm",
"dry_level": "Mức độ tín hiệu gốc",
"dry_level_info": "Điều chỉnh mức độ của tín hiệu không có hiệu ứng",
"width": "Chiều rộng âm thanh",
"width_info": "Điều chỉnh độ rộng của không gian âm thanh",
"chorus_depth": "Giảm âm",
"chorus_depth_info": "Điều chỉnh cường độ hòa âm, tạo ra cảm giác rộng cho âm thanh",
"chorus_rate_hz": "Tần s��",
"chorus_rate_hz_info": "Điều chỉnh tốc độ dao động của hòa âm",
"chorus_mix": "Trộn tín hiệu",
"chorus_mix_info": "Điều chỉnh mức độ trộn giữa âm gốc và âm có hiệu ứng",
"chorus_centre_delay_ms": "Đỗ trễ trung tâm (mili giây)",
"chorus_centre_delay_ms_info": "Khoảng thời gian trễ giữa các kênh stereo để tạo hiệu ứng hòa âm",
"chorus_feedback": "Phản hồi",
"chorus_feedback_info": "Điều chỉnh lượng tín hiệu hiệu ứng được quay lại vào tín hiệu gốc",
"delay_seconds": "Thời gian trễ",
"delay_seconds_info": "Điều chỉnh khoảng thời gian trễ giữa âm gốc và âm có hiệu ứng",
"delay_feedback": "Phản hồi độ trễ",
"delay_feedback_info": "Điều chỉnh lượng tín hiệu được quay lại, tạo hiệu ứng lặp lại",
"delay_mix": "Trộn tín hiệu độ trễ",
"delay_mix_info": "Điều chỉnh mức độ trộn giữa âm gốc và âm trễ",
"fade": "Hiệu ứng mờ dần",
"bass_or_treble": "Âm trầm và âm cao",
"limiter": "Giới hạn ngưỡng",
"distortion": "Hiệu ứng nhiễu âm",
"gain": "Cường độ âm",
"bitcrush": "Hiệu ứng giảm bits",
"clipping": "Hiệu ứng méo âm",
"fade_in": "Hiệu ứng mờ dần vào (mili giây)",
"fade_in_info": "Thời gian mà âm thanh sẽ tăng dần từ mức 0 đến mức bình thường",
"fade_out": "Hiệu ứng mờ dần ra (mili giây)",
"fade_out_info": "thời gian mà âm thanh sẽ giảm dần từ bình thường xuống mức 0",
"bass_boost": "Độ khuếch đại âm trầm (db)",
"bass_boost_info": "mức độ tăng cường âm trầm trong đoạn âm thanh",
"bass_frequency": "Tần số cắt của bộ lọc thông thấp (Hz)",
"bass_frequency_info": "tần số bị giảm. Tần số thấp sẽ làm âm trầm rõ hơn",
"treble_boost": "Độ khuếch đại âm cao (db)",
"treble_boost_info": "mức độ tăng cường âm cao trong đoạn âm thanh",
"treble_frequency": "Tần số cắt của bộ lọc thông cao (Hz)",
"treble_frequency_info": "tần số sẽ lọc bỏ. Tần số càng cao thì giữ lại âm càng cao",
"limiter_threashold_db": "Ngưỡng giới hạn",
"limiter_threashold_db_info": "Giới hạn mức độ âm thanh tối đa, ngăn không cho vượt quá ngưỡng",
"limiter_release_ms": "Thời gian thả",
"limiter_release_ms_info": "Khoảng thời gian để âm thanh trở lại sau khi bị giới hạn (Mili Giây)",
"distortion_info": "Điều chỉnh mức độ nhiễu âm, tạo hiệu ứng méo tiếng",
"gain_info": "Tăng giảm âm lượng của tín hiệu",
"clipping_threashold_db": "Ngưỡng cắt",
"clipping_threashold_db_info": "Cắt bớt tín hiệu vượt quá ngưỡng, tạo âm thanh méo",
"bitcrush_bit_depth": "Độ sâu bit",
"bitcrush_bit_depth_info": "Giảm chất lượng âm thanh bằng cách giảm số bit, tạo hiệu ứng âm thanh bị méo",
"phaser_depth": "Độ sâu",
"phaser_depth_info": "Điều chỉnh độ sâu của hiệu ứng, ảnh hưởng đến cường độ của hiệu ứng xoay pha",
"phaser_rate_hz": "Tần số",
"phaser_rate_hz_info": "Điều chỉnh tốc độ của hiệu ứng hiệu ứng xoay pha",
"phaser_mix": "Trộn tín hiệu",
"phaser_mix_info": "Điều chỉnh mức độ trộn giữa tín hiệu gốc và tín hiệu đã qua xử lý",
"phaser_centre_frequency_hz": "Tần số trung tâm",
"phaser_centre_frequency_hz_info": "Tần số trung tâm của hiệu ứng xoay pha, ảnh hưởng đến tần số bị điều chỉnh",
"phaser_feedback": "Phản hồi",
"phaser_feedback_info": "Điều chỉnh lượng phản hồi tín hiệu, tạo cảm giác xoay pha mạnh hoặc nhẹ",
"compressor_threashold_db": "Ngưỡng nén",
"compressor_threashold_db_info": "Ngưỡng mức âm thanh sẽ bị nén khi vượt qua ngưỡng này",
"compressor_ratio": "Tỉ lệ nén",
"compressor_ratio_info": "Điều chỉnh mức độ nén âm thanh khi vượt qua ngưỡng",
"compressor_attack_ms": "Thời gian tấn công (mili giây)",
"compressor_attack_ms_info": "Khoảng thời gian nén bắt đầu tác dụng sau khi âm thanh vượt ngưỡng",
"compressor_release_ms": "Thời gian thả",
"compressor_release_ms_info": "Thời gian để âm thanh trở lại trạng thái bình thường sau khi bị nén",
"create_dataset_url": "Đường dẫn liên kết đến âm thanh(sử dụng dấu , để sử dụng nhiều liên kết)",
"createdataset": "Tạo dữ liệu",
"create_dataset_markdown": "## Tạo Dữ Liệu Huấn Luyện Từ Youtube",
"create_dataset_markdown_2": "Xử lý và tạo tập tin dữ liệu huấn luyện bằng đường dẫn youtube",
"denoise": "Khử tách mô hình",
"skip": "Bỏ qua giây",
"model_ver": "Phiên bản tách giọng",
"model_ver_info": "Phiên bản của mô hình tách nhạc để tách giọng",
"create_dataset_info": "Thông tin tạo dữ liệu",
"output_data": "Đầu ra dữ liệu",
"output_data_info": "Đầu ra dữ liệu sau khi tạo xong dữ liệu",
"skip_start": "Bỏ qua phần đầu",
"skip_start_info": "Bỏ qua số giây đầu của âm thanh, dùng dấu , để sử dụng cho nhiều âm thanh",
"skip_end": "Bỏ qua phần cuối",
"skip_end_info": "Bỏ qua số giây cuối của âm thanh, dùng dấu , để sử dụng cho nhiều âm thanh",
"training_model": "Huấn Luyện Mô Hình",
"training_markdown": "Huấn luyện và đào tạo mô hình giọng nói bằng một lượng dữ liệu giọng nói",
"training_model_name": "Tên của mô hình khi huấn luyện(không sử dụng ký tự đặc biệt hay dấu cách)",
"sample_rate": "Tỉ lệ lấy mẫu",
"sample_rate_info": "Tỉ lệ lấy mẫu của mô hình",
"training_version": "Phiên bản mô hình",
"training_version_info": "Phiên bản mô hình khi huấn luyện",
"training_pitch": "Huấn luyện cao độ",
"upload_dataset": "Tải lên dữ liệu huấn luyện",
"preprocess_effect": "Xử lý hậu kỳ",
"clear_dataset": "Làm sạch dữ liệu",
"preprocess_info": "Thông tin phần xử lý trước",
"preprocess_button": "1. Xử lý dữ liệu",
"extract_button": "2. Trích xuất dữ liệu",
"extract_info": "Thông tin phần trích xuất dữ liệu",
"total_epoch": "Tổng số kỷ nguyên",
"total_epoch_info": "Tổng số kỷ nguyên huấn luyện đào tạo",
"save_epoch": "Tần suất lưu",
"save_epoch_info": "Tần suất lưu mô hình khi huấn luyện, giúp việc huấn luyện lại mô hình",
"create_index": "Tạo chỉ mục",
"index_algorithm": "Thuật toán chỉ mục",
"index_algorithm_info": "Thuật toán tạo chỉ mục",
"custom_dataset": "Tùy chọn thư mục",
"custom_dataset_info": "Tùy chọn thư mục dữ liệu huấn luyện",
"overtraining_detector": "Kiểm tra quá sức",
"overtraining_detector_info": "Kiểm tra huấn luyện mô hình quá sức",
"cleanup_training": "Làm sạch huấn luyện",
"cleanup_training_info": "Bật khi cần huấn luyện lại từ đầu.",
"cache_in_gpu": "Lưu mô hình vào đệm",
"cache_in_gpu_info": "Lưu mô hình vào bộ nhớ đệm gpu",
"dataset_folder": "Thư mục chứa dữ liệu",
"threshold": "Ngưỡng huấn luyện quá sức",
"setting_cpu_gpu": "Tùy chọn CPU/GPU",
"gpu_number": "Số gpu được sử dụng",
"gpu_number_info": "Số của GPU được sử dụng trong huấn luyện",
"save_only_latest": "Chỉ lưu mới nhất",
"save_only_latest_info": "Chỉ lưu mô hình D và G mới nhất",
"save_every_weights": "Lưu mọi mô hình",
"save_every_weights_info": "Lưu mọi mô hình sau mỗi lượt kỷ nguyên",
"gpu_info": "Thông tin của GPU",
"gpu_info_2": "Thông tin của GPU được sử dụng trong huấn luyện",
"cpu_core": "Số lõi xử lý có thể sử dụng",
"cpu_core_info": "Số lõi được sử dụng trong việc huấn luyện",
"not_use_pretrain_2": "Không dùng huấn luyện",
"not_use_pretrain_info": "Không dùng huấn luyện trước",
"custom_pretrain": "Tùy chỉnh huấn luyện",
"custom_pretrain_info": "Tùy chỉnh huấn luyện trước",
"pretrain_file": "Tệp mô hình huấn luyện trước {dg}",
"train_info": "Thông tin phần huấn luyện",
"export_model": "5. Xuất Mô hình",
"zip_model": "2. Nén mô hình",
"output_zip": "Đầu ra tệp khi nén",
"model_path": "Đường dẫn mô hình",
"model_ratio": "Tỉ lệ mô hình",
"model_ratio_info": "Chỉnh hướng về bên nào sẽ làm cho mô hình giống với bên đó",
"output_model_path": "Đầu ra mô hình",
"fushion": "Dung Hợp Mô Hình",
"fushion_markdown": "## Dung Hợp Hai Mô Hình Với Nhau",
"fushion_markdown_2": "Dung hợp hai mô hình giọng nói lại với nhau để tạo thành một mô hình duy nhất",
"read_model": "Đọc Thông Tin",
"read_model_markdown": "## Đọc Thông Tin Của Mô Hình",
"read_model_markdown_2": "Đọc các thông tin được ghi trong mô hình",
"drop_model": "Thả mô hình vào đây",
"readmodel": "Đọc mô hình",
"model_path_info": "Nhập đường dẫn đến tệp mô hình",
"modelinfo": "Thông Tin Mô Hình",
"download_markdown": "## Tải Xuống Mô Hình",
"download_markdown_2": "Tải xuống mô hình giọng nói, mô hình huấn luyện trước, mô hình nhúng",
"model_download": "Tải xuống mô hình giọng nói",
"model_url": "Đường dẫn liên kết đến mô hình",
"15s": "Vui lòng đợi khoảng 15 giây. Hệ thống sẽ tự khởi động lại!",
"model_download_select": "Chọn cách tải mô hình",
"model_warehouse": "Kho mô hình",
"get_model": "Nhận mô hình",
"name_to_search": "Tên để tìm kiếm",
"search_2": "Tìm kiếm",
"select_download_model": "Chọn mô hình đã được tìm kiếm(Bấm vào để chọn)",
"download_pretrained_2": "Tải xuống mô hình huấn luyện trước",
"only_huggingface": "Chỉ hỗ trợ huggingface.co",
"pretrained_url": "Đường dẫn liên kết đến mô hình huấn luyện trước {dg}",
"select_pretrain": "Chọn mô hình huấn luyện trước",
"select_pretrain_info": "Chọn mô hình huấn luyện trước để cài đặt về",
"pretrain_sr": "Tốc độ lấy mẫu của mô hình",
"drop_pretrain": "Thả mô hình huấn luyện trước {dg} vào đây",
"hubert_download": "Tải xuống mô hình nhúng",
"hubert_url": "Đường dẫn liên kết tới mô hình nhúng",
"drop_hubert": "Thả mô hình nhúng vào đây",
"settings": "Tùy Chỉnh",
"settings_markdown": "## Tùy Chỉnh Thêm",
"settings_markdown_2": "Tùy chỉnh thêm một số tính năng của dự án",
"lang": "Ngôn ngữ",
"lang_restart": "Ngôn ngữ được hiển thị trong dự án(Khi đổi ngôn ngữ hệ thống sẽ tự khởi động lại sau 15 giây để cập nhật)",
"change_lang": "Đổi Ngôn Ngữ",
"theme": "Chủ đề",
"theme_restart": "Loại Chủ đề của giao diện được hiển thị(Khi đổi chủ đề hệ thống sẽ tự khởi động lại sau 15 giây để cập nhật)",
"theme_button": "Đổi Chủ Đề",
"change_light_dark": "Đổi Chế Độ Sáng/Tối",
"tensorboard_url": "Đường dẫn biểu đồ",
"errors_loading_audio": "Lỗi khi tải âm thanh: {e}",
"apply_error": "Đã xảy ra lỗi khi áp dụng hiệu ứng: {e}",
"indexpath": "Đường dẫn chỉ mục",
"split_total": "Tổng số phần đã cắt",
"process_audio_error": "Đã xảy ra lỗi khi xử lý âm thanh",
"merge_error": "Đã xảy ra lỗi khi ghép âm thanh",
"not_found_convert_file": "Không tìm thấy tệp đã xử lý",
"convert_batch": "Chuyển đổi hàng loạt...",
"found_audio": "Tìm thấy {audio_files} tệp âm thanh cho việc chuyển đổi.",
"not_found_audio": "Không tìm thấy tệp âm thanh!",
"error_convert": "Đã xảy ra lỗi khi chuyển đổi âm thanh: {e}",
"error_convert_batch": "Đã xảy ra lỗi khi chuyển đổi các đoạn âm thanh cắt: {e}",
"error_convert_batch_2": "Đã xảy ra lỗi khi chuyển đổi âm thanh hàng loạt: {e}",
"convert_batch_success": "Đã chuyển đổi hàng loạt hoàn tất sau {elapsed_time} giây. {output_path}",
"convert_audio_success": "Tệp {input_path} được chuyển đổi hoàn tất sau {elapsed_time} giây. {output_path}",
"hybrid_methods": "Tính toán ước lượng cao độ f0 cho các phương pháp {methods}",
"method_not_valid": "Phương pháp không hợp lệ",
"read_faiss_index_error": "Đã xảy ra lỗi khi đọc chỉ mục FAISS: {e}",
"read_model_error": "Thất bại khi tải mô hình: {e}",
"starting_download": "Bắt đầu tải xuống",
"version_not_valid": "Phiên bản tách giọng không hợp lệ",
"skip<audio": "Không thể bỏ qua vì số lượng thời gian bỏ qua thấp hơn số lượng tệp âm thanh",
"skip>audio": "Không thể bỏ qua vì số lượng thời gian bỏ qua cao hơn số lượng tệp âm thanh",
"=<0": "Thời gian bỏ qua bé hơn hoặc bằng 0 nên bỏ qua",
"skip_warning": "Thời lượng bỏ qua ({seconds} giây) vượt quá thời lượng âm thanh ({total_duration} giây). Bỏ qua.",
"download_success": "Đã tải xuống hoàn tất",
"create_dataset_error": "Đã xảy ra lỗi khi tạo dữ liệu huấn luyện",
"create_dataset_success": "Quá trình tạo dữ liệu huấn huyện đã hoàn tất sau: {elapsed_time} giây",
"skip_start_audio": "Bỏ qua âm thanh đầu hoàn tất: {input_file}",
"skip_end_audio": "Bỏ qua âm thanh cuối hoàn tất: {input_file}",
"merge_audio": "Đã ghép các phần chứa âm thanh lại",
"separator_process": "Đang tách giọng: {input}...",
"not_found_main_vocal": "Không tìm thấy giọng chính!",
"not_found_backing_vocal": "Không tìm thấy giọng bè!",
"not_found_instruments": "Không tìm thấy nhạc nền",
"merge_instruments_process": "Kết hợp giọng với nhạc nền...",
"dereverb": "Đang tách âm vang",
"dereverb_success": "Đã tách âm vang hoàn tất",
"save_index": "Đã lưu tệp chỉ mục",
"create_index_error": "Đã xảy ra lỗi khi tạo chỉ mục",
"sr_not_16000": "Tỉ lệ mẫu phải là 16000",
"gpu_not_valid": "Chỉ số GPU không hợp lệ. Chuyển sang CPU.",
"extract_file_error": "Đã xảy ra lỗi khi giải nén tập tin",
"extract_f0_method": "Bắt đầu trích xuất cao độ với {num_processes} lõi với phương pháp trích xuất {f0_method}...",
"extract_f0": "Trích Xuất Cao Độ",
"extract_f0_success": "Quá trình trích xuất cao độ đã hoàn tất vào {elapsed_time} giây.",
"NaN": "chứa giá trị NaN và sẽ bị bỏ qua.",
"start_extract_hubert": "Đang bắt đầu nhúng trích xuất...",
"not_found_audio_file": "Không tìm thấy tập tin âm thanh. Hãy chắc chắn rằng bạn đã cung cấp âm thanh chính xác.",
"process_error": "Đã xảy ra lỗi khi xử lý",
"extract_hubert_success": "Quá trình trích xuất nhúng đã hoàn tất trong {elapsed_time} giây.",
"export_process": "Đường dẫn của mô hình",
"extract_error": "Đã xảy ra lỗi khi trích xuất dữ liệu",
"extract_success": "Đã trích xuất hoàn tất mô hình",
"min_length>=min_interval>=hop_size": "min_length lớn hơn hoặc bằng min_interval lớn hơn hoặc bằng hop_size là bắt buộc",
"max_sil_kept>=hop_size": "max_sil_kept lớn hơn hoặc bằng hop_size là bắt buộc",
"start_preprocess": "Đang bắt đầu xử lý dữ liệu với {num_processes} lõi xử lý...",
"not_integer": "Thư mục ID giọng nói phải là số nguyên, thay vào đó có",
"preprocess_success": "Quá trình xử lý hoàn tất sau {elapsed_time} giây.",
"preprocess_model_success": "Đã hoàn tất xử lý trước dữ liệu cho mô hình",
"turn_on_dereverb": "Điều kiện cần để sử dụng tách vang giọng bè là phải bật tách vang",
"turn_on_separator_backing": "Điều kiện cần để sử dụng tách vang giọng bè là phải bật tách bè",
"backing_model_ver": "Phiên bản mô hình của tách bè",
"clean_audio_success": "Đã làm sạch âm hoàn tất!",
"separator_error": "Đã xảy ra lỗi khi tách nhạc",
"separator_success": "Quá trình tách nhạc đã hoàn tất sau: {elapsed_time} giây",
"separator_process_2": "Đang xử lý tách nhạc",
"separator_success_2": "Đã tách nhạc hoàn tất!",
"separator_process_backing": "Đang xử lý tách giọng bè",
"separator_process_backing_success": "Đã tách giọng bè hoàn tất!",
"process_original": "Đang xử lý tách âm vang giọng gốc...",
"process_original_success": "Đã tách âm vang giọng gốc hoàn tất!",
"process_main": "Đang xử lý tách âm vang giọng chính...",
"process_main_success": "Đã tách âm vang giọng chính hoàn tất!",
"process_backing": "Đang xử lý tách âm vang giọng bè...",
"process_backing_success": "Đã tách âm vang giọng bè hoàn tất!",
"save_every_epoch": "Lưu mô hình sau: ",
"total_e": "Tổng số kỷ nguyên huấn luyện: ",
"dorg": "Huấn luyện trước G: {pretrainG} | Huấn luyện trước D: {pretrainD}",
"training_f0": "Huấn luyện cao độ",
"not_gpu": "Không phát hiện thấy GPU, hoàn nguyên về CPU (không khuyến nghị)",
"not_found_checkpoint": "Không tìm thấy tệp điểm đã lưu: {checkpoint_path}",
"save_checkpoint": "Đã tải lại điểm đã lưu '{checkpoint_path}' (kỷ nguyên {checkpoint_dict})",
"save_model": "Đã lưu mô hình '{checkpoint_path}' (kỷ nguyên {iteration})",
"sr_does_not_match": "{sample_rate} Tỉ lệ mẫu không khớp với mục tiêu {sample_rate2} Tỉ lệ mẫu",
"spec_error": "Đã xảy ra lỗi khi nhận thông số kỹ thuật từ {spec_filename}: {e}",
"time_or_speed_training": "thời gian={current_time} | tốc độ huấn luyện={elapsed_time_str}",
"savemodel": "Đã lưu mô hình '{model_dir}' (kỷ nguyên {epoch} và bước {step})",
"model_author": "Ghi công mô hình cho {model_author}",
"unregistered": "Mô hình không được ghi chép",
"not_author": "Mô hình không được ghi chép",
"training_author": "Tên chủ mô hình",
"training_author_info": "Nếu bạn muốn ghi công mô hình hãy nhập tên của bạn vào đây",
"extract_model_error": "Đã xảy ra lỗi khi trích xuất mô hình",
"start_training": "Bắt đầu huấn luyện",
"import_pretrain": "Đã nạp huấn luyện trước ({dg}) '{pretrain}'",
"not_using_pretrain": "Sẽ không có huấn luyện trước ({dg}) được sử dụng",
"training_warning": "CẢNH BÁO: Tổn thất tạo ra thấp hơn đã bị vượt quá tổn thất thấp hơn trong kỷ nguyên tiếp theo.",
"overtraining_find": "Tập luyện quá sức được phát hiện ở kỷ nguyên {epoch} với mất mát g được làm mịn {smoothed_value_gen} và mất mát d được làm mịn {smoothed_value_disc}",
"best_epoch": "Kỷ nguyên mới tốt nhất {epoch} với mất mát g được làm mịn {smoothed_value_gen} và mất mát d được làm mịn {smoothed_value_disc}",
"success_training": "Đã đào tạo hoàn tất với {epoch} kỷ nguyên, {global_step} các bước và {loss_gen_all} mất mát gen.",
"training_info": "Tổn thất gen thấp nhất: {lowest_value_rounded} ở ký nguyên {lowest_value_epoch}, bước {lowest_value_step}",
"model_training_info": "{model_name} | kỷ nguyên={epoch} | bước={global_step} | {epoch_recorder} | giá trị thấp nhất={lowest_value_rounded} (kỷ nguyên {lowest_value_epoch} và bước {lowest_value_step}) | Số kỷ nguyên còn lại để tập luyện quá sức: g/total: {remaining_epochs_gen} d/total: {remaining_epochs_disc} | làm mịn mất mát gen={smoothed_value_gen} | làm mịn mất mát disc={smoothed_value_disc}",
"model_training_info_2": "{model_name} | kỷ nguyên={epoch} | bước={global_step} | {epoch_recorder} | giá trị thấp nhất={lowest_value_rounded} (kỷ nguyên {lowest_value_epoch} và bước {lowest_value_step})",
"model_training_info_3": "{model_name} | kỷ nguyên={epoch} | bước={global_step} | {epoch_recorder}",
"training_error": "Đã xảy ra lỗi khi huấn luyện mô hình:",
"separator_info": "Đang khởi tạo với đường dẫn đầu ra: {output_dir}, định dạng đầu ra: {output_format}",
"output_dir_is_none": "Thư mục đầu ra không được chỉ định. Sử dụng thư mục làm việc hiện tại.",
">0or=1": "Ngưỡng chuẩn hóa phải lớn hơn 0 và nhỏ hơn hoặc bằng 1.",
"output_single": "Đã yêu cầu đầu ra một gốc nên chỉ có một tệp đầu ra ({output_single_stem}) sẽ được ghi",
"step2": "Bước thứ hai sẽ được đảo ngược bằng cách sử dụng quang phổ thay vì dạng sóng. Điều này có thể cải thiện chất lượng nhưng chậm hơn một chút.",
"name_ver": "Phiên bản {name}",
"os": "Hệ điều hành",
"platform_info": "Hệ thống: {system_info} Tên: {node} Phát hành: {release} Máy: {machine} Vi xử lý: {processor}",
"none_ffmpeg": "FFmpeg chưa được cài đặt. Vui lòng cài đặt FFmpeg để sử dụng gói này.",
"install_onnx": "Gói {pu} ONNX Runtime được cài đặt cùng với phiên bản",
"running_in_cpu": "Không thể cấu hình khả năng tăng tốc phần cứng, chạy ở chế độ CPU",
"running_in_cuda": "CUDA có sẵn trong Torch, cài đặt thiết bị Torch thành CUDA",
"onnx_have": "ONNXruntime có sẵn {have}, cho phép tăng tốc",
"onnx_not_have": "{have} không có sẵn trong ONNXruntime, do đó khả năng tăng tốc sẽ KHÔNG được bật",
"python_not_install": "Gói Python: {package_name} chưa được cài đặt",
"hash": "Tính hash của tệp mô hình {model_path}",
"ioerror": "IOError đang tìm kiếm -10 MB hoặc đọc tệp mô hình để tính toán hàm băm: {e}",
"cancel_download": "Tệp đã tồn tại tại {output_path}, bỏ qua quá trình tải xuống",
"download_model": "Đang tải tệp từ {url} xuống {output_path} với thời gian chờ 300 giây",
"download_error": "Không tải được tệp xuống từ {url}, mã phản hồi: {status_code}",
"vip_model": "Mô hình: '{model_friendly_name}' là mô hình cao cấp, được Anjok07 dự định chỉ dành cho những người đăng ký trả phí truy cập.",
"vip_print": "Này bạn, nếu bạn chưa đăng ký, vui lòng cân nhắc việc hỗ trợ cho nhà phát triển của UVR, Anjok07 bằng cách đăng ký tại đây: https://patreon.com/uvr",
"search_model": "Đang tìm kiếm mô hình {model_filename} trong tập tin các mô hình được hỗ trợ trong nhóm",
"load_download_json": "Đã tải danh sách tải xuống mô hình",
"single_model": "Đã xác định được tệp mô hình đơn: {model_friendly_name}",
"not_found_model": "Không tìm thấy mô hình trong kho lưu trữ UVR, đang cố tải xuống từ kho lưu trữ mô hình phân tách âm thanh...",
"single_model_path": "Đường dẫn trả về cho tệp mô hình đơn: {model_path}",
"find_model": "Đã tìm thấy tên tệp đầu vào {model_filename} trong mô hình nhiều tệp: {model_friendly_name}",
"find_models": "Đã xác định mô hình nhiều tệp: {model_friendly_name}, lặp qua các tệp để tải xuống",
"find_path": "Đang cố gắng xác định ĐƯỜNG DẪN tải xuống cho cặp cấu hình",
"not_found_model_warehouse": "Không tìm thấy mô hình trong kho lưu trữ UVR, đang cố tải xuống từ kho lưu trữ mô hình phân tách âm thanh...",
"yaml_warning": "Tên mô hình bạn đã chỉ định, {model_filename} thực sự là tệp cấu hình mô hình chứ không phải tệp mô hình.",
"yaml_warning_2": "Chúng tôi đã tìm thấy một mô hình khớp với tệp cấu hình này: {config_key} nên chúng tôi sẽ sử dụng tệp mô hình đó cho lần chạy này.",
"yaml_warning_3": "Để tránh hành vi gây nhầm lẫn/không nhất quán trong tương lai, thay vào đó hãy chỉ định tên tệp mô hình thực tế.",
"yaml_debug": "Không tìm thấy tệp cấu hình mô hình YAML trong kho lưu trữ UVR, đang cố tải xuống từ kho lưu trữ mô hình phân tách âm thanh...",
"download_model_friendly": "Tất cả các tệp đã tải xuống cho mô hình {model_friendly_name}, trả về đường dẫn ban đầu {model_path}",
"not_found_model_2": "Không tìm thấy tệp mô hình {model_filename} trong các tệp mô hình được hỗ trợ",
"load_yaml": "Đang tải dữ liệu mô hình từ YAML tại đường dẫn {model_data_yaml_filepath}",
"load_yaml_2": "Dữ liệu mô hình được tải từ tệp YAML: {model_data}",
"hash_md5": "Tính hash MD5 cho tệp mô hình để xác định các tham số mô hình từ dữ liệu UVR...",
"model_hash": "Mô hình {model_path} có hash {model_hash}",
"mdx_data": "Đường dẫn dữ liệu mô hình MDX được đặt thành {mdx_model_data_path}",
"load_mdx": "Đang tải các tham số mô hình MDX từ tệp dữ liệu mô hình UVR...",
"model_not_support": "Tệp mô hình không được hỗ trợ: không thể tìm thấy tham số cho hash MD5 {model_hash} trong tệp dữ liệu mô hình UVR cho vòm MDX.",
"uvr_json": "Dữ liệu mô hình được tải từ UVR JSON bằng hàm băm {model_hash}: {model_data}",
"loading_model": "Đang tải mô hình {model_filename}...",
"download_model_friendly_2": "Đã tải xuống mô hình, tên thân thiện: {model_friendly_name}, Đường dẫn mô hình: {model_path}",
"model_type_not_support": "Loại mô hình không được hỗ trợ: {model_type}",
"demucs_not_support_python<3.10": "Các mô hình Demucs yêu cầu phiên bản Python 3.10 trở lên.",
"import_module": "Nhập mô-đun cho loại mô hình",
"initialization": "Khởi tạo lớp phân cách cho loại mô hình",
"loading_model_success": "Đang tải mô hình hoàn tất.",
"loading_model_duration": "Tải thời lượng mô hình",
"starting_separator": "Bắt đầu quá trình tách cho đường dẫn tập tin âm thanh",
"normalization": "Ngưỡng chuẩn hóa được đặt thành {normalization_threshold}, dạng sóng sẽ hạ xuống biên độ tối đa này để tránh bị cắt.",
"loading_separator_model": "Đang tải xuống mô hình {model_filename}...",
"separator_success_3": "Quá trình tách hoàn tất.",
"separator_duration": "Thời gian tách",
"downloading_model": "Đã tải xuống mô hình, loại: {model_type}, tên thân thiện: {model_friendly_name}, đường dẫn mô hình: {model_path}, dữ liệu mô hình: {model_data_dict_size} mục",
"demucs_info": "Thông số Demucs: Kích thước phân đoạn = {segment_size}, Kích hoạt kích thước phân đoạn = {segments_enabled}",
"demucs_info_2": "Thông số Demucs: Số lượng dự đoán = {shifts}, Chồng chéo = {overlap}",
"start_demucs": "Khởi tạo hoàn tất Demucs Separator",
"start_separator": "Bắt đầu quá trình tách...",
"prepare_mix": "Chuẩn bị hỗn hợp...",
"demix": "Hỗn hợp đã chuẩn bị để khử trộn. Hình dạng: {shape}",
"cancel_mix": "Đang tải mô hình để hủy trộn...",
"model_review": "Mô hình được tải và đặt ở chế độ đánh giá.",
"del_gpu_cache_after_demix": "Đã xóa bộ nhớ đệm mô hình và GPU sau khi hủy trộn.",
"process_output_file": "Đang xử lý tập tin đầu ra...",
"source_length": "Đang xử lý mảng nguồn, độ dài nguồn là {source_length}",
"process_ver": "Đang xử lý nguồn phiên bản...",
"set_map": "Đặt bản đồ nguồn thành {part} phần gốc...",
"process_all_part": "Xử lý cho tất cả các phần gốc...",
"skip_part": "Bỏ qua phần viết gốc {stem_name} vì out_single_stem được đặt thành {output_single_stem}...",
"starting_demix_demucs": "Đang bắt đầu quá trình trộn trong demix_demucs...",
"model_infer": "Chạy mô hình suy luận...",
"name_not_pretrained": "{name} không phải là một mô hình được đào tạo trước hay một túi mô hình.",
"invalid_checksum": "Tổng kiểm tra không hợp lệ cho tệp {path}, dự kiến {checksum} nhưng lại nhận được {actual_checksum}",
"mdx_info": "Thông số MDX: Kích thước lô = {batch_size}, Kích thước phân đoạn = {segment_size}",
"mdx_info_2": "Thông số MDX: Chồng chéo = {overlap}, Hop_length = {hop_length}, Kích hoạt khữ nhiễu = {enable_denoise}",
"mdx_info_3": "Thông số MDX",
"load_model_onnx": "Đang tải mô hình ONNX để suy luận...",
"load_model_onnx_success": "Đã tải mô hình hoàn tất bằng phiên suy luận ONNXruntime.",
"onnx_to_pytorch": "Mô hình được chuyển đổi từ onnx sang pytorch do kích thước phân đoạn không khớp với dim_t, quá trình xử lý có thể chậm hơn.",
"stft": "STFT nghịch đảo được áp dụng. Trả về kết quả có hình dạng",
"no_denoise": "Mô hình chạy trên quang phổ mà không khử nhiễu.",
"mix": "Đang chuẩn bị trộn cho tệp âm thanh đầu vào {audio_file_path}...",
"normalization_demix": "Chuẩn hóa hỗn hợp trước khi khử trộn...",
"mix_success": "Quá trình trộn hoàn tất.",
"primary_source": "Bình thường hóa nguồn chính...",
"secondary_source": "Sản xuất nguồn thứ cấp: Trộn ở chế độ trộn phù hợp",
"invert_using_spec": "Đảo ngược thân thứ cấp bằng cách sử dụng quang phổ khi invert_USE_spec được đặt thành True",
"invert_using_spec_2": "Đảo ngược thân thứ cấp bằng cách trừ đi thân cây được chuyển đổi từ hỗn hợp ban đầu được chuyển đổi",
"enable_denoise": "Mô hình chạy trên cả phổ âm và dương để khử nhiễu.",
"is_match_mix": "is_match_mix: dự đoán phổ thu được trực tiếp từ đầu ra STFT.",
"save_secondary_stem_output_path": "Đang lưu phần gốc {stem_name} vào {stem_output_path}...",
"starting_model": "Đang khởi tạo cài đặt mô hình...",
"input_info": "Thông số đầu vào của mô hình",
"model_settings": "Cài đặt mô hình",
"initialize_mix": "Đang khởi tạo kết hợp với is_ckpt = {is_ckpt}. Hình dạng trộn ban đầu: {shape}",
"!=2": "Dự kiến có tín hiệu âm thanh 2 kênh nhưng lại có {shape} kênh",
"process_check": "Xử lý ở chế độ điểm kiểm tra...",
"stft_2": "STFT được áp dụng trên hỗn hợp. Hình dạng quang phổ: {shape}",
"cache": "Khoảng đệm được tính toán",
"shape": "Hình dạng hỗn hợp sau khi đệm: {shape}, Số phần: {num_chunks}",
"process_no_check": "Xử lý ở chế độ không có điểm kiểm tra...",
"n_sample_or_pad": "Số lượng mẫu: {n_sample}, Đã tính đệm: {pad}",
"shape_2": "Hình dạng hỗn hợp sau khi đệm",
"process_part": "Đoạn đã xử lý {mix_waves}: Bắt đầu {i}, Kết thúc {ii}",
"mix_waves_to_tensor": "Đã chuyển đổi mix_waves thành tensor. Hình dạng tensor: {shape}",
"mix_match": "Chế độ trộn Match; áp dụng hệ số bù.",
"tar_waves": "Sóng tar_waves. Hình dạng",
"normalization_2": "Chuẩn hóa kết quả bằng cách chia kết quả cho số chia.",
"mix_wave": "Đang xử lý lô mix_wave",
"mix_or_batch": "Trộn phần chia thành từng đợt. Số lượng lô",
"demix_is_match_mix": "Bắt đầu quá trình hủy trộn với is_match_mix,",
"mix_shape": "Hỗn hợp phần gốc được lưu trữ. Hình dạng",
"chunk_size_or_overlap": "Kích thước đoạn để trộn phù hợp: {chunk_size}, Chồng chéo: {overlap}",
"chunk_size_or_overlap_standard": "Kích thước phần tiêu chuẩn: {chunk_size}, Chồng chéo: {overlap}",
"calc_size": "Kích thước được tạo được tính toán",
"window": "Cửa sổ được áp dụng cho đoạn này.",
"process_part_2": "Đang xử lý đoạn {total}/{total_chunks}: Bắt đầu {start}, Kết thúc {end}",
"all_process_part": "Tổng số phần cần xử lý",
"step_or_overlap": "Kích thước bước để xử lý các phần: {step} khi chồng chéo được đặt thành {overlap}.",
"mix_cache": "Hỗn hợp được chuẩn bị với lớp đệm. Hình dạng hỗn hợp",
"dims": "Không thể sử dụng mã hóa vị trí sin/cos với thứ nguyên lẻ (có dim={dims})",
"activation": "kích hoạt phải là relu/gelu, không phải {activation}",
"length_or_training_length": "Độ dài cho trước {length} dài hơn thời lượng huấn luyện {training_length}",
"type_not_valid": "Loại không hợp lệ cho",
"del_parameter": "Bỏ tham số không tồn tại ",
"info": "Các thông số phổ biến: Tên mô hình = {model_name}, Đường dẫn mô hình = {model_path}",
"info_2": "Các thông số phổ biến: Đường dẫn đầu ra = {output_dir}, Định dạng đầu ra = {output_format}",
"info_3": "Các thông số phổ biến: ngưỡng chuẩn hóa = {normalization_threshold}",
"info_4": "Các thông số phổ biến: Kích hoạt khữ nhiễu = {enable_denoise}, Đầu ra một phần = {output_single_stem}",
"info_5": "Các thông số phổ biến: Đảo ngược bằng cách sử dụng thông số kỹ thuật = {invert_using_spec}, tỷ lệ mẫu = {sample_rate}",
"info_6": "Các thông số phổ biến: Tên phần gốc chính = {primary_stem_name}, Tên phần gốc phụ = {secondary_stem_name}",
"info_7": "Các thông số phổ biến: Là Karaoke = {is_karaoke}, là mô hình bv = {is_bv_model}, tái cân bằng mô hình bv = {bv_model_rebalance}",
"success_process": "Đang hoàn tất quá trình xử lý phần gốc {stem_name} và ghi âm thanh...",
"load_audio": "Đang tải âm thanh từ tập tin",
"load_audio_success": "Đã tải âm thanh. Tốc độ mẫu: {sr}, Hình dạng âm thanh: {shape}",
"convert_mix": "Chuyển đổi mảng hỗn hợp được cung cấp.",
"convert_shape": "Hình dạng hỗn hợp chuyển đổi: {shape}",
"audio_not_valid": "Tệp âm thanh {audio_path} trống hoặc không hợp lệ",
"audio_valid": "Tệp âm thanh hợp lệ và chứa dữ liệu.",
"mix_single": "Hỗn hợp là đơn sắc. Chuyển đổi sang âm thanh nổi.",
"convert_mix_audio": "Đã chuyển đổi thành bản trộn âm thanh nổi.",
"mix_success_2": "Công tác chuẩn bị hỗn hợp đã hoàn tất.",
"duration": "Thời lượng âm thanh là {duration_hours} giờ ({duration_seconds} giây).",
"write": "Sử dụng {name} để viết.",
"write_audio": "Đang nhập {name} bằng đường dẫn gốc:",
"original_not_valid": "Cảnh báo: mảng nguồn gốc gần như im lặng hoặc trống.",
"shape_audio": "Hình dạng dữ liệu âm thanh trước khi xử lý",
"convert_data": "Kiểu dữ liệu trước khi chuyển đổi",
"original_source_to_int16": "Đã chuyển đổi original_source thành int16.",
"shape_audio_2": "Hình dạng dữ liệu âm thanh xen kẽ",
"create_audiosegment": "Đã tạo AudioSegment hoàn tất.",
"create_audiosegment_error": "Lỗi cụ thể khi tạo AudioSegment",
"export_error": "Lỗi xuất file âm thanh",
"export_success": "Đã xuất hoàn tất tệp âm thanh sang",
"clean": "Chạy thu gom rác...",
"clean_cache": "Xóa bộ nhớ đệm {name}...",
"del_path": "Xóa đường dẫn, nguồn và gốc của tệp âm thanh đầu vào...",
"not_success": "Quá trình đăng không hoàn tất: ",
"resample_error": "Lỗi trong quá trình lấy mẫu lại",
"shapes": "Hình dạng",
"wav_resolution": "Loại độ phân giải",
"warnings": "Cảnh báo: Đã phát hiện các giá trị cực kỳ hung hãn",
"warnings_2": "Cảnh báo: Đã phát hiện NaN hoặc giá trị vô hạn trong đầu vào sóng. Hình dạng",
"process_file": "Đang xử lý tập tin... \n",
"save_instruments": "Lưu bản nhạc ngược...",
"assert": "Các tệp âm thanh phải có hình dạng giống nhau - Mix: {mixshape}, Inst: {instrumentalshape}",
"rubberband": "Không thể thực Rubberband. Vui lòng xác minh rằng Rubberband-cli đã được cài đặt.",
"rate": "Tỉ lệ phải hoàn toàn tích cực",
"gdown_error": "Không thể truy xuất liên kết công khai của tệp. Bạn có thể cần phải thay đổi quyền thành bất kỳ ai có liên kết hoặc đã có nhiều quyền truy cập.",
"to": "Đến:",
"gdown_value_error": "Phải chỉ định đường dẫn hoặc id",
"missing_url": "Thiếu đường dẫn",
"mac_not_match": "MAC không khớp",
"file_not_access": "Tệp tin không thể truy cập",
"int_resp==-3": "Yêu cầu không hoàn tất, đang thử lại",
"search_separate": "Tìm bản tách...",
"found_choice": "Tìm thấy {choice}",
"separator==0": "Không tìm thấy bản tách nào!",
"select_separate": "Chọn bản tách",
"start_app": "Khởi động giao diện...",
"provide_audio": "Nhập đường dẫn đến tệp âm thanh",
"set_torch_mps": "Cài đặt thiết bị Torch thành MPS",
"googletts": "Chuyển đổi văn bản bằng google",
"pitch_info_2": "Cao độ giọng nói của bộ chuyển đổi văn bản",
"waveform": "Dạng sóng phải có hình dạng (# khung, # kênh)",
"freq_mask_smooth_hz": "freq_mask_smooth_hz cần ít nhất là {hz}Hz",
"time_mask_smooth_ms": "time_mask_smooth_ms cần ít nhất là {ms}ms",
"x": "x phải lớn hơn",
"xn": "xn phải lớn hơn",
"not_found_pid": "Không thấy tiến trình nào!",
"end_pid": "Đã kết thúc tiến trình!",
"clean_audios": "Bắt đầu dọn dẹp âm thanh...",
"clean_audios_success": "Hoàn tất dọn dẹp tệp âm thanh!",
"clean_separate": "Bắt đầu dọn dẹp mô hình tách nhạc...",
"clean_separate_success": "Hoàn tất dọn dẹp mô hình tách nhạc!",
"clean_model": "Bắt đầu dọn dẹp mô hình...",
"clean_model_success": "Hoàn tất dọn dẹp tệp mô hình!",
"clean_index": "Bắt đầu dọn dẹp chỉ mục...",
"clean_index_success": "Hoàn tất dọn dẹp tệp chỉ mục!",
"clean_pretrain": "Bắt đầu dọn mô hình huấn luyện...",
"clean_pretrain_success": "Dọn tệp hoàn tất!",
"clean_all_audios": "Bắt đầu dọn tất cả tệp âm thanh...",
"clean_all_audios_success": "Hoàn tất dọn tất cả tệp âm thanh!",
"not_found_separate_model": "Không tìm thấy tệp mô hình tách nhạc nào!",
"clean_all_separate_model": "Bắt đầu dọn tất cả tệp mô hình tách nhạc...",
"clean_all_separate_model_success": "Hoàn tất dọn tất cả tệp mô hình tách nhạc!",
"clean_all_models_success": "Hoàn tất dọn dẹp tất cả các tệp mô hình",
"not_found_pretrained": "Không tìm thấy tệp mô hình huấn luyện trước nào!",
"clean_all_pretrained": "Bắt đầu dọn tất cả tệp mô hình huấn luyện trước...",
"clean_all_pretrained_success": "Hoàn tất dọn tất cả tệp mô hình huấn luyện trước!",
"not_found_log": "Không tìm thấy tệp nhật ký nào!",
"clean_all_log": "Bắt đầu dọn dẹp tất cả tệp nhật ký...",
"clean_all_log_success": "Hoàn tất dọn dẹp nhật ký!",
"not_found_predictors": "Không tìm thấy tệp mô hình dự đoán nào!",
"clean_all_predictors": "Bắt đầu dọn dẹp tất cả tệp mô hình dự đoán...",
"clean_all_predictors_success": "Hoàn tất dọn dẹp tất cả tệp mô hình dự đoán!",
"not_found_embedders": "Không tìm thấy tệp mô hình nhúng nào!",
"clean_all_embedders": "Bắt đầu dọn tất cả tệp mô hình nhúng...",
"clean_all_embedders_success": "Hoàn tất dọn dẹp tất cả tệp mô hình nhúng!",
"provide_folder": "Vui lòng cung cấp thư mục hợp lệ!",
"empty_folder": "Thư mục dữ liệu trống!",
"clean_dataset": "Bắt đầu dọn dẹp thư mục dữ liệu...",
"clean_dataset_success": "Hoàn tất dọn dẹp thư mục dữ liệu!",
"vocoder": "Bộ mã hóa",
"vocoder_info": "Bộ mã hóa giọng nói dùng để phân tích và tổng hợp tín hiệu giọng nói của con người để chuyển đổi giọng nói.",
"code_error": "Lỗi: Nhận mã trạng thái",
"json_error": "Lỗi: Không thể phân tích từ phản hồi.",
"requests_error": "Yêu cầu thất bại: {e}",
"memory_efficient_training": "Sử dụng hiệu quả bộ nhớ",
"not_use_pretrain_error_download": "Sẽ không dùng huấn luyện trước vì không có mô hình",
"start_clean_model": "Bắt đầu dọn tất cả mô hình...",
"provide_file_settings": "Vui lòng cung cấp tệp cài đặt trước!",
"load_presets": "Đã tải tệp cài đặt trước {presets}",
"provide_filename_settings": "Vui lòng cung cấp tên tệp cài đặt trước!",
"choose1": "Vui lòng chọn 1 để xuất!",
"export_settings": "Đã xuất tệp cài đặt trước {name}",
"use_presets": "Sử dụng tệp cài đặt trước",
"file_preset": "Tệp cài đặt trước",
"load_file": "Tải tệp",
"export_file": "Xuất tệp cài đặt trước",
"save_clean": "Lưu làm sạch",
"save_autotune": "Lưu tự điều chỉnh",
"save_pitch": "Lưu cao độ",
"save_index_2": "Lưu ảnh hưởng chỉ mục",
"save_resample": "Lưu lấy mẫu lại",
"save_filter": "Lưu trung vị",
"save_envelope": "Lưu đường bao âm",
"save_protect": "Lưu bảo vệ âm",
"save_split": "Lưu cắt âm",
"filename_to_save": "Tên khi lưu tệp",
"upload_presets": "Tải lên tệp cài đặt",
"stop": "Dừng tiến trình",
"stop_separate": "Dừng Tách Nhạc",
"stop_convert": "Dừng Chuyển Đổi",
"stop_create_dataset": "Dừng Tạo Dữ Liệu",
"stop_training": "Dừng Huấn Luyện",
"stop_extract": "Dừng Xử Lí Dữ Liệu",
"stop_preprocess": "Dừng Trích Xuất Dữ Liệu",
"cleaner": "Dọn Dẹp",
"clean_audio": "Dọn dẹp âm thanh",
"clean_all": "Dọn tất cả",
"clean_file": "Dọn tệp",
"clean_models": "Dọn tệp mô hình",
"clean_pretrained": "Dọn t���p mô hình huấn luyện trước",
"clean_separated": "Dọn tệp mô hình tách nhạc",
"clean_presets": "Dọn dẹp tệp cài đặt trước",
"clean_datasets": "Dọn dẹp thư mục dữ liệu huấn luyện",
"clean_dataset_folder": "Dọn thư mục dữ liệu",
"clean_log": "Dọn dẹp tệp nhật ký",
"clean_predictors": "Dọn mô hình dự đoán",
"clean_embed": "Dọn mô hình nhúng",
"clean_presets_2": "Bắt đầu dọn dẹp tệp cài đặt trước...",
"clean_presets_success": "Hoàn tất dọn dẹp tệp!",
"not_found_presets": "Không tìm thấy tệp cài đặt sẳn nào trong thư mục!",
"clean_all_presets": "Bắt đầu dọn dẹp tất cả tệp cài đặt sẳn...",
"clean_all_presets_success": "Hoàn tất dọn dẹp tất cả tệp cài đặt sẳn!",
"port": "Cổng {port} không thể dùng! Giảm cổng xuống một...",
"empty_json": "{file}: Bị lỗi hoặc trống",
"thank": "Cảm ơn bạn đã báo cáo lỗi và cũng xin lỗi bạn vì sự bất tiện do lỗi gây ra này!",
"error_read_log": "Đã xảy ra lỗi khi đọc các tệp nhật ký!",
"error_send": "Đã xảy ra lỗi khi gửi báo cáo! Hãy liên hệ tôi qua Discord: pham_huynh_anh!",
"report_bugs": "Báo Cáo Lỗi",
"agree_log": "Đồng ý cung cấp tất cả tệp nhật ký",
"error_info": "Mô tả lỗi",
"error_info_2": "Cung cấp thêm thông tin về lỗi",
"report_bug_info": "Báo cáo các lỗi xảy ra khi sử dụng chương trình",
"sr_info": "LƯU Ý: MỘT SỐ ĐỊNH DẠNG KHÔNG HỖ TRỢ TRÊN 48000",
"report_info": "Nếu được bạn hãy đồng ý cung cấp các tệp nhật ký để hỗ trợ quá trình sửa lỗi\n\nNếu không cung cấp các tệp nhật ký bạn hãy mô tả chi tiết lỗi, lỗi xảy ra khi nào ở đâu\n\nNếu hệ thống báo cáo này bị lỗi nốt thì bạn có thể liên hệ qua [ISSUE]({github}) hoặc discord: `pham_huynh_anh`",
"default_setting": "Đã xảy ra lỗi khi sử dụng tách, đặt tất cả cài đặt về mặc định...",
"dataset_folder1": "Vui lòng nhập tên thư mục dữ liệu",
"checkpointing_err": "Các tham số của mô hình đào tạo trước như tốc độ mẫu hoặc kiến trúc không khớp với mô hình đã chọn.",
"start_onnx_export": "Bắt đầu chuyển đổi mô hình sang dạng onnx",
"convert_model": "Chuyển Đổi Mô Hình",
"pytorch2onnx": "Chuyển Đổi Mô Hình PYTORCH Sang ONNX",
"pytorch2onnx_markdown": "Chuyển đổi mô hình RVC từ dạng pytorch sang onnx để tối ưu cho việc chuyển đổi âm thanh",
"error_readfile": "Đã xảy ra lỗi khi đọc tệp!",
"read_sf": "Đọc tệp âm thanh bằng soundfile...",
"read_librosa": "Đọc tệp âm thanh bằng librosa do soundfile không hỗ trợ...",
"f0_onnx_mode": "Chế độ F0 ONNX",
"f0_onnx_mode_info": "Trích xuất cao độ bằng mô hình ONNX có thể giúp tăng tốc độ",
"formantshift": "Dịch chuyển cao độ và âm sắc",
"formant_qfrency": "Tần số cho dịch chuyển định dạng",
"formant_timbre": "Âm sắc để chuyển đổi định dạng",
"time_frames": "Thời Gian (Khung)",
"Frequency": "Tần Số (Hz)",
"f0_extractor_tab": "Trích xuất F0",
"f0_extractor_markdown": "## Trích Xuất Cao Độ",
"f0_extractor_markdown_2": "Trích xuất cao độ F0 nhằm mục đích sử dụng cho suy luận chuyển đổi âm thanh",
"start_extract": "Bắt đầu quá trình trích xuất...",
"extract_done": "Hoàn tất quá trình trích xuất!",
"f0_file": "Sử dụng tệp F0 trích xuất trước",
"upload_f0": "Tải lên tệp F0",
"f0_file_2": "Tệp F0",
"clean_f0_file": "Dọp dẹp tệp F0",
"start_clean_f0": "Bắt đầu dọn dẹp tệp F0...",
"clean_f0_done": "Hoàn tất dọn dẹp tệp F0!",
"embed_onnx": "Chế độ nhúng ONNX",
"embed_onnx_info": "Trích xuất nhúng bằng mô hình ONNX có thể giúp tăng tốc độ"
}123version https://git-lfs.github.com/spec/v1oid sha256:9b9acf9ab7facdb032e1d687fe35182670b0b94566c4b209ae48c239d19956a6size 1332123version https://git-lfs.github.com/spec/v1oid sha256:30792849c8e72d67e6691754077f2888b101cb741e9c7f193c91dd9692870c87size 2536123version https://git-lfs.github.com/spec/v1oid sha256:9edcf85ec77e88bd01edf3d887bdc418d3596d573f7ad2694da546f41dae6bafsize 192078123version https://git-lfs.github.com/spec/v1oid sha256:67a816e77b50cb9f016e49e5c01f07e080c4e3b82b7a8ac3e64bcb143f90f31bsize 240078123version https://git-lfs.github.com/spec/v1oid sha256:55c55a03e13a694bcad2057d1a17392970886b17051443ddaf3666083609ee04size 529258123version https://git-lfs.github.com/spec/v1oid sha256:2f2bb4daaa106e351aebb001e5a25de985c0b472f22e8d60676bc924a79056eesize 288078123version https://git-lfs.github.com/spec/v1oid sha256:64d5abbac078e19a3f649c0d78a02cb33a71407ded3ddf2db78e6b803d0c0126size 152704123version https://git-lfs.github.com/spec/v1oid sha256:16ef62b957887ac9f0913aa5158f18983afff1ef5a3e4c5fd067ac20fc380d54size 457856123456789101112131415161718192021222324252627282930import os
import sys
import json
import logging
import webbrowser
from tensorboard import program
sys.path.append(os.getcwd())
from main.configs.config import Config
translations = Config().translations
with open(os.path.join("main", "configs", "config.json"), "r") as f:
configs = json.load(f)
def launch_tensorboard():
for l in ["root", "tensorboard"]:
logging.getLogger(l).setLevel(logging.ERROR)
tb = program.TensorBoard()
tb.configure(argv=[None, "--logdir", "assets/logs", f"--port={configs['tensorboard_port']}"])
url = tb.launch()
print(f"{translations['tensorboard_url']}: {url}")
if "--open" in sys.argv: webbrowser.open(url)
return f"{translations['tensorboard_url']}: {url}"
if __name__ == "__main__": launch_tensorboard()12345678910111213141516171819202122232425262728293031{
"language": "vi-VN",
"support_language": ["en-US", "vi-VN"],
"theme": "NoCrypt/miku",
"themes": ["NoCrypt/miku", "gstaff/xkcd", "JohnSmith9982/small_and_pretty", "ParityError/Interstellar", "earneleh/paris", "shivi/calm_seafoam", "Hev832/Applio", "YTheme/Minecraft", "gstaff/sketch", "SebastianBravo/simci_css", "allenai/gradio-theme", "Nymbo/Nymbo_Theme_5", "lone17/kotaemon", "Zarkel/IBM_Carbon_Theme", "SherlockRamos/Feliz", "freddyaboulton/dracula_revamped", "freddyaboulton/bad-theme-space", "gradio/dracula_revamped", "abidlabs/dracula_revamped", "gradio/dracula_test", "gradio/seafoam", "gradio/glass", "gradio/monochrome", "gradio/soft", "gradio/default", "gradio/base", "abidlabs/pakistan", "dawood/microsoft_windows", "ysharma/steampunk", "ysharma/huggingface", "abidlabs/Lime", "freddyaboulton/this-theme-does-not-exist-2", "aliabid94/new-theme", "aliabid94/test2", "aliabid94/test3", "aliabid94/test4", "abidlabs/banana", "freddyaboulton/test-blue", "gstaff/whiteboard", "ysharma/llamas", "abidlabs/font-test", "YenLai/Superhuman", "bethecloud/storj_theme", "sudeepshouche/minimalist", "knotdgaf/gradiotest", "ParityError/Anime", "Ajaxon6255/Emerald_Isle", "ParityError/LimeFace", "finlaymacklon/smooth_slate", "finlaymacklon/boxy_violet", "derekzen/stardust", "EveryPizza/Cartoony-Gradio-Theme", "Ifeanyi/Cyanister", "Tshackelton/IBMPlex-DenseReadable", "snehilsanyal/scikit-learn", "Himhimhim/xkcd", "nota-ai/theme", "rawrsor1/Everforest", "rottenlittlecreature/Moon_Goblin", "abidlabs/test-yellow", "abidlabs/test-yellow3", "idspicQstitho/dracula_revamped", "kfahn/AnimalPose", "HaleyCH/HaleyCH_Theme", "simulKitke/dracula_test", "braintacles/CrimsonNight", "wentaohe/whiteboardv2", "reilnuud/polite", "remilia/Ghostly", "Franklisi/darkmode", "coding-alt/soft", "xiaobaiyuan/theme_land", "step-3-profit/Midnight-Deep", "xiaobaiyuan/theme_demo", "Taithrah/Minimal", "Insuz/SimpleIndigo", "zkunn/Alipay_Gradio_theme", "Insuz/Mocha", "xiaobaiyuan/theme_brief", "Ama434/434-base-Barlow", "Ama434/def_barlow", "Ama434/neutral-barlow", "dawood/dracula_test", "nuttea/Softblue", "BlueDancer/Alien_Diffusion", "naughtondale/monochrome", "Dagfinn1962/standard", "default"],
"mdx_model": ["Main_340", "Main_390", "Main_406", "Main_427", "Main_438", "Inst_full_292", "Inst_HQ_1", "Inst_HQ_2", "Inst_HQ_3", "Inst_HQ_4", "Inst_HQ_5", "Kim_Vocal_1", "Kim_Vocal_2", "Kim_Inst", "Inst_187_beta", "Inst_82_beta", "Inst_90_beta", "Voc_FT", "Crowd_HQ", "Inst_1", "Inst_2", "Inst_3", "MDXNET_1_9703", "MDXNET_2_9682", "MDXNET_3_9662", "Inst_Main", "MDXNET_Main", "MDXNET_9482"],
"demucs_model": ["HT-Normal", "HT-Tuned", "HD_MMI", "HT_6S"],
"edge_tts": ["af-ZA-AdriNeural", "af-ZA-WillemNeural", "sq-AL-AnilaNeural", "sq-AL-IlirNeural", "am-ET-AmehaNeural", "am-ET-MekdesNeural", "ar-DZ-AminaNeural", "ar-DZ-IsmaelNeural", "ar-BH-AliNeural", "ar-BH-LailaNeural", "ar-EG-SalmaNeural", "ar-EG-ShakirNeural", "ar-IQ-BasselNeural", "ar-IQ-RanaNeural", "ar-JO-SanaNeural", "ar-JO-TaimNeural", "ar-KW-FahedNeural", "ar-KW-NouraNeural", "ar-LB-LaylaNeural", "ar-LB-RamiNeural", "ar-LY-ImanNeural", "ar-LY-OmarNeural", "ar-MA-JamalNeural", "ar-MA-MounaNeural", "ar-OM-AbdullahNeural", "ar-OM-AyshaNeural", "ar-QA-AmalNeural", "ar-QA-MoazNeural", "ar-SA-HamedNeural", "ar-SA-ZariyahNeural", "ar-SY-AmanyNeural", "ar-SY-LaithNeural", "ar-TN-HediNeural", "ar-TN-ReemNeural", "ar-AE-FatimaNeural", "ar-AE-HamdanNeural", "ar-YE-MaryamNeural", "ar-YE-SalehNeural", "az-AZ-BabekNeural", "az-AZ-BanuNeural", "bn-BD-NabanitaNeural", "bn-BD-PradeepNeural", "bn-IN-BashkarNeural", "bn-IN-TanishaaNeural", "bs-BA-GoranNeural", "bs-BA-VesnaNeural", "bg-BG-BorislavNeural", "bg-BG-KalinaNeural", "my-MM-NilarNeural", "my-MM-ThihaNeural", "ca-ES-EnricNeural", "ca-ES-JoanaNeural", "zh-HK-HiuGaaiNeural", "zh-HK-HiuMaanNeural", "zh-HK-WanLungNeural", "zh-CN-XiaoxiaoNeural", "zh-CN-XiaoyiNeural", "zh-CN-YunjianNeural", "zh-CN-YunxiNeural", "zh-CN-YunxiaNeural", "zh-CN-YunyangNeural", "zh-CN-liaoning-XiaobeiNeural", "zh-TW-HsiaoChenNeural", "zh-TW-YunJheNeural", "zh-TW-HsiaoYuNeural", "zh-CN-shaanxi-XiaoniNeural", "hr-HR-GabrijelaNeural", "hr-HR-SreckoNeural", "cs-CZ-AntoninNeural", "cs-CZ-VlastaNeural", "da-DK-ChristelNeural", "da-DK-JeppeNeural", "nl-BE-ArnaudNeural", "nl-BE-DenaNeural", "nl-NL-ColetteNeural", "nl-NL-FennaNeural", "nl-NL-MaartenNeural", "en-AU-NatashaNeural", "en-AU-WilliamNeural", "en-CA-ClaraNeural", "en-CA-LiamNeural", "en-HK-SamNeural", "en-HK-YanNeural", "en-IN-NeerjaExpressiveNeural", "en-IN-NeerjaNeural", "en-IN-PrabhatNeural", "en-IE-ConnorNeural", "en-IE-EmilyNeural", "en-KE-AsiliaNeural", "en-KE-ChilembaNeural", "en-NZ-MitchellNeural", "en-NZ-MollyNeural", "en-NG-AbeoNeural", "en-NG-EzinneNeural", "en-PH-JamesNeural", "en-PH-RosaNeural", "en-SG-LunaNeural", "en-SG-WayneNeural", "en-ZA-LeahNeural", "en-ZA-LukeNeural", "en-TZ-ElimuNeural", "en-TZ-ImaniNeural", "en-GB-LibbyNeural", "en-GB-MaisieNeural", "en-GB-RyanNeural", "en-GB-SoniaNeural", "en-GB-ThomasNeural", "en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural", "en-US-EmmaMultilingualNeural", "en-US-BrianMultilingualNeural", "en-US-AvaNeural", "en-US-AndrewNeural", "en-US-EmmaNeural", "en-US-BrianNeural", "en-US-AnaNeural", "en-US-AriaNeural", "en-US-ChristopherNeural", "en-US-EricNeural", "en-US-GuyNeural", "en-US-JennyNeural", "en-US-MichelleNeural", "en-US-RogerNeural", "en-US-SteffanNeural", "et-EE-AnuNeural", "et-EE-KertNeural", "fil-PH-AngeloNeural", "fil-PH-BlessicaNeural", "fi-FI-HarriNeural", "fi-FI-NooraNeural", "fr-BE-CharlineNeural", "fr-BE-GerardNeural", "fr-CA-ThierryNeural", "fr-CA-AntoineNeural", "fr-CA-JeanNeural", "fr-CA-SylvieNeural", "fr-FR-VivienneMultilingualNeural", "fr-FR-RemyMultilingualNeural", "fr-FR-DeniseNeural", "fr-FR-EloiseNeural", "fr-FR-HenriNeural", "fr-CH-ArianeNeural", "fr-CH-FabriceNeural", "gl-ES-RoiNeural", "gl-ES-SabelaNeural", "ka-GE-EkaNeural", "ka-GE-GiorgiNeural", "de-AT-IngridNeural", "de-AT-JonasNeural", "de-DE-SeraphinaMultilingualNeural", "de-DE-FlorianMultilingualNeural", "de-DE-AmalaNeural", "de-DE-ConradNeural", "de-DE-KatjaNeural", "de-DE-KillianNeural", "de-CH-JanNeural", "de-CH-LeniNeural", "el-GR-AthinaNeural", "el-GR-NestorasNeural", "gu-IN-DhwaniNeural", "gu-IN-NiranjanNeural", "he-IL-AvriNeural", "he-IL-HilaNeural", "hi-IN-MadhurNeural", "hi-IN-SwaraNeural", "hu-HU-NoemiNeural", "hu-HU-TamasNeural", "is-IS-GudrunNeural", "is-IS-GunnarNeural", "id-ID-ArdiNeural", "id-ID-GadisNeural", "ga-IE-ColmNeural", "ga-IE-OrlaNeural", "it-IT-GiuseppeNeural", "it-IT-DiegoNeural", "it-IT-ElsaNeural", "it-IT-IsabellaNeural", "ja-JP-KeitaNeural", "ja-JP-NanamiNeural", "jv-ID-DimasNeural", "jv-ID-SitiNeural", "kn-IN-GaganNeural", "kn-IN-SapnaNeural", "kk-KZ-AigulNeural", "kk-KZ-DauletNeural", "km-KH-PisethNeural", "km-KH-SreymomNeural", "ko-KR-HyunsuNeural", "ko-KR-InJoonNeural", "ko-KR-SunHiNeural", "lo-LA-ChanthavongNeural", "lo-LA-KeomanyNeural", "lv-LV-EveritaNeural", "lv-LV-NilsNeural", "lt-LT-LeonasNeural", "lt-LT-OnaNeural", "mk-MK-AleksandarNeural", "mk-MK-MarijaNeural", "ms-MY-OsmanNeural", "ms-MY-YasminNeural", "ml-IN-MidhunNeural", "ml-IN-SobhanaNeural", "mt-MT-GraceNeural", "mt-MT-JosephNeural", "mr-IN-AarohiNeural", "mr-IN-ManoharNeural", "mn-MN-BataaNeural", "mn-MN-YesuiNeural", "ne-NP-HemkalaNeural", "ne-NP-SagarNeural", "nb-NO-FinnNeural", "nb-NO-PernilleNeural", "ps-AF-GulNawazNeural", "ps-AF-LatifaNeural", "fa-IR-DilaraNeural", "fa-IR-FaridNeural", "pl-PL-MarekNeural", "pl-PL-ZofiaNeural", "pt-BR-ThalitaNeural", "pt-BR-AntonioNeural", "pt-BR-FranciscaNeural", "pt-PT-DuarteNeural", "pt-PT-RaquelNeural", "ro-RO-AlinaNeural", "ro-RO-EmilNeural", "ru-RU-DmitryNeural", "ru-RU-SvetlanaNeural", "sr-RS-NicholasNeural", "sr-RS-SophieNeural", "si-LK-SameeraNeural", "si-LK-ThiliniNeural", "sk-SK-LukasNeural", "sk-SK-ViktoriaNeural", "sl-SI-PetraNeural", "sl-SI-RokNeural", "so-SO-MuuseNeural", "so-SO-UbaxNeural", "es-AR-ElenaNeural", "es-AR-TomasNeural", "es-BO-MarceloNeural", "es-BO-SofiaNeural", "es-CL-CatalinaNeural", "es-CL-LorenzoNeural", "es-ES-XimenaNeural", "es-CO-GonzaloNeural", "es-CO-SalomeNeural", "es-CR-JuanNeural", "es-CR-MariaNeural", "es-CU-BelkysNeural", "es-CU-ManuelNeural", "es-DO-EmilioNeural", "es-DO-RamonaNeural", "es-EC-AndreaNeural", "es-EC-LuisNeural", "es-SV-LorenaNeural", "es-SV-RodrigoNeural", "es-GQ-JavierNeural", "es-GQ-TeresaNeural", "es-GT-AndresNeural", "es-GT-MartaNeural", "es-HN-CarlosNeural", "es-HN-KarlaNeural", "es-MX-DaliaNeural", "es-MX-JorgeNeural", "es-NI-FedericoNeural", "es-NI-YolandaNeural", "es-PA-MargaritaNeural", "es-PA-RobertoNeural", "es-PY-MarioNeural", "es-PY-TaniaNeural", "es-PE-AlexNeural", "es-PE-CamilaNeural", "es-PR-KarinaNeural", "es-PR-VictorNeural", "es-ES-AlvaroNeural", "es-ES-ElviraNeural", "es-US-AlonsoNeural", "es-US-PalomaNeural", "es-UY-MateoNeural", "es-UY-ValentinaNeural", "es-VE-PaolaNeural", "es-VE-SebastianNeural", "su-ID-JajangNeural", "su-ID-TutiNeural", "sw-KE-RafikiNeural", "sw-KE-ZuriNeural", "sw-TZ-DaudiNeural", "sw-TZ-RehemaNeural", "sv-SE-MattiasNeural", "sv-SE-SofieNeural", "ta-IN-PallaviNeural", "ta-IN-ValluvarNeural", "ta-MY-KaniNeural", "ta-MY-SuryaNeural", "ta-SG-AnbuNeural", "ta-SG-VenbaNeural", "ta-LK-KumarNeural", "ta-LK-SaranyaNeural", "te-IN-MohanNeural", "te-IN-ShrutiNeural", "th-TH-NiwatNeural", "th-TH-PremwadeeNeural", "tr-TR-AhmetNeural", "tr-TR-EmelNeural", "uk-UA-OstapNeural", "uk-UA-PolinaNeural", "ur-IN-GulNeural", "ur-IN-SalmanNeural", "ur-PK-AsadNeural", "ur-PK-UzmaNeural", "uz-UZ-MadinaNeural", "uz-UZ-SardorNeural", "vi-VN-HoaiMyNeural", "vi-VN-NamMinhNeural", "cy-GB-AledNeural", "cy-GB-NiaNeural", "zu-ZA-ThandoNeural", "zu-ZA-ThembaNeural"],
"google_tts_voice": ["af", "am", "ar", "bg", "bn", "bs", "ca", "cs", "cy", "da", "de", "el", "en", "es", "et", "eu", "fi", "fr", "fr-CA", "gl", "gu", "ha", "hi", "hr", "hu", "id", "is", "it", "iw", "ja", "jw", "km", "kn", "ko", "la", "lt", "lv", "ml", "mr", "ms", "my", "ne", "nl", "no", "pa", "pl", "pt", "pt-PT", "ro", "ru", "si", "sk", "sq", "sr", "su", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "ur", "vi", "yue", "zh-CN", "zh-TW", "zh"],
"separator_tab": true,
"convert_tab": true,
"tts_tab": true,
"effects_tab": true,
"create_dataset_tab": true,
"training_tab": true,
"fushion_tab": true,
"read_tab": true,
"onnx_tab": true,
"downloads_tab": true,
"f0_extractor_tab": true,
"settings_tab": true,
"report_bug_tab": true,
"app_port": 7860,
"tensorboard_port": 6870,
"num_of_restart": 5,
"server_name": "0.0.0.0",
"app_show_error": true
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import osimport jsonimport torch
version_config_paths = [os.path.join(version, size) for version in ["v1", "v2"] for size in ["32000.json", "40000.json", "44100.json", "48000.json"]]
def singleton(cls): instances = {} def get_instance(*args, **kwargs): if cls not in instances: instances[cls] = cls(*args, **kwargs) return instances[cls] return get_instance
@singletonclass Config: def __init__(self): self.device = "cuda:0" if torch.cuda.is_available() else "cpu" self.gpu_name = (torch.cuda.get_device_name(int(self.device.split(":")[-1])) if self.device.startswith("cuda") else None) self.translations = self.multi_language() self.json_config = self.load_config_json() self.gpu_mem = None self.x_pad, self.x_query, self.x_center, self.x_max = self.device_config() def multi_language(self): try: with open(os.path.join("main", "configs", "config.json"), "r") as f: configs = json.load(f)
lang = configs.get("language", "vi-VN") if len([l for l in os.listdir(os.path.join("assets", "languages")) if l.endswith(".json")]) < 1: raise FileNotFoundError("Không tìm thấy bất cứ gói ngôn ngữ nào(No package languages found)")
if not lang: lang = "vi-VN" if lang not in configs["support_language"]: raise ValueError("Ngôn ngữ không được hỗ trợ(Language not supported)")
lang_path = os.path.join("assets", "languages", f"{lang}.json") if not os.path.exists(lang_path): lang_path = os.path.join("assets", "languages", "vi-VN.json")
with open(lang_path, encoding="utf-8") as f: translations = json.load(f) except json.JSONDecodeError: print(self.translations["empty_json"].format(file=lang)) pass return translations
def load_config_json(self): configs = {} for config_file in version_config_paths: try: with open(os.path.join("main", "configs", config_file), "r") as f: configs[config_file] = json.load(f) except json.JSONDecodeError: print(self.translations["empty_json"].format(file=config_file)) pass return configs
def device_config(self): if self.device.startswith("cuda"): self.set_cuda_config() elif self.has_mps(): self.device = "mps" else: self.device = "cpu"
if self.gpu_mem is not None and self.gpu_mem <= 4: return 1, 5, 30, 32 return 1, 6, 38, 41
def set_cuda_config(self): i_device = int(self.device.split(":")[-1]) self.gpu_name = torch.cuda.get_device_name(i_device) self.gpu_mem = torch.cuda.get_device_properties(i_device).total_memory // (1024**3)
def has_mps(self): return torch.backends.mps.is_available()123version https://git-lfs.github.com/spec/v1oid sha256:330268cbf6b9317a76510b533e1640ef48ed074a07c013e5b1abc4d48cfd9dcesize 3212345678910111213141516171819202122232425262728293031323334353637383940414243444546{
"train": {
"log_interval": 200,
"seed": 1234,
"epochs": 20000,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"batch_size": 4,
"lr_decay": 0.999875,
"segment_size": 12800,
"init_lr_ratio": 1,
"warmup_epochs": 0,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 32000,
"filter_length": 1024,
"hop_length": 320,
"win_length": 1024,
"n_mel_channels": 80,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 256,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 4, 2, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [16, 16, 4, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546{
"train": {
"log_interval": 200,
"seed": 1234,
"epochs": 20000,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"batch_size": 4,
"lr_decay": 0.999875,
"segment_size": 12800,
"init_lr_ratio": 1,
"warmup_epochs": 0,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 40000,
"filter_length": 2048,
"hop_length": 400,
"win_length": 2048,
"n_mel_channels": 125,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 256,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 10, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [16, 16, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546{
"train": {
"log_interval": 200,
"seed": 1234,
"epochs": 20000,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"batch_size": 4,
"lr_decay": 0.999875,
"segment_size": 15876,
"init_lr_ratio": 1,
"warmup_epochs": 0,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 44100,
"filter_length": 2048,
"hop_length": 441,
"win_length": 2048,
"n_mel_channels": 128,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 256,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [ 1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 10, 2.205, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [20, 20, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}12345678910111213141516171819202122232425262728293031323334353637383940414243444546{
"train": {
"log_interval": 200,
"seed": 1234,
"epochs": 20000,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"batch_size": 4,
"lr_decay": 0.999875,
"segment_size": 11520,
"init_lr_ratio": 1,
"warmup_epochs": 0,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 48000,
"filter_length": 2048,
"hop_length": 480,
"win_length": 2048,
"n_mel_channels": 128,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 256,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 6, 2, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [16, 16, 4, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}123456789101112131415161718192021222324252627282930313233343536373839404142{
"train": {
"log_interval": 200,
"seed": 1234,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"lr_decay": 0.999875,
"segment_size": 12800,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 32000,
"filter_length": 1024,
"hop_length": 320,
"win_length": 1024,
"n_mel_channels": 80,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 768,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 8, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [20, 16, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}123456789101112131415161718192021222324252627282930313233343536373839404142{
"train": {
"log_interval": 200,
"seed": 1234,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"lr_decay": 0.999875,
"segment_size": 12800,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 40000,
"filter_length": 2048,
"hop_length": 400,
"win_length": 2048,
"n_mel_channels": 125,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 768,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 10, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [16, 16, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}123456789101112131415161718192021222324252627282930313233343536373839404142{
"train": {
"log_interval": 200,
"seed": 1234,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"lr_decay": 0.999875,
"segment_size": 15876,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 44100,
"filter_length": 2048,
"hop_length": 441,
"win_length": 2048,
"n_mel_channels": 128,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 768,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [10, 10, 2.205, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [20, 20, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}123456789101112131415161718192021222324252627282930313233343536373839404142{
"train": {
"log_interval": 200,
"seed": 1234,
"learning_rate": 0.0001,
"betas": [0.8, 0.99],
"eps": 1e-09,
"lr_decay": 0.999875,
"segment_size": 17280,
"c_mel": 45,
"c_kl": 1.0
},
"data": {
"max_wav_value": 32768.0,
"sample_rate": 48000,
"filter_length": 2048,
"hop_length": 480,
"win_length": 2048,
"n_mel_channels": 128,
"mel_fmin": 0.0,
"mel_fmax": null
},
"model": {
"inter_channels": 192,
"hidden_channels": 192,
"filter_channels": 768,
"text_enc_hidden_dim": 768,
"n_heads": 2,
"n_layers": 6,
"kernel_size": 3,
"p_dropout": 0,
"resblock": "1",
"resblock_kernel_sizes": [3, 7, 11],
"resblock_dilation_sizes": [[1, 3, 5], [1, 3, 5], [1, 3, 5]],
"upsample_rates": [12, 10, 2, 2],
"upsample_initial_channel": 512,
"upsample_kernel_sizes": [24, 20, 4, 4],
"use_spectral_norm": false,
"gin_channels": 256,
"spk_embed_dim": 109
}
}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180import os
import sys
import librosa
import argparse
import numpy as np
import soundfile as sf
from distutils.util import strtobool
from scipy.signal import butter, filtfilt
from pedalboard import Pedalboard, Chorus, Distortion, Reverb, PitchShift, Delay, Limiter, Gain, Bitcrush, Clipping, Compressor, Phaser, HighpassFilter
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.utils import pydub_convert, pydub_load
translations = Config().translations
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--input_path", type=str, required=True)
parser.add_argument("--output_path", type=str, default="./audios/apply_effects.wav")
parser.add_argument("--export_format", type=str, default="wav")
parser.add_argument("--resample", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--resample_sr", type=int, default=0)
parser.add_argument("--chorus", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--chorus_depth", type=float, default=0.5)
parser.add_argument("--chorus_rate", type=float, default=1.5)
parser.add_argument("--chorus_mix", type=float, default=0.5)
parser.add_argument("--chorus_delay", type=int, default=10)
parser.add_argument("--chorus_feedback", type=float, default=0)
parser.add_argument("--distortion", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--drive_db", type=int, default=20)
parser.add_argument("--reverb", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--reverb_room_size", type=float, default=0.5)
parser.add_argument("--reverb_damping", type=float, default=0.5)
parser.add_argument("--reverb_wet_level", type=float, default=0.33)
parser.add_argument("--reverb_dry_level", type=float, default=0.67)
parser.add_argument("--reverb_width", type=float, default=1)
parser.add_argument("--reverb_freeze_mode", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--pitchshift", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--pitch_shift", type=int, default=0)
parser.add_argument("--delay", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--delay_seconds", type=float, default=0.5)
parser.add_argument("--delay_feedback", type=float, default=0.5)
parser.add_argument("--delay_mix", type=float, default=0.5)
parser.add_argument("--compressor", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--compressor_threshold", type=int, default=-20)
parser.add_argument("--compressor_ratio", type=float, default=4)
parser.add_argument("--compressor_attack_ms", type=float, default=10)
parser.add_argument("--compressor_release_ms", type=int, default=200)
parser.add_argument("--limiter", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--limiter_threshold", type=int, default=0)
parser.add_argument("--limiter_release", type=int, default=100)
parser.add_argument("--gain", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--gain_db", type=int, default=0)
parser.add_argument("--bitcrush", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--bitcrush_bit_depth", type=int, default=16)
parser.add_argument("--clipping", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clipping_threshold", type=int, default=-10)
parser.add_argument("--phaser", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--phaser_rate_hz", type=float, default=0.5)
parser.add_argument("--phaser_depth", type=float, default=0.5)
parser.add_argument("--phaser_centre_frequency_hz", type=int, default=1000)
parser.add_argument("--phaser_feedback", type=float, default=0)
parser.add_argument("--phaser_mix", type=float, default=0.5)
parser.add_argument("--treble_bass_boost", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--bass_boost_db", type=int, default=0)
parser.add_argument("--bass_boost_frequency", type=int, default=100)
parser.add_argument("--treble_boost_db", type=int, default=0)
parser.add_argument("--treble_boost_frequency", type=int, default=3000)
parser.add_argument("--fade_in_out", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--fade_in_duration", type=float, default=2000)
parser.add_argument("--fade_out_duration", type=float, default=2000)
parser.add_argument("--audio_combination", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--audio_combination_input", type=str)
return parser.parse_args()
def process_audio(input_path, output_path, resample, resample_sr, chorus_depth, chorus_rate, chorus_mix, chorus_delay, chorus_feedback, distortion_drive, reverb_room_size, reverb_damping, reverb_wet_level, reverb_dry_level, reverb_width, reverb_freeze_mode, pitch_shift, delay_seconds, delay_feedback, delay_mix, compressor_threshold, compressor_ratio, compressor_attack_ms, compressor_release_ms, limiter_threshold, limiter_release, gain_db, bitcrush_bit_depth, clipping_threshold, phaser_rate_hz, phaser_depth, phaser_centre_frequency_hz, phaser_feedback, phaser_mix, bass_boost_db, bass_boost_frequency, treble_boost_db, treble_boost_frequency, fade_in_duration, fade_out_duration, export_format, chorus, distortion, reverb, pitchshift, delay, compressor, limiter, gain, bitcrush, clipping, phaser, treble_bass_boost, fade_in_out, audio_combination, audio_combination_input):
def bass_boost(audio, gain_db, frequency, sample_rate):
if gain_db >= 1:
b, a = butter(4, frequency / (0.5 * sample_rate), btype='low')
return filtfilt(b, a, audio) * 10 ** (gain_db / 20)
else: return audio
def treble_boost(audio, gain_db, frequency, sample_rate):
if gain_db >=1:
b, a = butter(4, frequency / (0.5 * sample_rate), btype='high')
return filtfilt(b, a, audio) * 10 ** (gain_db / 20)
else: return audio
def fade_out_effect(audio, sr, duration=3.0):
length = int(duration * sr)
end = audio.shape[0]
if length > end: length = end
start = end - length
audio[start:end] = audio[start:end] * np.linspace(1.0, 0.0, length)
return audio
def fade_in_effect(audio, sr, duration=3.0):
length = int(duration * sr)
start = 0
if length > audio.shape[0]: length = audio.shape[0]
end = length
audio[start:end] = audio[start:end] * np.linspace(0.0, 1.0, length)
return audio
if not input_path or not os.path.exists(input_path):
print(translations["input_not_valid"])
sys.exit(1)
if not output_path:
print(translations["output_not_valid"])
sys.exit(1)
if os.path.exists(output_path): os.remove(output_path)
try:
input_path = input_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
try:
audio, sample_rate = sf.read(input_path)
except:
audio, sample_rate = librosa.load(input_path, sr=None)
except Exception as e:
raise RuntimeError(f"{translations['errors_loading_audio']}: {e}")
audio = audio.flatten()
try:
board = Pedalboard([HighpassFilter()])
if chorus: board.append(Chorus(depth=chorus_depth, rate_hz=chorus_rate, mix=chorus_mix, centre_delay_ms=chorus_delay, feedback=chorus_feedback))
if distortion: board.append(Distortion(drive_db=distortion_drive))
if reverb: board.append(Reverb(room_size=reverb_room_size, damping=reverb_damping, wet_level=reverb_wet_level, dry_level=reverb_dry_level, width=reverb_width, freeze_mode=1 if reverb_freeze_mode else 0))
if pitchshift: board.append(PitchShift(semitones=pitch_shift))
if delay: board.append(Delay(delay_seconds=delay_seconds, feedback=delay_feedback, mix=delay_mix))
if compressor: board.append(Compressor(threshold_db=compressor_threshold, ratio=compressor_ratio, attack_ms=compressor_attack_ms, release_ms=compressor_release_ms))
if limiter: board.append(Limiter(threshold_db=limiter_threshold, release_ms=limiter_release))
if gain: board.append(Gain(gain_db=gain_db))
if bitcrush: board.append(Bitcrush(bit_depth=bitcrush_bit_depth))
if clipping: board.append(Clipping(threshold_db=clipping_threshold))
if phaser: board.append(Phaser(rate_hz=phaser_rate_hz, depth=phaser_depth, centre_frequency_hz=phaser_centre_frequency_hz, feedback=phaser_feedback, mix=phaser_mix))
processed_audio = board(audio, sample_rate)
if treble_bass_boost:
processed_audio = bass_boost(processed_audio, bass_boost_db, bass_boost_frequency, sample_rate)
processed_audio = treble_boost(processed_audio, treble_boost_db, treble_boost_frequency, sample_rate)
if fade_in_out:
processed_audio = fade_in_effect(processed_audio, sample_rate, fade_in_duration)
processed_audio = fade_out_effect(processed_audio, sample_rate, fade_out_duration)
if resample_sr != sample_rate and resample_sr > 0 and resample:
target_sr = min([8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 96000], key=lambda x: abs(x - resample_sr))
processed_audio = librosa.resample(processed_audio, orig_sr=sample_rate, target_sr=target_sr, res_type="soxr_vhq")
sample_rate = target_sr
sf.write(output_path.replace("wav", export_format), processed_audio, sample_rate, format=export_format)
if audio_combination: pydub_convert(pydub_load(audio_combination_input)).overlay(pydub_convert(pydub_load(output_path.replace("wav", export_format)))).export(output_path.replace("wav", export_format), format=export_format)
except Exception as e:
raise RuntimeError(translations["apply_error"].format(e=e))
return output_path
if __name__ == "__main__":
args = parse_arguments()
process_audio(input_path=args.input_path, output_path=args.output_path, resample=args.resample, resample_sr=args.resample_sr, chorus_depth=args.chorus_depth, chorus_rate=args.chorus_rate, chorus_mix=args.chorus_mix, chorus_delay=args.chorus_delay, chorus_feedback=args.chorus_feedback, distortion_drive=args.drive_db, reverb_room_size=args.reverb_room_size, reverb_damping=args.reverb_damping, reverb_wet_level=args.reverb_wet_level, reverb_dry_level=args.reverb_dry_level, reverb_width=args.reverb_width, reverb_freeze_mode=args.reverb_freeze_mode, pitch_shift=args.pitch_shift, delay_seconds=args.delay_seconds, delay_feedback=args.delay_feedback, delay_mix=args.delay_mix, compressor_threshold=args.compressor_threshold, compressor_ratio=args.compressor_ratio, compressor_attack_ms=args.compressor_attack_ms, compressor_release_ms=args.compressor_release_ms, limiter_threshold=args.limiter_threshold, limiter_release=args.limiter_release, gain_db=args.gain_db, bitcrush_bit_depth=args.bitcrush_bit_depth, clipping_threshold=args.clipping_threshold, phaser_rate_hz=args.phaser_rate_hz, phaser_depth=args.phaser_depth, phaser_centre_frequency_hz=args.phaser_centre_frequency_hz, phaser_feedback=args.phaser_feedback, phaser_mix=args.phaser_mix, bass_boost_db=args.bass_boost_db, bass_boost_frequency=args.bass_boost_frequency, treble_boost_db=args.treble_boost_db, treble_boost_frequency=args.treble_boost_frequency, fade_in_duration=args.fade_in_duration, fade_out_duration=args.fade_out_duration, export_format=args.export_format, chorus=args.chorus, distortion=args.distortion, reverb=args.reverb, pitchshift=args.pitchshift, delay=args.delay, compressor=args.compressor, limiter=args.limiter, gain=args.gain, bitcrush=args.bitcrush, clipping=args.clipping, phaser=args.phaser, treble_bass_boost=args.treble_bass_boost, fade_in_out=args.fade_in_out, audio_combination=args.audio_combination, audio_combination_input=args.audio_combination_input)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680import re
import os
import sys
import time
import faiss
import torch
import shutil
import librosa
import logging
import argparse
import warnings
import onnxruntime
import logging.handlers
import numpy as np
import soundfile as sf
import torch.nn.functional as F
from tqdm import tqdm
from scipy import signal
from distutils.util import strtobool
from fairseq import checkpoint_utils
warnings.filterwarnings("ignore")
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.algorithm.synthesizers import Synthesizer
from main.library.utils import check_predictors, check_embedders, load_audio, process_audio, merge_audio
bh, ah = signal.butter(N=5, Wn=48, btype="high", fs=16000)
config = Config()
translations = config.translations
logger = logging.getLogger(__name__)
logger.propagate = False
for l in ["torch", "faiss", "httpx", "fairseq", "httpcore", "faiss.loader", "numba.core", "urllib3"]:
logging.getLogger(l).setLevel(logging.ERROR)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join("assets", "logs", "convert.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--pitch", type=int, default=0)
parser.add_argument("--filter_radius", type=int, default=3)
parser.add_argument("--index_rate", type=float, default=0.5)
parser.add_argument("--volume_envelope", type=float, default=1)
parser.add_argument("--protect", type=float, default=0.33)
parser.add_argument("--hop_length", type=int, default=64)
parser.add_argument("--f0_method", type=str, default="rmvpe")
parser.add_argument("--embedder_model", type=str, default="contentvec_base.pt")
parser.add_argument("--input_path", type=str, required=True)
parser.add_argument("--output_path", type=str, default="./audios/output.wav")
parser.add_argument("--export_format", type=str, default="wav")
parser.add_argument("--pth_path", type=str, required=True)
parser.add_argument("--index_path", type=str)
parser.add_argument("--f0_autotune", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--f0_autotune_strength", type=float, default=1)
parser.add_argument("--clean_audio", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clean_strength", type=float, default=0.7)
parser.add_argument("--resample_sr", type=int, default=0)
parser.add_argument("--split_audio", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--checkpointing", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--f0_file", type=str, default=None)
parser.add_argument("--f0_onnx", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--embedders_onnx", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--formant_shifting", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--formant_qfrency", type=float, default=0.8)
parser.add_argument("--formant_timbre", type=float, default=0.8)
return parser.parse_args()
def main():
args = parse_arguments()
pitch, filter_radius, index_rate, volume_envelope, protect, hop_length, f0_method, input_path, output_path, pth_path, index_path, f0_autotune, f0_autotune_strength, clean_audio, clean_strength, export_format, embedder_model, resample_sr, split_audio, checkpointing, f0_file, f0_onnx, embedders_onnx, formant_shifting, formant_qfrency, formant_timbre = args.pitch, args.filter_radius, args.index_rate, args.volume_envelope,args.protect, args.hop_length, args.f0_method, args.input_path, args.output_path, args.pth_path, args.index_path, args.f0_autotune, args.f0_autotune_strength, args.clean_audio, args.clean_strength, args.export_format, args.embedder_model, args.resample_sr, args.split_audio, args.checkpointing, args.f0_file, args.f0_onnx, args.embedders_onnx, args.formant_shifting, args.formant_qfrency, args.formant_timbre
log_data = {translations['pitch']: pitch, translations['filter_radius']: filter_radius, translations['index_strength']: index_rate, translations['volume_envelope']: volume_envelope, translations['protect']: protect, "Hop length": hop_length, translations['f0_method']: f0_method, translations['audio_path']: input_path, translations['output_path']: output_path.replace('wav', export_format), translations['model_path']: pth_path, translations['indexpath']: index_path, translations['autotune']: f0_autotune, translations['clear_audio']: clean_audio, translations['export_format']: export_format, translations['hubert_model']: embedder_model, translations['split_audio']: split_audio, translations['memory_efficient_training']: checkpointing, translations["f0_onnx_mode"]: f0_onnx, translations["embed_onnx"]: embedders_onnx}
if clean_audio: log_data[translations['clean_strength']] = clean_strength
if resample_sr != 0: log_data[translations['sample_rate']] = resample_sr
if f0_autotune: log_data[translations['autotune_rate_info']] = f0_autotune_strength
if os.path.isfile(f0_file): log_data[translations['f0_file']] = f0_file
if formant_shifting:
log_data[translations['formant_qfrency']] = formant_qfrency
log_data[translations['formant_timbre']] = formant_timbre
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
run_convert_script(pitch=pitch, filter_radius=filter_radius, index_rate=index_rate, volume_envelope=volume_envelope, protect=protect, hop_length=hop_length, f0_method=f0_method, input_path=input_path, output_path=output_path, pth_path=pth_path, index_path=index_path, f0_autotune=f0_autotune, f0_autotune_strength=f0_autotune_strength, clean_audio=clean_audio, clean_strength=clean_strength, export_format=export_format, embedder_model=embedder_model, resample_sr=resample_sr, split_audio=split_audio, checkpointing=checkpointing, f0_file=f0_file, f0_onnx=f0_onnx, embedders_onnx=embedders_onnx, formant_shifting=formant_shifting, formant_qfrency=formant_qfrency, formant_timbre=formant_timbre)
def run_batch_convert(params):
path, audio_temp, export_format, cut_files, pitch, filter_radius, index_rate, volume_envelope, protect, hop_length, f0_method, pth_path, index_path, f0_autotune, f0_autotune_strength, clean_audio, clean_strength, embedder_model, resample_sr, checkpointing, f0_file, f0_onnx, formant_shifting, formant_qfrency, formant_timbre = params["path"], params["audio_temp"], params["export_format"], params["cut_files"], params["pitch"], params["filter_radius"], params["index_rate"], params["volume_envelope"], params["protect"], params["hop_length"], params["f0_method"], params["pth_path"], params["index_path"], params["f0_autotune"], params["f0_autotune_strength"], params["clean_audio"], params["clean_strength"], params["embedder_model"], params["resample_sr"], params["checkpointing"], params["f0_file"], params["f0_onnx"], params["formant_shifting"], params["formant_qfrency"], params["formant_timbre"]
segment_output_path = os.path.join(audio_temp, f"output_{cut_files.index(path)}.{export_format}")
if os.path.exists(segment_output_path): os.remove(segment_output_path)
VoiceConverter().convert_audio(pitch=pitch, filter_radius=filter_radius, index_rate=index_rate, volume_envelope=volume_envelope, protect=protect, hop_length=hop_length, f0_method=f0_method, audio_input_path=path, audio_output_path=segment_output_path, model_path=pth_path, index_path=index_path, f0_autotune=f0_autotune, f0_autotune_strength=f0_autotune_strength, clean_audio=clean_audio, clean_strength=clean_strength, export_format=export_format, embedder_model=embedder_model, resample_sr=resample_sr, checkpointing=checkpointing, f0_file=f0_file, f0_onnx=f0_onnx, formant_shifting=formant_shifting, formant_qfrency=formant_qfrency, formant_timbre=formant_timbre)
os.remove(path)
if os.path.exists(segment_output_path): return segment_output_path
else:
logger.warning(f"{translations['not_found_convert_file']}: {segment_output_path}")
sys.exit(1)
def run_convert_script(pitch=0, filter_radius=3, index_rate=0.5, volume_envelope=1, protect=0.5, hop_length=64, f0_method="rmvpe", input_path=None, output_path="./output.wav", pth_path=None, index_path=None, f0_autotune=False, f0_autotune_strength=1, clean_audio=False, clean_strength=0.7, export_format="wav", embedder_model="contentvec_base.pt", resample_sr=0, split_audio=False, checkpointing=False, f0_file=None, f0_onnx=False, embedders_onnx=False, formant_shifting=False, formant_qfrency=0.8, formant_timbre=0.8):
check_predictors(f0_method, f0_onnx); check_embedders(embedder_model, embedders_onnx)
embedder_model += ".onnx" if embedders_onnx else ".pt"
cvt = VoiceConverter()
start_time = time.time()
pid_path = os.path.join("assets", "convert_pid.txt")
with open(pid_path, "w") as pid_file:
pid_file.write(str(os.getpid()))
if not pth_path or not os.path.exists(pth_path) or os.path.isdir(pth_path) or not pth_path.endswith((".pth", ".onnx")):
logger.warning(translations["provide_file"].format(filename=translations["model"]))
sys.exit(1)
processed_segments = []
audio_temp = os.path.join("audios_temp")
if not os.path.exists(audio_temp) and split_audio: os.makedirs(audio_temp, exist_ok=True)
if os.path.isdir(input_path):
try:
logger.info(translations["convert_batch"])
audio_files = [f for f in os.listdir(input_path) if f.lower().endswith(("wav", "mp3", "flac", "ogg", "opus", "m4a", "mp4", "aac", "alac", "wma", "aiff", "webm", "ac3"))]
if not audio_files:
logger.warning(translations["not_found_audio"])
sys.exit(1)
logger.info(translations["found_audio"].format(audio_files=len(audio_files)))
for audio in audio_files:
audio_path = os.path.join(input_path, audio)
output_audio = os.path.join(input_path, os.path.splitext(audio)[0] + f"_output.{export_format}")
if split_audio:
try:
cut_files, time_stamps = process_audio(logger, audio_path, audio_temp)
params_list = [{"path": path, "audio_temp": audio_temp, "export_format": export_format, "cut_files": cut_files, "pitch": pitch, "filter_radius": filter_radius, "index_rate": index_rate, "volume_envelope": volume_envelope, "protect": protect, "hop_length": hop_length, "f0_method": f0_method, "pth_path": pth_path, "index_path": index_path, "f0_autotune": f0_autotune, "f0_autotune_strength": f0_autotune_strength, "clean_audio": clean_audio, "clean_strength": clean_strength, "embedder_model": embedder_model, "resample_sr": resample_sr, "checkpointing": checkpointing, "f0_file": f0_file, "f0_onnx": f0_onnx, "formant_shifting": formant_shifting, "formant_qfrency": formant_qfrency, "formant_timbre": formant_timbre} for path in cut_files]
with tqdm(total=len(params_list), desc=translations["convert_audio"], ncols=100, unit="a") as pbar:
for params in params_list:
processed_segments.append(run_batch_convert(params))
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
merge_audio(processed_segments, time_stamps, audio_path, output_audio, export_format)
except Exception as e:
logger.error(translations["error_convert_batch"].format(e=e))
finally:
if os.path.exists(audio_temp): shutil.rmtree(audio_temp, ignore_errors=True)
else:
try:
logger.info(f"{translations['convert_audio']} '{audio_path}'...")
if os.path.exists(output_audio): os.remove(output_audio)
with tqdm(total=1, desc=translations["convert_audio"], ncols=100, unit="a") as pbar:
cvt.convert_audio(pitch=pitch, filter_radius=filter_radius, index_rate=index_rate, volume_envelope=volume_envelope, protect=protect, hop_length=hop_length, f0_method=f0_method, audio_input_path=audio_path, audio_output_path=output_audio, model_path=pth_path, index_path=index_path, f0_autotune=f0_autotune, f0_autotune_strength=f0_autotune_strength, clean_audio=clean_audio, clean_strength=clean_strength, export_format=export_format, embedder_model=embedder_model, resample_sr=resample_sr, checkpointing=checkpointing, f0_file=f0_file, f0_onnx=f0_onnx, formant_shifting=formant_shifting, formant_qfrency=formant_qfrency, formant_timbre=formant_timbre)
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
except Exception as e:
logger.error(translations["error_convert"].format(e=e))
logger.info(translations["convert_batch_success"].format(elapsed_time=f"{(time.time() - start_time):.2f}", output_path=output_path.replace('wav', export_format)))
except Exception as e:
logger.error(translations["error_convert_batch_2"].format(e=e))
else:
logger.info(f"{translations['convert_audio']} '{input_path}'...")
if not os.path.exists(input_path):
logger.warning(translations["not_found_audio"])
sys.exit(1)
if os.path.exists(output_path): os.remove(output_path)
if split_audio:
try:
cut_files, time_stamps = process_audio(logger, input_path, audio_temp)
params_list = [{"path": path, "audio_temp": audio_temp, "export_format": export_format, "cut_files": cut_files, "pitch": pitch, "filter_radius": filter_radius, "index_rate": index_rate, "volume_envelope": volume_envelope, "protect": protect, "hop_length": hop_length, "f0_method": f0_method, "pth_path": pth_path, "index_path": index_path, "f0_autotune": f0_autotune, "f0_autotune_strength": f0_autotune_strength, "clean_audio": clean_audio, "clean_strength": clean_strength, "embedder_model": embedder_model, "resample_sr": resample_sr, "checkpointing": checkpointing, "f0_file": f0_file, "f0_onnx": f0_onnx, "formant_shifting": formant_shifting, "formant_qfrency": formant_qfrency, "formant_timbre": formant_timbre} for path in cut_files]
with tqdm(total=len(params_list), desc=translations["convert_audio"], ncols=100, unit="a") as pbar:
for params in params_list:
processed_segments.append(run_batch_convert(params))
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
merge_audio(processed_segments, time_stamps, input_path, output_path.replace("wav", export_format), export_format)
except Exception as e:
logger.error(translations["error_convert_batch"].format(e=e))
finally:
if os.path.exists(audio_temp): shutil.rmtree(audio_temp, ignore_errors=True)
else:
try:
with tqdm(total=1, desc=translations["convert_audio"], ncols=100, unit="a") as pbar:
cvt.convert_audio(pitch=pitch, filter_radius=filter_radius, index_rate=index_rate, volume_envelope=volume_envelope, protect=protect, hop_length=hop_length, f0_method=f0_method, audio_input_path=input_path, audio_output_path=output_path, model_path=pth_path, index_path=index_path, f0_autotune=f0_autotune, f0_autotune_strength=f0_autotune_strength, clean_audio=clean_audio, clean_strength=clean_strength, export_format=export_format, embedder_model=embedder_model, resample_sr=resample_sr, checkpointing=checkpointing, f0_file=f0_file, f0_onnx=f0_onnx, formant_shifting=formant_shifting, formant_qfrency=formant_qfrency, formant_timbre=formant_timbre)
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
except Exception as e:
logger.error(translations["error_convert"].format(e=e))
if os.path.exists(pid_path): os.remove(pid_path)
logger.info(translations["convert_audio_success"].format(input_path=input_path, elapsed_time=f"{(time.time() - start_time):.2f}", output_path=output_path.replace('wav', export_format)))
def change_rms(source_audio, source_rate, target_audio, target_rate, rate):
rms2 = F.interpolate(torch.from_numpy(librosa.feature.rms(y=target_audio, frame_length=target_rate // 2 * 2, hop_length=target_rate // 2)).float().unsqueeze(0), size=target_audio.shape[0], mode="linear").squeeze()
return (target_audio * (torch.pow(F.interpolate(torch.from_numpy(librosa.feature.rms(y=source_audio, frame_length=source_rate // 2 * 2, hop_length=source_rate // 2)).float().unsqueeze(0), size=target_audio.shape[0], mode="linear").squeeze(), 1 - rate) * torch.pow(torch.maximum(rms2, torch.zeros_like(rms2) + 1e-6), rate - 1)).numpy())
def get_providers():
ort_providers = onnxruntime.get_available_providers()
if "CUDAExecutionProvider" in ort_providers: providers = ["CUDAExecutionProvider"]
elif "CoreMLExecutionProvider" in ort_providers: providers = ["CoreMLExecutionProvider"]
else: providers = ["CPUExecutionProvider"]
return providers
class Autotune:
def __init__(self, ref_freqs):
self.ref_freqs = ref_freqs
self.note_dict = self.ref_freqs
def autotune_f0(self, f0, f0_autotune_strength):
autotuned_f0 = np.zeros_like(f0)
for i, freq in enumerate(f0):
autotuned_f0[i] = freq + (min(self.note_dict, key=lambda x: abs(x - freq)) - freq) * f0_autotune_strength
return autotuned_f0
class VC:
def __init__(self, tgt_sr, config):
self.x_pad = config.x_pad
self.x_query = config.x_query
self.x_center = config.x_center
self.x_max = config.x_max
self.sample_rate = 16000
self.window = 160
self.t_pad = self.sample_rate * self.x_pad
self.t_pad_tgt = tgt_sr * self.x_pad
self.t_pad2 = self.t_pad * 2
self.t_query = self.sample_rate * self.x_query
self.t_center = self.sample_rate * self.x_center
self.t_max = self.sample_rate * self.x_max
self.time_step = self.window / self.sample_rate * 1000
self.f0_min = 50
self.f0_max = 1100
self.f0_mel_min = 1127 * np.log(1 + self.f0_min / 700)
self.f0_mel_max = 1127 * np.log(1 + self.f0_max / 700)
self.device = config.device
self.ref_freqs = [49.00, 51.91, 55.00, 58.27, 61.74, 65.41, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.83, 110.00, 116.54, 123.47, 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63, 349.23, 369.99, 392.00, 415.30, 440.00, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.25, 698.46, 739.99, 783.99, 830.61, 880.00, 932.33, 987.77, 1046.50]
self.autotune = Autotune(self.ref_freqs)
self.note_dict = self.autotune.note_dict
def get_f0_pm(self, x, p_len):
import parselmouth
f0 = (parselmouth.Sound(x, self.sample_rate).to_pitch_ac(time_step=self.window / self.sample_rate * 1000 / 1000, voicing_threshold=0.6, pitch_floor=self.f0_min, pitch_ceiling=self.f0_max).selected_array["frequency"])
pad_size = (p_len - len(f0) + 1) // 2
if pad_size > 0 or p_len - len(f0) - pad_size > 0: f0 = np.pad(f0, [[pad_size, p_len - len(f0) - pad_size]], mode="constant")
return f0
def get_f0_mangio_crepe(self, x, p_len, hop_length, model="full", onnx=False):
from main.library.predictors.CREPE import predict
x = x.astype(np.float32)
x /= np.quantile(np.abs(x), 0.999)
audio = torch.unsqueeze(torch.from_numpy(x).to(self.device, copy=True), dim=0)
if audio.ndim == 2 and audio.shape[0] > 1: audio = torch.mean(audio, dim=0, keepdim=True).detach()
p_len = p_len or x.shape[0] // hop_length
source = np.array(predict(audio.detach(), self.sample_rate, hop_length, self.f0_min, self.f0_max, model, batch_size=hop_length * 2, device=self.device, pad=True, providers=get_providers(), onnx=onnx).squeeze(0).cpu().float().numpy())
source[source < 0.001] = np.nan
return np.nan_to_num(np.interp(np.arange(0, len(source) * p_len, len(source)) / p_len, np.arange(0, len(source)), source))
def get_f0_crepe(self, x, model="full", onnx=False):
from main.library.predictors.CREPE import predict, mean, median
f0, pd = predict(torch.tensor(np.copy(x))[None].float(), self.sample_rate, self.window, self.f0_min, self.f0_max, model, batch_size=512, device=self.device, return_periodicity=True, providers=get_providers(), onnx=onnx)
f0, pd = mean(f0, 3), median(pd, 3)
f0[pd < 0.1] = 0
return f0[0].cpu().numpy()
def get_f0_fcpe(self, x, p_len, hop_length, onnx=False, legacy=False):
from main.library.predictors.FCPE import FCPE
model_fcpe = FCPE(os.path.join("assets", "models", "predictors", ("fcpe_legacy" if legacy else"fcpe") + (".onnx" if onnx else ".pt")), hop_length=int(hop_length), f0_min=int(self.f0_min), f0_max=int(self.f0_max), dtype=torch.float32, device=self.device, sample_rate=self.sample_rate, threshold=0.03, providers=get_providers(), onnx=onnx, legacy=legacy)
f0 = model_fcpe.compute_f0(x, p_len=p_len)
del model_fcpe
return f0
def get_f0_rmvpe(self, x, legacy=False, onnx=False):
from main.library.predictors.RMVPE import RMVPE
rmvpe_model = RMVPE(os.path.join("assets", "models", "predictors", "rmvpe" + (".onnx" if onnx else ".pt")), device=self.device, onnx=onnx, providers=get_providers())
f0 = rmvpe_model.infer_from_audio_with_pitch(x, thred=0.03, f0_min=self.f0_min, f0_max=self.f0_max) if legacy else rmvpe_model.infer_from_audio(x, thred=0.03)
del rmvpe_model
return f0
def get_f0_pyworld_wrapper(self, x, filter_radius, model="harvest"):
from main.library.predictors.WORLD_WRAPPER import PYWORLD
pw = PYWORLD()
x = x.astype(np.double)
if model == "harvest": f0, t = pw.harvest(x, fs=self.sample_rate, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=10)
elif model == "dio": f0, t = pw.dio(x, fs=self.sample_rate, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=10)
else: raise ValueError(translations["method_not_valid"])
f0 = pw.stonemask(x, self.sample_rate, t, f0)
if filter_radius > 2 or model == "dio": f0 = signal.medfilt(f0, 3)
return f0
def get_f0_pyworld(self, x, filter_radius, model="harvest"):
from main.library.predictors.pyworld import harvest, dio, stonemask
x = x.astype(np.double)
if model == "harvest": f0, t = harvest.harvest(x, fs=self.sample_rate, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=10)
elif model == "dio": f0, t = dio.dio(x, fs=self.sample_rate, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=10)
else: raise ValueError(translations["method_not_valid"])
f0 = stonemask.stonemask(x, self.sample_rate, t, f0)
if filter_radius > 2 or model == "dio": f0 = signal.medfilt(f0, 3)
return f0
def get_f0_swipe(self, x):
from main.library.predictors.SWIPE import swipe
f0, _ = swipe(x.astype(np.double), self.sample_rate, f0_floor=self.f0_min, f0_ceil=self.f0_max, frame_period=10, device=self.device)
return f0
def get_f0_yin(self, x, hop_length, p_len):
source = np.array(librosa.yin(x.astype(np.float32), sr=self.sample_rate, fmin=self.f0_min, fmax=self.f0_max, hop_length=hop_length))
source[source < 0.001] = np.nan
return np.nan_to_num(np.interp(np.arange(0, len(source) * p_len, len(source)) / p_len, np.arange(0, len(source)), source))
def get_f0_pyin(self, x, hop_length, p_len):
f0, _, _ = librosa.pyin(x.astype(np.float32), fmin=self.f0_min, fmax=self.f0_max, sr=self.sample_rate, hop_length=hop_length)
source = np.array(f0)
source[source < 0.001] = np.nan
return np.nan_to_num(np.interp(np.arange(0, len(source) * p_len, len(source)) / p_len, np.arange(0, len(source)), source))
def get_f0_hybrid(self, methods_str, x, p_len, hop_length, filter_radius, onnx_mode):
methods_str = re.search("hybrid\[(.+)\]", methods_str)
if methods_str: methods = [method.strip() for method in methods_str.group(1).split("+")]
f0_computation_stack, resampled_stack = [], []
logger.debug(translations["hybrid_methods"].format(methods=methods))
x = x.astype(np.float32)
x /= np.quantile(np.abs(x), 0.999)
for method in methods:
f0 = None
f0_methods = {"pm": lambda: self.get_f0_pm(x, p_len), "diow": lambda: self.get_f0_pyworld_wrapper(x, filter_radius, "dio"), "dio": lambda: self.get_f0_pyworld(x, filter_radius, "dio"), "mangio-crepe-tiny": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "tiny", onnx=onnx_mode), "mangio-crepe-small": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "small", onnx=onnx_mode), "mangio-crepe-medium": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "medium", onnx=onnx_mode), "mangio-crepe-large": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "large", onnx=onnx_mode), "mangio-crepe-full": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "full", onnx=onnx_mode), "crepe-tiny": lambda: self.get_f0_crepe(x, "tiny", onnx=onnx_mode), "crepe-small": lambda: self.get_f0_crepe(x, "small", onnx=onnx_mode), "crepe-medium": lambda: self.get_f0_crepe(x, "medium", onnx=onnx_mode), "crepe-large": lambda: self.get_f0_crepe(x, "large", onnx=onnx_mode), "crepe-full": lambda: self.get_f0_crepe(x, "full", onnx=onnx_mode), "fcpe": lambda: self.get_f0_fcpe(x, p_len, int(hop_length), onnx=onnx_mode), "fcpe-legacy": lambda: self.get_f0_fcpe(x, p_len, int(hop_length), legacy=True, onnx=onnx_mode), "rmvpe": lambda: self.get_f0_rmvpe(x, onnx=onnx_mode), "rmvpe-legacy": lambda: self.get_f0_rmvpe(x, legacy=True, onnx=onnx_mode), "harvestw": lambda: self.get_f0_pyworld_wrapper(x, filter_radius, "harvest"), "harvest": lambda: self.get_f0_pyworld(x, filter_radius, "harvest"), "yin": lambda: self.get_f0_yin(x, int(hop_length), p_len), "pyin": lambda: self.get_f0_pyin(x, int(hop_length), p_len), "swipe": lambda: self.get_f0_swipe(x)}
f0 = f0_methods.get(method, lambda: ValueError(translations["method_not_valid"]))()
f0_computation_stack.append(f0)
for f0 in f0_computation_stack:
resampled_stack.append(np.interp(np.linspace(0, len(f0), p_len), np.arange(len(f0)), f0))
return resampled_stack[0] if len(resampled_stack) == 1 else np.nanmedian(np.vstack(resampled_stack), axis=0)
def get_f0(self, x, p_len, pitch, f0_method, filter_radius, hop_length, f0_autotune, f0_autotune_strength, inp_f0=None, onnx_mode=False):
f0_methods = {"pm": lambda: self.get_f0_pm(x, p_len), "diow": lambda: self.get_f0_pyworld_wrapper(x, filter_radius, "dio"), "dio": lambda: self.get_f0_pyworld(x, filter_radius, "dio"), "mangio-crepe-tiny": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "tiny", onnx=onnx_mode), "mangio-crepe-small": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "small", onnx=onnx_mode), "mangio-crepe-medium": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "medium", onnx=onnx_mode), "mangio-crepe-large": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "large", onnx=onnx_mode), "mangio-crepe-full": lambda: self.get_f0_mangio_crepe(x, p_len, int(hop_length), "full", onnx=onnx_mode), "crepe-tiny": lambda: self.get_f0_crepe(x, "tiny", onnx=onnx_mode), "crepe-small": lambda: self.get_f0_crepe(x, "small", onnx=onnx_mode), "crepe-medium": lambda: self.get_f0_crepe(x, "medium", onnx=onnx_mode), "crepe-large": lambda: self.get_f0_crepe(x, "large", onnx=onnx_mode), "crepe-full": lambda: self.get_f0_crepe(x, "full", onnx=onnx_mode), "fcpe": lambda: self.get_f0_fcpe(x, p_len, int(hop_length), onnx=onnx_mode), "fcpe-legacy": lambda: self.get_f0_fcpe(x, p_len, int(hop_length), legacy=True, onnx=onnx_mode), "rmvpe": lambda: self.get_f0_rmvpe(x, onnx=onnx_mode), "rmvpe-legacy": lambda: self.get_f0_rmvpe(x, legacy=True, onnx=onnx_mode), "harvestw": lambda: self.get_f0_pyworld_wrapper(x, filter_radius, "harvest"), "harvest": lambda: self.get_f0_pyworld(x, filter_radius, "harvest"), "yin": lambda: self.get_f0_yin(x, int(hop_length), p_len), "pyin": lambda: self.get_f0_pyin(x, int(hop_length), p_len), "swipe": lambda: self.get_f0_swipe(x)}
f0 = self.get_f0_hybrid(f0_method, x, p_len, hop_length, filter_radius, onnx_mode) if "hybrid" in f0_method else f0_methods.get(f0_method, lambda: ValueError(translations["method_not_valid"]))()
if f0_autotune: f0 = Autotune.autotune_f0(self, f0, f0_autotune_strength)
if isinstance(f0, tuple): f0 = f0[0]
f0 *= pow(2, pitch / 12)
tf0 = self.sample_rate // self.window
if inp_f0 is not None:
replace_f0 = np.interp(list(range(np.round((inp_f0[:, 0].max() - inp_f0[:, 0].min()) * tf0 + 1).astype(np.int16))), inp_f0[:, 0] * 100, inp_f0[:, 1])
f0[self.x_pad * tf0 : self.x_pad * tf0 + len(replace_f0)] = replace_f0[:f0[self.x_pad * tf0 : self.x_pad * tf0 + len(replace_f0)].shape[0]]
f0_mel = 1127 * np.log(1 + f0 / 700)
f0_mel[f0_mel > 0] = (f0_mel[f0_mel > 0] - self.f0_mel_min) * 254 / (self.f0_mel_max - self.f0_mel_min) + 1
f0_mel[f0_mel <= 1] = 1
f0_mel[f0_mel > 255] = 255
return np.rint(f0_mel).astype(np.int32), f0.copy()
def extract_features(self, model, feats, version):
return torch.as_tensor(model.run([model.get_outputs()[0].name, model.get_outputs()[1].name], {"feats": feats.detach().cpu().numpy()})[0 if version == "v1" else 1], dtype=torch.float32, device=feats.device)
def voice_conversion(self, model, net_g, sid, audio0, pitch, pitchf, index, big_npy, index_rate, version, protect):
pitch_guidance = pitch != None and pitchf != None
feats = torch.from_numpy(audio0).float()
if feats.dim() == 2: feats = feats.mean(-1)
assert feats.dim() == 1, feats.dim()
feats = feats.view(1, -1)
if self.embed_suffix == ".pt":
padding_mask = torch.BoolTensor(feats.shape).to(self.device).fill_(False)
inputs = {"source": feats.to(self.device), "padding_mask": padding_mask, "output_layer": 9 if version == "v1" else 12}
with torch.no_grad():
if self.embed_suffix == ".pt":
logits = model.extract_features(**inputs)
feats = model.final_proj(logits[0]) if version == "v1" else logits[0]
else: feats = self.extract_features(model, feats, version).to(self.device)
if protect < 0.5 and pitch_guidance: feats0 = feats.clone()
if (not isinstance(index, type(None)) and not isinstance(big_npy, type(None)) and index_rate != 0):
npy = feats[0].cpu().numpy()
score, ix = index.search(npy, k=8)
weight = np.square(1 / score)
weight /= weight.sum(axis=1, keepdims=True)
npy = np.sum(big_npy[ix] * np.expand_dims(weight, axis=2), axis=1)
feats = (torch.from_numpy(npy).unsqueeze(0).to(self.device) * index_rate + (1 - index_rate) * feats)
feats = F.interpolate(feats.permute(0, 2, 1), scale_factor=2).permute(0, 2, 1)
if protect < 0.5 and pitch_guidance: feats0 = F.interpolate(feats0.permute(0, 2, 1), scale_factor=2).permute(0, 2, 1)
p_len = audio0.shape[0] // self.window
if feats.shape[1] < p_len:
p_len = feats.shape[1]
if pitch_guidance:
pitch = pitch[:, :p_len]
pitchf = pitchf[:, :p_len]
if protect < 0.5 and pitch_guidance:
pitchff = pitchf.clone()
pitchff[pitchf > 0] = 1
pitchff[pitchf < 1] = protect
pitchff = pitchff.unsqueeze(-1)
feats = feats * pitchff + feats0 * (1 - pitchff)
feats = feats.to(feats0.dtype)
p_len = torch.tensor([p_len], device=self.device).long()
audio1 = ((net_g.infer(feats.float(), p_len, pitch if pitch_guidance else None, pitchf.float() if pitch_guidance else None, sid)[0][0, 0]).data.cpu().float().numpy()) if self.suffix == ".pth" else (net_g.run([net_g.get_outputs()[0].name], ({net_g.get_inputs()[0].name: feats.cpu().numpy().astype(np.float32), net_g.get_inputs()[1].name: p_len.cpu().numpy(), net_g.get_inputs()[2].name: np.array([sid.cpu().item()], dtype=np.int64), net_g.get_inputs()[3].name: np.random.randn(1, 192, p_len).astype(np.float32), net_g.get_inputs()[4].name: pitch.cpu().numpy().astype(np.int64), net_g.get_inputs()[5].name: pitchf.cpu().numpy().astype(np.float32)} if pitch_guidance else {net_g.get_inputs()[0].name: feats.cpu().numpy().astype(np.float32), net_g.get_inputs()[1].name: p_len.cpu().numpy(), net_g.get_inputs()[2].name: np.array([sid.cpu().item()], dtype=np.int64), net_g.get_inputs()[3].name: np.random.randn(1, 192, p_len).astype(np.float32)}))[0][0, 0])
if self.embed_suffix == ".pt": del padding_mask
del feats, p_len, net_g
if torch.cuda.is_available(): torch.cuda.empty_cache()
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
return audio1
def pipeline(self, model, net_g, sid, audio, pitch, f0_method, file_index, index_rate, pitch_guidance, filter_radius, tgt_sr, resample_sr, volume_envelope, version, protect, hop_length, f0_autotune, f0_autotune_strength, suffix, embed_suffix, f0_file=None, f0_onnx=False):
self.suffix = suffix
self.embed_suffix = embed_suffix
if file_index != "" and os.path.exists(file_index) and index_rate != 0:
try:
index = faiss.read_index(file_index)
big_npy = index.reconstruct_n(0, index.ntotal)
except Exception as e:
logger.error(translations["read_faiss_index_error"].format(e=e))
index = big_npy = None
else: index = big_npy = None
opt_ts, audio_opt = [], []
audio = signal.filtfilt(bh, ah, audio)
audio_pad = np.pad(audio, (self.window // 2, self.window // 2), mode="reflect")
if audio_pad.shape[0] > self.t_max:
audio_sum = np.zeros_like(audio)
for i in range(self.window):
audio_sum += audio_pad[i : i - self.window]
for t in range(self.t_center, audio.shape[0], self.t_center):
opt_ts.append(t - self.t_query + np.where(np.abs(audio_sum[t - self.t_query : t + self.t_query]) == np.abs(audio_sum[t - self.t_query : t + self.t_query]).min())[0][0])
s = 0
t, inp_f0 = None, None
audio_pad = np.pad(audio, (self.t_pad, self.t_pad), mode="reflect")
sid = torch.tensor(sid, device=self.device).unsqueeze(0).long()
p_len = audio_pad.shape[0] // self.window
if hasattr(f0_file, "name"):
try:
with open(f0_file.name, "r") as f:
raw_lines = f.read()
if len(raw_lines) > 0:
inp_f0 = []
for line in raw_lines.strip("\n").split("\n"):
inp_f0.append([float(i) for i in line.split(",")])
inp_f0 = np.array(inp_f0, dtype=np.float32)
except:
logger.error(translations["error_readfile"])
inp_f0 = None
if pitch_guidance:
pitch, pitchf = self.get_f0(audio_pad, p_len, pitch, f0_method, filter_radius, hop_length, f0_autotune, f0_autotune_strength, inp_f0, onnx_mode=f0_onnx)
pitch, pitchf = pitch[:p_len], pitchf[:p_len]
if self.device == "mps": pitchf = pitchf.astype(np.float32)
pitch, pitchf = torch.tensor(pitch, device=self.device).unsqueeze(0).long(), torch.tensor(pitchf, device=self.device).unsqueeze(0).float()
for t in opt_ts:
t = t // self.window * self.window
audio_opt.append(self.voice_conversion(model, net_g, sid, audio_pad[s : t + self.t_pad2 + self.window], pitch[:, s // self.window : (t + self.t_pad2) // self.window] if pitch_guidance else None, pitchf[:, s // self.window : (t + self.t_pad2) // self.window] if pitch_guidance else None, index, big_npy, index_rate, version, protect)[self.t_pad_tgt : -self.t_pad_tgt])
s = t
audio_opt.append(self.voice_conversion(model, net_g, sid, audio_pad[t:], (pitch[:, t // self.window :] if t is not None else pitch) if pitch_guidance else None, (pitchf[:, t // self.window :] if t is not None else pitchf) if pitch_guidance else None, index, big_npy, index_rate, version, protect)[self.t_pad_tgt : -self.t_pad_tgt])
audio_opt = np.concatenate(audio_opt)
if volume_envelope != 1: audio_opt = change_rms(audio, self.sample_rate, audio_opt, tgt_sr, volume_envelope)
if resample_sr >= self.sample_rate and tgt_sr != resample_sr: audio_opt = librosa.resample(audio_opt, orig_sr=tgt_sr, target_sr=resample_sr, res_type="soxr_vhq")
audio_max = np.abs(audio_opt).max() / 0.99
if audio_max > 1: audio_opt /= audio_max
if pitch_guidance: del pitch, pitchf
del sid
if torch.cuda.is_available(): torch.cuda.empty_cache()
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
return audio_opt
class VoiceConverter:
def __init__(self):
self.config = config
self.hubert_model = None
self.tgt_sr = None
self.net_g = None
self.vc = None
self.cpt = None
self.version = None
self.n_spk = None
self.use_f0 = None
self.loaded_model = None
self.vocoder = "Default"
self.checkpointing = False
def load_embedders(self, embedder_model):
embedder_model_path = os.path.join("assets", "models", "embedders", embedder_model)
if not os.path.exists(embedder_model_path) and not embedder_model.endswith((".pt", ".onnx")): raise FileNotFoundError(f"{translations['not_found'].format(name=translations['model'])}: {embedder_model}")
try:
if embedder_model.endswith(".pt"):
models, _, _ = checkpoint_utils.load_model_ensemble_and_task([embedder_model_path], suffix="")
self.embed_suffix = ".pt"
self.hubert_model = models[0].to(self.config.device).float().eval()
else:
sess_options = onnxruntime.SessionOptions()
sess_options.log_severity_level = 3
self.embed_suffix = ".onnx"
self.hubert_model = onnxruntime.InferenceSession(embedder_model_path, sess_options=sess_options, providers=get_providers())
except Exception as e:
logger.error(translations["read_model_error"].format(e=e))
def convert_audio(self, audio_input_path, audio_output_path, model_path, index_path, embedder_model, pitch, f0_method, index_rate, volume_envelope, protect, hop_length, f0_autotune, f0_autotune_strength, filter_radius, clean_audio, clean_strength, export_format, resample_sr = 0, sid = 0, checkpointing = False, f0_file = None, f0_onnx = False, formant_shifting = False, formant_qfrency=0.8, formant_timbre=0.8):
try:
self.get_vc(model_path, sid)
audio = load_audio(logger, audio_input_path, 16000, formant_shifting=formant_shifting, formant_qfrency=formant_qfrency, formant_timbre=formant_timbre)
self.checkpointing = checkpointing
audio_max = np.abs(audio).max() / 0.95
if audio_max > 1: audio /= audio_max
if not self.hubert_model: self.load_embedders(embedder_model)
if self.tgt_sr != resample_sr >= 16000: self.tgt_sr = resample_sr
target_sr = min([8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 96000], key=lambda x: abs(x - self.tgt_sr))
audio_output = self.vc.pipeline(model=self.hubert_model, net_g=self.net_g, sid=sid, audio=audio, pitch=pitch, f0_method=f0_method, file_index=(index_path.strip().strip('"').strip("\n").strip('"').strip().replace("trained", "added")), index_rate=index_rate, pitch_guidance=self.use_f0, filter_radius=filter_radius, tgt_sr=self.tgt_sr, resample_sr=target_sr, volume_envelope=volume_envelope, version=self.version, protect=protect, hop_length=hop_length, f0_autotune=f0_autotune, f0_autotune_strength=f0_autotune_strength, suffix=self.suffix, embed_suffix=self.embed_suffix, f0_file=f0_file, f0_onnx=f0_onnx)
if clean_audio:
from main.tools.noisereduce import reduce_noise
audio_output = reduce_noise(y=audio_output, sr=target_sr, prop_decrease=clean_strength, device=config.device)
sf.write(audio_output_path, audio_output, target_sr, format=export_format)
except Exception as e:
logger.error(translations["error_convert"].format(e=e))
import traceback
logger.debug(traceback.format_exc())
def get_vc(self, weight_root, sid):
if sid == "" or sid == []:
self.cleanup()
if torch.cuda.is_available(): torch.cuda.empty_cache()
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
if not self.loaded_model or self.loaded_model != weight_root:
self.loaded_model = weight_root
self.load_model()
if self.cpt is not None: self.setup()
def cleanup(self):
if self.hubert_model is not None:
del self.net_g, self.n_spk, self.vc, self.hubert_model, self.tgt_sr
self.hubert_model = self.net_g = self.n_spk = self.vc = self.tgt_sr = None
if torch.cuda.is_available(): torch.cuda.empty_cache()
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
del self.net_g, self.cpt
if torch.cuda.is_available(): torch.cuda.empty_cache()
elif torch.backends.mps.is_available(): torch.mps.empty_cache()
self.cpt = None
def load_model(self):
if os.path.isfile(self.loaded_model):
if self.loaded_model.endswith(".pth"): self.cpt = torch.load(self.loaded_model, map_location="cpu")
else:
sess_options = onnxruntime.SessionOptions()
sess_options.log_severity_level = 3
self.cpt = onnxruntime.InferenceSession(self.loaded_model, sess_options=sess_options, providers=get_providers())
else: self.cpt = None
def setup(self):
if self.cpt is not None:
if self.loaded_model.endswith(".pth"):
self.tgt_sr = self.cpt["config"][-1]
self.cpt["config"][-3] = self.cpt["weight"]["emb_g.weight"].shape[0]
self.use_f0 = self.cpt.get("f0", 1)
self.version = self.cpt.get("version", "v1")
self.vocoder = self.cpt.get("vocoder", "Default")
self.net_g = Synthesizer(*self.cpt["config"], use_f0=self.use_f0, text_enc_hidden_dim=768 if self.version == "v2" else 256, vocoder=self.vocoder, checkpointing=self.checkpointing)
del self.net_g.enc_q
self.net_g.load_state_dict(self.cpt["weight"], strict=False)
self.net_g.eval().to(self.config.device).float()
self.n_spk = self.cpt["config"][-3]
self.suffix = ".pth"
else:
import json
import onnx
model = onnx.load(self.loaded_model)
metadata_dict = None
for prop in model.metadata_props:
if prop.key == "model_info":
metadata_dict = json.loads(prop.value)
break
self.net_g = self.cpt
self.tgt_sr = metadata_dict.get("sr", 32000)
self.use_f0 = metadata_dict.get("f0", 1)
self.suffix = ".onnx"
self.vc = VC(self.tgt_sr, self.config)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240import os
import sys
import time
import yt_dlp
import shutil
import librosa
import logging
import argparse
import warnings
import logging.handlers
from soundfile import read, write
from distutils.util import strtobool
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.algorithm.separator import Separator
from main.library.utils import process_audio, merge_audio
config = Config()
translations = config.translations
dataset_temp = os.path.join("dataset_temp")
logger = logging.getLogger(__name__)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join("assets", "logs", "create_dataset.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--input_audio", type=str, required=True)
parser.add_argument("--output_dataset", type=str, default="./dataset")
parser.add_argument("--sample_rate", type=int, default=44100)
parser.add_argument("--clean_dataset", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clean_strength", type=float, default=0.7)
parser.add_argument("--separator_reverb", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--kim_vocal_version", type=int, default=2)
parser.add_argument("--overlap", type=float, default=0.25)
parser.add_argument("--segments_size", type=int, default=256)
parser.add_argument("--mdx_hop_length", type=int, default=1024)
parser.add_argument("--mdx_batch_size", type=int, default=1)
parser.add_argument("--denoise_mdx", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--skip", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--skip_start_audios", type=str, default="0")
parser.add_argument("--skip_end_audios", type=str, default="0")
return parser.parse_args()
def main():
pid_path = os.path.join("assets", "create_dataset_pid.txt")
with open(pid_path, "w") as pid_file:
pid_file.write(str(os.getpid()))
args = parse_arguments()
input_audio, output_dataset, sample_rate, clean_dataset, clean_strength, separator_reverb, kim_vocal_version, overlap, segments_size, hop_length, batch_size, denoise_mdx, skip, skip_start_audios, skip_end_audios = args.input_audio, args.output_dataset, args.sample_rate, args.clean_dataset, args.clean_strength, args.separator_reverb, args.kim_vocal_version, args.overlap, args.segments_size, args.mdx_hop_length, args.mdx_batch_size, args.denoise_mdx, args.skip, args.skip_start_audios, args.skip_end_audios
log_data = {translations['audio_path']: input_audio, translations['output_path']: output_dataset, translations['sr']: sample_rate, translations['clear_dataset']: clean_dataset, translations['dereveb_audio']: separator_reverb, translations['segments_size']: segments_size, translations['overlap']: overlap, "Hop length": hop_length, translations['batch_size']: batch_size, translations['denoise_mdx']: denoise_mdx, translations['skip']: skip}
if clean_dataset: log_data[translations['clean_strength']] = clean_strength
if skip:
log_data[translations['skip_start']] = skip_start_audios
log_data[translations['skip_end']] = skip_end_audios
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
if kim_vocal_version not in [1, 2]: raise ValueError(translations["version_not_valid"])
start_time = time.time()
try:
paths = []
if not os.path.exists(dataset_temp): os.makedirs(dataset_temp, exist_ok=True)
urls = input_audio.replace(", ", ",").split(",")
for url in urls:
path = downloader(url, urls.index(url))
paths.append(path)
if skip:
skip_start_audios = skip_start_audios.replace(", ", ",").split(",")
skip_end_audios = skip_end_audios.replace(", ", ",").split(",")
if len(skip_start_audios) < len(paths) or len(skip_end_audios) < len(paths):
logger.warning(translations["skip<audio"])
sys.exit(1)
elif len(skip_start_audios) > len(paths) or len(skip_end_audios) > len(paths):
logger.warning(translations["skip>audio"])
sys.exit(1)
else:
for audio, skip_start_audio, skip_end_audio in zip(paths, skip_start_audios, skip_end_audios):
skip_start(audio, skip_start_audio)
skip_end(audio, skip_end_audio)
separator_paths = []
for audio in paths:
vocals = separator_music_main(audio, dataset_temp, segments_size, overlap, denoise_mdx, kim_vocal_version, hop_length, batch_size, sample_rate)
if separator_reverb: vocals = separator_reverb_audio(vocals, dataset_temp, segments_size, overlap, denoise_mdx, hop_length, batch_size, sample_rate)
separator_paths.append(vocals)
paths = separator_paths
processed_paths = []
for audio in paths:
cut_files, time_stamps = process_audio(logger, audio, os.path.dirname(audio))
processed_paths.append(merge_audio(cut_files, time_stamps, audio, os.path.splitext(audio)[0] + "_processed" + ".wav", "wav"))
paths = processed_paths
for audio_path in paths:
data, sample_rate = read(audio_path)
data = librosa.to_mono(data.T)
if clean_dataset:
from main.tools.noisereduce import reduce_noise
data = reduce_noise(y=data, prop_decrease=clean_strength, device=config.device)
write(audio_path, data, sample_rate)
except Exception as e:
logger.error(f"{translations['create_dataset_error']}: {e}")
import traceback
logger.error(traceback.format_exc())
finally:
for audio in paths:
shutil.move(audio, output_dataset)
if os.path.exists(dataset_temp): shutil.rmtree(dataset_temp, ignore_errors=True)
elapsed_time = time.time() - start_time
if os.path.exists(pid_path): os.remove(pid_path)
logger.info(translations["create_dataset_success"].format(elapsed_time=f"{elapsed_time:.2f}"))
def downloader(url, name):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
ydl_opts = {"format": "bestaudio/best", "outtmpl": os.path.join(dataset_temp, f"{name}"), "postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "wav", "preferredquality": "192"}], "no_warnings": True, "noplaylist": True, "noplaylist": True, "verbose": False}
logger.info(f"{translations['starting_download']}: {url}...")
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.extract_info(url)
logger.info(f"{translations['download_success']}: {url}")
return os.path.join(dataset_temp, f"{name}" + ".wav")
def skip_start(input_file, seconds):
data, sr = read(input_file)
total_duration = len(data) / sr
if seconds <= 0: logger.warning(translations["=<0"])
elif seconds >= total_duration: logger.warning(translations["skip_warning"].format(seconds=seconds, total_duration=f"{total_duration:.2f}"))
else:
logger.info(f"{translations['skip_start']}: {input_file}...")
write(input_file, data[int(seconds * sr):], sr)
logger.info(translations["skip_start_audio"].format(input_file=input_file))
def skip_end(input_file, seconds):
data, sr = read(input_file)
total_duration = len(data) / sr
if seconds <= 0: logger.warning(translations["=<0"])
elif seconds > total_duration: logger.warning(translations["skip_warning"].format(seconds=seconds, total_duration=f"{total_duration:.2f}"))
else:
logger.info(f"{translations['skip_end']}: {input_file}...")
write(input_file, data[:-int(seconds * sr)], sr)
logger.info(translations["skip_end_audio"].format(input_file=input_file))
def separator_music_main(input, output, segments_size, overlap, denoise, version, hop_length, batch_size, sample_rate):
if not os.path.exists(input):
logger.warning(translations["input_not_valid"])
return None
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
return None
model = f"Kim_Vocal_{version}.onnx"
output_separator = separator_main(audio_file=input, model_filename=model, output_format="wav", output_dir=output, mdx_segment_size=segments_size, mdx_overlap=overlap, mdx_batch_size=batch_size, mdx_hop_length=hop_length, mdx_enable_denoise=denoise, sample_rate=sample_rate)
for f in output_separator:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Instrumental)_' in f: os.rename(path, os.path.splitext(path)[0].replace("(", "").replace(")", "") + ".wav")
elif '_(Vocals)_' in f:
rename_file = os.path.splitext(path)[0].replace("(", "").replace(")", "") + ".wav"
os.rename(path, rename_file)
return rename_file
def separator_reverb_audio(input, output, segments_size, overlap, denoise, hop_length, batch_size, sample_rate):
if not os.path.exists(input):
logger.warning(translations["input_not_valid"])
return None
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
return None
logger.info(f"{translations['dereverb']}: {input}...")
output_dereverb = separator_main(audio_file=input, model_filename="Reverb_HQ_By_FoxJoy.onnx", output_format="wav", output_dir=output, mdx_segment_size=segments_size, mdx_overlap=overlap, mdx_batch_size=hop_length, mdx_hop_length=batch_size, mdx_enable_denoise=denoise, sample_rate=sample_rate)
for f in output_dereverb:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Reverb)_' in f: os.rename(path, os.path.splitext(path)[0].replace("(", "").replace(")", "") + ".wav")
elif '_(No Reverb)_' in f:
rename_file = os.path.splitext(path)[0].replace("(", "").replace(")", "") + ".wav"
os.rename(path, rename_file)
logger.info(f"{translations['dereverb_success']}: {rename_file}")
return rename_file
def separator_main(audio_file=None, model_filename="Kim_Vocal_1.onnx", output_format="wav", output_dir=".", mdx_segment_size=256, mdx_overlap=0.25, mdx_batch_size=1, mdx_hop_length=1024, mdx_enable_denoise=True, sample_rate=44100):
try:
separator = Separator(logger=logger, log_formatter=file_formatter, log_level=logging.INFO, output_dir=output_dir, output_format=output_format, output_bitrate=None, normalization_threshold=0.9, output_single_stem=None, invert_using_spec=False, sample_rate=sample_rate, mdx_params={"hop_length": mdx_hop_length, "segment_size": mdx_segment_size, "overlap": mdx_overlap, "batch_size": mdx_batch_size, "enable_denoise": mdx_enable_denoise})
separator.load_model(model_filename=model_filename)
return separator.separate(audio_file)
except:
logger.debug(translations["default_setting"])
separator = Separator(logger=logger, log_formatter=file_formatter, log_level=logging.INFO, output_dir=output_dir, output_format=output_format, output_bitrate=None, normalization_threshold=0.9, output_single_stem=None, invert_using_spec=False, sample_rate=44100, mdx_params={"hop_length": 1024, "segment_size": 256, "overlap": 0.25, "batch_size": 1, "enable_denoise": mdx_enable_denoise})
separator.load_model(model_filename=model_filename)
return separator.separate(audio_file)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100import os
import sys
import faiss
import logging
import argparse
import logging.handlers
import numpy as np
from multiprocessing import cpu_count
from sklearn.cluster import MiniBatchKMeans
sys.path.append(os.getcwd())
from main.configs.config import Config
translations = Config().translations
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--model_name", type=str, required=True)
parser.add_argument("--rvc_version", type=str, default="v2")
parser.add_argument("--index_algorithm", type=str, default="Auto")
return parser.parse_args()
def main():
args = parse_arguments()
exp_dir = os.path.join("assets", "logs", args.model_name)
version = args.rvc_version
index_algorithm = args.index_algorithm
logger = logging.getLogger(__name__)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join(exp_dir, "create_index.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
log_data = {translations['modelname']: args.model_name, translations['model_path']: exp_dir, translations['training_version']: version, translations['index_algorithm_info']: index_algorithm}
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
try:
npys = []
feature_dir = os.path.join(exp_dir, f"{version}_extracted")
model_name = os.path.basename(exp_dir)
for name in sorted(os.listdir(feature_dir)):
npys.append(np.load(os.path.join(feature_dir, name)))
big_npy = np.concatenate(npys, axis=0)
big_npy_idx = np.arange(big_npy.shape[0])
np.random.shuffle(big_npy_idx)
big_npy = big_npy[big_npy_idx]
if big_npy.shape[0] > 2e5 and (index_algorithm == "Auto" or index_algorithm == "KMeans"): big_npy = (MiniBatchKMeans(n_clusters=10000, verbose=True, batch_size=256 * cpu_count(), compute_labels=False, init="random").fit(big_npy).cluster_centers_)
np.save(os.path.join(exp_dir, "total_fea.npy"), big_npy)
n_ivf = min(int(16 * np.sqrt(big_npy.shape[0])), big_npy.shape[0] // 39)
index_trained = faiss.index_factory(256 if version == "v1" else 768, f"IVF{n_ivf},Flat")
index_ivf_trained = faiss.extract_index_ivf(index_trained)
index_ivf_trained.nprobe = 1
index_trained.train(big_npy)
faiss.write_index(index_trained, os.path.join(exp_dir, f"trained_IVF{n_ivf}_Flat_nprobe_{index_ivf_trained.nprobe}_{model_name}_{version}.index"))
index_added = faiss.index_factory(256 if version == "v1" else 768, f"IVF{n_ivf},Flat")
index_ivf_added = faiss.extract_index_ivf(index_added)
index_ivf_added.nprobe = 1
index_added.train(big_npy)
batch_size_add = 8192
for i in range(0, big_npy.shape[0], batch_size_add):
index_added.add(big_npy[i : i + batch_size_add])
index_filepath_added = os.path.join(exp_dir, f"added_IVF{n_ivf}_Flat_nprobe_{index_ivf_added.nprobe}_{model_name}_{version}.index")
faiss.write_index(index_added, index_filepath_added)
logger.info(f"{translations['save_index']} '{index_filepath_added}'")
except Exception as e:
logger.error(f"{translations['create_index_error']}: {e}")
import traceback
logger.debug(traceback.format_exc())
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400import os
import re
import sys
import time
import tqdm
import torch
import shutil
import logging
import argparse
import warnings
import onnxruntime
import logging.handlers
import numpy as np
import soundfile as sf
import torch.nn.functional as F
from random import shuffle
from distutils.util import strtobool
from fairseq import checkpoint_utils
from concurrent.futures import ThreadPoolExecutor, as_completed
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.utils import check_predictors, check_embedders, load_audio
logger = logging.getLogger(__name__)
translations = Config().translations
logger.propagate = False
warnings.filterwarnings("ignore")
for l in ["torch", "faiss", "httpx", "fairseq", "httpcore", "faiss.loader", "numba.core", "urllib3"]:
logging.getLogger(l).setLevel(logging.ERROR)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--model_name", type=str, required=True)
parser.add_argument("--rvc_version", type=str, default="v2")
parser.add_argument("--f0_method", type=str, default="rmvpe")
parser.add_argument("--pitch_guidance", type=lambda x: bool(strtobool(x)), default=True)
parser.add_argument("--hop_length", type=int, default=128)
parser.add_argument("--cpu_cores", type=int, default=2)
parser.add_argument("--gpu", type=str, default="-")
parser.add_argument("--sample_rate", type=int, required=True)
parser.add_argument("--embedder_model", type=str, default="contentvec_base.pt")
parser.add_argument("--f0_onnx", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--embedders_onnx", type=lambda x: bool(strtobool(x)), default=False)
return parser.parse_args()
def generate_config(rvc_version, sample_rate, model_path):
config_save_path = os.path.join(model_path, "config.json")
if not os.path.exists(config_save_path): shutil.copy(os.path.join("main", "configs", rvc_version, f"{sample_rate}.json"), config_save_path)
def generate_filelist(pitch_guidance, model_path, rvc_version, sample_rate):
gt_wavs_dir, feature_dir = os.path.join(model_path, "sliced_audios"), os.path.join(model_path, f"{rvc_version}_extracted")
f0_dir, f0nsf_dir = None, None
if pitch_guidance: f0_dir, f0nsf_dir = os.path.join(model_path, "f0"), os.path.join(model_path, "f0_voiced")
gt_wavs_files, feature_files = set(name.split(".")[0] for name in os.listdir(gt_wavs_dir)), set(name.split(".")[0] for name in os.listdir(feature_dir))
names = gt_wavs_files & feature_files & set(name.split(".")[0] for name in os.listdir(f0_dir)) & set(name.split(".")[0] for name in os.listdir(f0nsf_dir)) if pitch_guidance else gt_wavs_files & feature_files
options = []
mute_base_path = os.path.join("assets", "logs", "mute")
for name in names:
options.append(f"{gt_wavs_dir}/{name}.wav|{feature_dir}/{name}.npy|{f0_dir}/{name}.wav.npy|{f0nsf_dir}/{name}.wav.npy|0" if pitch_guidance else f"{gt_wavs_dir}/{name}.wav|{feature_dir}/{name}.npy|0")
mute_audio_path, mute_feature_path = os.path.join(mute_base_path, "sliced_audios", f"mute{sample_rate}.wav"), os.path.join(mute_base_path, f"{rvc_version}_extracted", "mute.npy")
for _ in range(2):
options.append(f"{mute_audio_path}|{mute_feature_path}|{os.path.join(mute_base_path, 'f0', 'mute.wav.npy')}|{os.path.join(mute_base_path, 'f0_voiced', 'mute.wav.npy')}|0" if pitch_guidance else f"{mute_audio_path}|{mute_feature_path}|0")
shuffle(options)
with open(os.path.join(model_path, "filelist.txt"), "w") as f:
f.write("\n".join(options))
def setup_paths(exp_dir, version = None):
wav_path = os.path.join(exp_dir, "sliced_audios_16k")
if version:
out_path = os.path.join(exp_dir, f"{version}_extracted")
os.makedirs(out_path, exist_ok=True)
return wav_path, out_path
else:
output_root1, output_root2 = os.path.join(exp_dir, "f0"), os.path.join(exp_dir, "f0_voiced")
os.makedirs(output_root1, exist_ok=True); os.makedirs(output_root2, exist_ok=True)
return wav_path, output_root1, output_root2
def read_wave(wav_path, normalize = False):
wav, sr = sf.read(wav_path)
assert sr == 16000, translations["sr_not_16000"]
feats = torch.from_numpy(wav).float()
if feats.dim() == 2: feats = feats.mean(-1)
feats = feats.view(1, -1)
if normalize: feats = F.layer_norm(feats, feats.shape)
return feats
def get_device(gpu_index):
try:
index = int(gpu_index)
if index < torch.cuda.device_count(): return f"cuda:{index}"
else: logger.warning(translations["gpu_not_valid"])
except ValueError:
logger.warning(translations["gpu_not_valid"])
return "cpu"
def get_providers():
ort_providers = onnxruntime.get_available_providers()
if "CUDAExecutionProvider" in ort_providers: providers = ["CUDAExecutionProvider"]
elif "CoreMLExecutionProvider" in ort_providers: providers = ["CoreMLExecutionProvider"]
else: providers = ["CPUExecutionProvider"]
return providers
class FeatureInput:
def __init__(self, sample_rate=16000, hop_size=160, device="cpu"):
self.fs = sample_rate
self.hop = hop_size
self.f0_bin = 256
self.f0_max = 1100.0
self.f0_min = 50.0
self.f0_mel_min = 1127 * np.log(1 + self.f0_min / 700)
self.f0_mel_max = 1127 * np.log(1 + self.f0_max / 700)
self.device = device
def compute_f0_hybrid(self, methods_str, np_arr, hop_length, f0_onnx):
methods_str = re.search("hybrid\[(.+)\]", methods_str)
if methods_str: methods = [method.strip() for method in methods_str.group(1).split("+")]
f0_computation_stack, resampled_stack = [], []
logger.debug(translations["hybrid_methods"].format(methods=methods))
for method in methods:
f0 = None
f0_methods = {"pm": lambda: self.get_pm(np_arr), "diow": lambda: self.get_pyworld_wrapper(np_arr, "dio"), "dio": lambda: self.get_pyworld(np_arr, "dio"), "mangio-crepe-full": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "full", onnx=f0_onnx), "mangio-crepe-large": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "large", onnx=f0_onnx), "mangio-crepe-medium": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "medium", onnx=f0_onnx), "mangio-crepe-small": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "small", onnx=f0_onnx), "mangio-crepe-tiny": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "tiny", onnx=f0_onnx), "crepe-full": lambda: self.get_crepe(np_arr, "full", onnx=f0_onnx), "crepe-large": lambda: self.get_crepe(np_arr, "large", onnx=f0_onnx), "crepe-medium": lambda: self.get_crepe(np_arr, "medium", onnx=f0_onnx), "crepe-small": lambda: self.get_crepe(np_arr, "small", onnx=f0_onnx), "crepe-tiny": lambda: self.get_crepe(np_arr, "tiny", onnx=f0_onnx), "fcpe": lambda: self.get_fcpe(np_arr, int(hop_length), onnx=f0_onnx), "fcpe-legacy": lambda: self.get_fcpe(np_arr, int(hop_length), legacy=True, onnx=f0_onnx), "rmvpe": lambda: self.get_rmvpe(np_arr, onnx=f0_onnx), "rmvpe-legacy": lambda: self.get_rmvpe(np_arr, legacy=True, onnx=f0_onnx), "harvestw": lambda: self.get_pyworld_wrapper(np_arr, "harvest"), "harvest": lambda: self.get_pyworld(np_arr, "harvest"), "swipe": lambda: self.get_swipe(np_arr), "yin": lambda: self.get_yin(np_arr, int(hop_length), mode="yin"), "pyin": lambda: self.get_yin(np_arr, int(hop_length), mode="pyin")}
f0 = f0_methods.get(method, lambda: ValueError(translations["method_not_valid"]))()
f0_computation_stack.append(f0)
for f0 in f0_computation_stack:
resampled_stack.append(np.interp(np.linspace(0, len(f0), (np_arr.size // self.hop)), np.arange(len(f0)), f0))
return resampled_stack[0] if len(resampled_stack) == 1 else np.nanmedian(np.vstack(resampled_stack), axis=0)
def compute_f0(self, np_arr, f0_method, hop_length, f0_onnx=False):
f0_methods = {"pm": lambda: self.get_pm(np_arr), "diow": lambda: self.get_pyworld_wrapper(np_arr, "dio"), "dio": lambda: self.get_pyworld(np_arr, "dio"), "mangio-crepe-full": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "full", onnx=f0_onnx), "mangio-crepe-large": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "large", onnx=f0_onnx), "mangio-crepe-medium": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "medium", onnx=f0_onnx), "mangio-crepe-small": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "small", onnx=f0_onnx), "mangio-crepe-tiny": lambda: self.get_mangio_crepe(np_arr, int(hop_length), "tiny", onnx=f0_onnx), "crepe-full": lambda: self.get_crepe(np_arr, "full", onnx=f0_onnx), "crepe-large": lambda: self.get_crepe(np_arr, "large", onnx=f0_onnx), "crepe-medium": lambda: self.get_crepe(np_arr, "medium", onnx=f0_onnx), "crepe-small": lambda: self.get_crepe(np_arr, "small", onnx=f0_onnx), "crepe-tiny": lambda: self.get_crepe(np_arr, "tiny", onnx=f0_onnx), "fcpe": lambda: self.get_fcpe(np_arr, int(hop_length), onnx=f0_onnx), "fcpe-legacy": lambda: self.get_fcpe(np_arr, int(hop_length), legacy=True, onnx=f0_onnx), "rmvpe": lambda: self.get_rmvpe(np_arr, onnx=f0_onnx), "rmvpe-legacy": lambda: self.get_rmvpe(np_arr, legacy=True, onnx=f0_onnx), "harvestw": lambda: self.get_pyworld_wrapper(np_arr, "harvest"), "harvest": lambda: self.get_pyworld(np_arr, "harvest"), "swipe": lambda: self.get_swipe(np_arr), "yin": lambda: self.get_yin(np_arr, int(hop_length), mode="yin"), "pyin": lambda: self.get_yin(np_arr, int(hop_length), mode="pyin")}
return self.compute_f0_hybrid(f0_method, np_arr, int(hop_length), f0_onnx) if "hybrid" in f0_method else f0_methods.get(f0_method, lambda: ValueError(translations["method_not_valid"]))()
def get_pm(self, x):
import parselmouth
f0 = (parselmouth.Sound(x, self.fs).to_pitch_ac(time_step=(160 / 16000 * 1000) / 1000, voicing_threshold=0.6, pitch_floor=50, pitch_ceiling=1100).selected_array["frequency"])
pad_size = ((x.size // self.hop) - len(f0) + 1) // 2
if pad_size > 0 or (x.size // self.hop) - len(f0) - pad_size > 0: f0 = np.pad(f0, [[pad_size, (x.size // self.hop) - len(f0) - pad_size]], mode="constant")
return f0
def get_mangio_crepe(self, x, hop_length, model="full", onnx=False):
from main.library.predictors.CREPE import predict
audio = torch.from_numpy(x.astype(np.float32)).to(self.device)
audio /= torch.quantile(torch.abs(audio), 0.999)
audio = audio.unsqueeze(0)
source = predict(audio, self.fs, hop_length, self.f0_min, self.f0_max, model=model, batch_size=hop_length * 2, device=self.device, pad=True, providers=get_providers(), onnx=onnx).squeeze(0).cpu().float().numpy()
source[source < 0.001] = np.nan
return np.nan_to_num(np.interp(np.arange(0, len(source) * (x.size // self.hop), len(source)) / (x.size // self.hop), np.arange(0, len(source)), source))
def get_crepe(self, x, model="full", onnx=False):
from main.library.predictors.CREPE import predict, mean, median
f0, pd = predict(torch.tensor(np.copy(x))[None].float(), self.fs, 160, self.f0_min, self.f0_max, model, batch_size=512, device=self.device, return_periodicity=True, providers=get_providers(), onnx=onnx)
f0, pd = mean(f0, 3), median(pd, 3)
f0[pd < 0.1] = 0
return f0[0].cpu().numpy()
def get_fcpe(self, x, hop_length, legacy=False, onnx=False):
from main.library.predictors.FCPE import FCPE
model_fcpe = FCPE(os.path.join("assets", "models", "predictors", ("fcpe_legacy" if legacy else"fcpe") + (".onnx" if onnx else ".pt")), hop_length=int(hop_length), f0_min=int(self.f0_min), f0_max=int(self.f0_max), dtype=torch.float32, device=self.device, sample_rate=self.fs, threshold=0.03, providers=get_providers(), onnx=onnx, legacy=legacy)
f0 = model_fcpe.compute_f0(x, p_len=(x.size // self.hop))
del model_fcpe
return f0
def get_rmvpe(self, x, legacy=False, onnx=False):
from main.library.predictors.RMVPE import RMVPE
rmvpe_model = RMVPE(os.path.join("assets", "models", "predictors", "rmvpe" + (".onnx" if onnx else ".pt")), device=self.device, onnx=onnx, providers=get_providers())
f0 = rmvpe_model.infer_from_audio_with_pitch(x, thred=0.03, f0_min=self.f0_min, f0_max=self.f0_max) if legacy else rmvpe_model.infer_from_audio(x, thred=0.03)
del rmvpe_model
return f0
def get_pyworld_wrapper(self, x, model="harvest"):
from main.library.predictors.WORLD_WRAPPER import PYWORLD
pw = PYWORLD()
x = x.astype(np.double)
if model == "harvest": f0, t = pw.harvest(x, fs=self.fs, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=1000 * self.hop / self.fs)
elif model == "dio": f0, t = pw.dio(x, fs=self.fs, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=1000 * self.hop / self.fs)
else: raise ValueError(translations["method_not_valid"])
return pw.stonemask(x, self.fs, t, f0)
def get_pyworld(self, x, model="harvest"):
from main.library.predictors.pyworld import dio, harvest, stonemask
x = x.astype(np.double)
if model == "harvest": f0, t = harvest.harvest(x, fs=self.fs, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=1000 * self.hop / self.fs)
elif model == "dio": f0, t = dio.dio(x, fs=self.fs, f0_ceil=self.f0_max, f0_floor=self.f0_min, frame_period=1000 * self.hop / self.fs)
else: raise ValueError(translations["method_not_valid"])
return stonemask.stonemask(x, self.fs, t, f0)
def get_swipe(self, x):
from main.library.predictors.SWIPE import swipe
f0, _ = swipe(x.astype(np.double), self.fs, f0_floor=self.f0_min, f0_ceil=self.f0_max, frame_period=1000 * self.hop / self.fs, device=self.device)
return f0
def get_yin(self, x, hop_length, mode="yin"):
import librosa
if mode == "yin":
source = np.array(librosa.yin(x.astype(np.float32), sr=self.fs, fmin=self.f0_min, fmax=self.f0_max, hop_length=hop_length))
source[source < 0.001] = np.nan
else:
f0, _, _ = librosa.pyin(x.astype(np.float32), fmin=self.f0_min, fmax=self.f0_max, sr=self.fs, hop_length=hop_length)
source = np.array(f0)
source[source < 0.001] = np.nan
return np.nan_to_num(np.interp(np.arange(0, len(source) * (x.size // self.hop), len(source)) / (x.size // self.hop), np.arange(0, len(source)), source))
def coarse_f0(self, f0):
return np.rint(np.clip(((1127 * np.log(1 + f0 / 700)) - self.f0_mel_min) * (self.f0_bin - 2) / (self.f0_mel_max - self.f0_mel_min) + 1, 1, self.f0_bin - 1)).astype(int)
def process_file(self, file_info, f0_method, hop_length, f0_onnx):
inp_path, opt_path1, opt_path2, np_arr = file_info
if os.path.exists(opt_path1 + ".npy") and os.path.exists(opt_path2 + ".npy"): return
try:
feature_pit = self.compute_f0(np_arr, f0_method, hop_length, f0_onnx)
if isinstance(feature_pit, tuple): feature_pit = feature_pit[0]
np.save(opt_path2, feature_pit, allow_pickle=False)
np.save(opt_path1, self.coarse_f0(feature_pit), allow_pickle=False)
except Exception as e:
raise RuntimeError(f"{translations['extract_file_error']} {inp_path}: {e}")
def process_files(self, files, f0_method, hop_length, f0_onnx, device, pbar):
self.device = device
for file_info in files:
self.process_file(file_info, f0_method, hop_length, f0_onnx)
pbar.update()
def run_pitch_extraction(exp_dir, f0_method, hop_length, num_processes, gpus, f0_onnx):
input_root, *output_roots = setup_paths(exp_dir)
output_root1, output_root2 = output_roots if len(output_roots) == 2 else (output_roots[0], None)
paths = [(os.path.join(input_root, name), os.path.join(output_root1, name) if output_root1 else None, os.path.join(output_root2, name) if output_root2 else None, load_audio(logger, os.path.join(input_root, name), 16000)) for name in sorted(os.listdir(input_root)) if "spec" not in name]
logger.info(translations["extract_f0_method"].format(num_processes=num_processes, f0_method=f0_method))
start_time = time.time()
gpus = gpus.split("-")
process_partials = []
devices = get_device(gpu) if gpu != "" else "cpu"
pbar = tqdm.tqdm(total=len(paths), ncols=100, unit="p")
for idx, gpu in enumerate(gpus):
feature_input = FeatureInput(device=devices)
process_partials.append((feature_input, paths[idx::len(gpus)]))
with ThreadPoolExecutor(max_workers=num_processes) as executor:
for future in as_completed([executor.submit(FeatureInput.process_files, feature_input, part_paths, f0_method, hop_length, f0_onnx, devices, pbar) for feature_input, part_paths in process_partials]):
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
future.result()
pbar.close()
logger.info(translations["extract_f0_success"].format(elapsed_time=f"{(time.time() - start_time):.2f}"))
def extract_features(model, feats, version):
return torch.as_tensor(model.run([model.get_outputs()[0].name, model.get_outputs()[1].name], {"feats": feats.detach().cpu().numpy()})[0 if version == "v1" else 1], dtype=torch.float32, device=feats.device)
def process_file_embedding(file, wav_path, out_path, model, device, version, saved_cfg, embed_suffix):
out_file_path = os.path.join(out_path, file.replace("wav", "npy"))
if os.path.exists(out_file_path): return
feats = read_wave(os.path.join(wav_path, file), normalize=saved_cfg.task.normalize if saved_cfg else False).to(device).float()
if embed_suffix == ".pt": inputs = {"source": feats, "padding_mask": torch.BoolTensor(feats.shape).fill_(False).to(device), "output_layer": 9 if version == "v1" else 12}
with torch.no_grad():
if embed_suffix == ".pt":
model = model.to(device).float().eval()
logits = model.extract_features(**inputs)
feats = model.final_proj(logits[0]) if version == "v1" else logits[0]
else: feats = extract_features(model, feats, version).to(device)
feats = feats.squeeze(0).float().cpu().numpy()
if not np.isnan(feats).any(): np.save(out_file_path, feats, allow_pickle=False)
else: logger.warning(f"{file} {translations['NaN']}")
def run_embedding_extraction(exp_dir, version, gpus, embedder_model):
wav_path, out_path = setup_paths(exp_dir, version)
logger.info(translations["start_extract_hubert"])
start_time = time.time()
embedder_model_path = os.path.join("assets", "models", "embedders", embedder_model)
if not os.path.exists(embedder_model_path) and not embedder_model.endswith((".pt", ".onnx")): raise FileNotFoundError(f"{translations['not_found'].format(name=translations['model'])}: {embedder_model}")
try:
if embedder_model.endswith(".pt"):
models, saved_cfg, _ = checkpoint_utils.load_model_ensemble_and_task([embedder_model_path], suffix="")
models = models[0]
embed_suffix = ".pt"
else:
sess_options = onnxruntime.SessionOptions()
sess_options.log_severity_level = 3
models = onnxruntime.InferenceSession(embedder_model_path, sess_options=sess_options, providers=get_providers())
saved_cfg, embed_suffix = None, ".onnx"
except Exception as e:
raise ImportError(translations["read_model_error"].format(e=e))
devices = [(get_device(gpu) for gpu in (gpus.split("-"))) if gpus != "-" else "cpu"]
paths = sorted([file for file in os.listdir(wav_path) if file.endswith(".wav")])
if not paths:
logger.warning(translations["not_found_audio_file"])
sys.exit(1)
pbar = tqdm.tqdm(total=len(paths) * len(devices), ncols=100, unit="p")
for task in [(file, wav_path, out_path, models, device, version, saved_cfg, embed_suffix) for file in paths for device in devices]:
try:
process_file_embedding(*task)
except Exception as e:
raise RuntimeError(f"{translations['process_error']} {task[0]}: {e}")
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
pbar.close()
logger.info(translations["extract_hubert_success"].format(elapsed_time=f"{(time.time() - start_time):.2f}"))
if __name__ == "__main__":
args = parse_arguments()
exp_dir = os.path.join("assets", "logs", args.model_name)
f0_method, hop_length, num_processes, gpus, version, pitch_guidance, sample_rate, embedder_model, f0_onnx, embedders_onnx = args.f0_method, args.hop_length, args.cpu_cores, args.gpu, args.rvc_version, args.pitch_guidance, args.sample_rate, args.embedder_model, args.f0_onnx, args.embedders_onnx
check_predictors(f0_method, f0_onnx); check_embedders(embedder_model, embedders_onnx)
embedder_model += ".onnx" if embedders_onnx else ".pt"
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join(exp_dir, "extract.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
log_data = {translations['modelname']: args.model_name, translations['export_process']: exp_dir, translations['f0_method']: f0_method, translations['pretrain_sr']: sample_rate, translations['cpu_core']: num_processes, "Gpu": gpus, "Hop length": hop_length, translations['training_version']: version, translations['extract_f0']: pitch_guidance, translations['hubert_model']: embedder_model, translations["f0_onnx_mode"]: f0_onnx, translations["embed_onnx"]: embedders_onnx}
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
pid_path = os.path.join(exp_dir, "extract_pid.txt")
with open(pid_path, "w") as pid_file:
pid_file.write(str(os.getpid()))
try:
run_pitch_extraction(exp_dir, f0_method, hop_length, num_processes, gpus, f0_onnx)
run_embedding_extraction(exp_dir, version, gpus, embedder_model)
generate_config(version, sample_rate, exp_dir)
generate_filelist(pitch_guidance, exp_dir, version, sample_rate)
except Exception as e:
logger.error(f"{translations['extract_error']}: {e}")
import traceback
logger.debug(traceback.format_exc())
if os.path.exists(pid_path): os.remove(pid_path)
logger.info(f"{translations['extract_success']} {args.model_name}.")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270import os
import sys
import time
import logging
import librosa
import argparse
import logging.handlers
import numpy as np
from tqdm import tqdm
from scipy import signal
from scipy.io import wavfile
from distutils.util import strtobool
from concurrent.futures import ProcessPoolExecutor, as_completed
sys.path.append(os.getcwd())
from main.library.utils import load_audio
from main.configs.config import Config
logger = logging.getLogger(__name__)
for l in ["numba.core.byteflow", "numba.core.ssa", "numba.core.interpreter"]:
logging.getLogger(l).setLevel(logging.ERROR)
OVERLAP, MAX_AMPLITUDE, ALPHA, HIGH_PASS_CUTOFF, SAMPLE_RATE_16K = 0.3, 0.9, 0.75, 48, 16000
config = Config()
translations = config.translations
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--model_name", type=str, required=True)
parser.add_argument("--dataset_path", type=str, default="./dataset")
parser.add_argument("--sample_rate", type=int, required=True)
parser.add_argument("--cpu_cores", type=int, default=2)
parser.add_argument("--cut_preprocess", type=lambda x: bool(strtobool(x)), default=True)
parser.add_argument("--process_effects", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clean_dataset", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clean_strength", type=float, default=0.7)
return parser.parse_args()
class Slicer:
def __init__(self, sr, threshold = -40.0, min_length = 5000, min_interval = 300, hop_size = 20, max_sil_kept = 5000):
if not min_length >= min_interval >= hop_size: raise ValueError(translations["min_length>=min_interval>=hop_size"])
if not max_sil_kept >= hop_size: raise ValueError(translations["max_sil_kept>=hop_size"])
min_interval = sr * min_interval / 1000
self.threshold = 10 ** (threshold / 20.0)
self.hop_size = round(sr * hop_size / 1000)
self.win_size = min(round(min_interval), 4 * self.hop_size)
self.min_length = round(sr * min_length / 1000 / self.hop_size)
self.min_interval = round(min_interval / self.hop_size)
self.max_sil_kept = round(sr * max_sil_kept / 1000 / self.hop_size)
def _apply_slice(self, waveform, begin, end):
start_idx = begin * self.hop_size
if len(waveform.shape) > 1: return waveform[:, start_idx:min(waveform.shape[1], end * self.hop_size)]
else: return waveform[start_idx:min(waveform.shape[0], end * self.hop_size)]
def slice(self, waveform):
samples = waveform.mean(axis=0) if len(waveform.shape) > 1 else waveform
if samples.shape[0] <= self.min_length: return [waveform]
rms_list = get_rms(y=samples, frame_length=self.win_size, hop_length=self.hop_size).squeeze(0)
sil_tags = []
silence_start, clip_start = None, 0
for i, rms in enumerate(rms_list):
if rms < self.threshold:
if silence_start is None: silence_start = i
continue
if silence_start is None: continue
is_leading_silence = silence_start == 0 and i > self.max_sil_kept
need_slice_middle = (i - silence_start >= self.min_interval and i - clip_start >= self.min_length)
if not is_leading_silence and not need_slice_middle:
silence_start = None
continue
if i - silence_start <= self.max_sil_kept:
pos = rms_list[silence_start : i + 1].argmin() + silence_start
sil_tags.append((0, pos) if silence_start == 0 else (pos, pos))
clip_start = pos
elif i - silence_start <= self.max_sil_kept * 2:
pos = rms_list[i - self.max_sil_kept : silence_start + self.max_sil_kept + 1].argmin()
pos += i - self.max_sil_kept
pos_r = (rms_list[i - self.max_sil_kept : i + 1].argmin() + i - self.max_sil_kept)
if silence_start == 0:
sil_tags.append((0, pos_r))
clip_start = pos_r
else:
sil_tags.append((min((rms_list[silence_start : silence_start + self.max_sil_kept + 1].argmin() + silence_start), pos), max(pos_r, pos)))
clip_start = max(pos_r, pos)
else:
pos_r = (rms_list[i - self.max_sil_kept : i + 1].argmin() + i - self.max_sil_kept)
sil_tags.append((0, pos_r) if silence_start == 0 else ((rms_list[silence_start : silence_start + self.max_sil_kept + 1].argmin() + silence_start), pos_r))
clip_start = pos_r
silence_start = None
total_frames = rms_list.shape[0]
if (silence_start is not None and total_frames - silence_start >= self.min_interval): sil_tags.append((rms_list[silence_start : min(total_frames, silence_start + self.max_sil_kept) + 1].argmin() + silence_start, total_frames + 1))
if not sil_tags: return [waveform]
else:
chunks = []
if sil_tags[0][0] > 0: chunks.append(self._apply_slice(waveform, 0, sil_tags[0][0]))
for i in range(len(sil_tags) - 1):
chunks.append(self._apply_slice(waveform, sil_tags[i][1], sil_tags[i + 1][0]))
if sil_tags[-1][1] < total_frames: chunks.append(self._apply_slice(waveform, sil_tags[-1][1], total_frames))
return chunks
def get_rms(y, frame_length=2048, hop_length=512, pad_mode="constant"):
y = np.pad(y, (int(frame_length // 2), int(frame_length // 2)), mode=pad_mode)
axis = -1
x_shape_trimmed = list(y.shape)
x_shape_trimmed[axis] -= frame_length - 1
xw = np.moveaxis(np.lib.stride_tricks.as_strided(y, shape=tuple(x_shape_trimmed) + tuple([frame_length]), strides=y.strides + tuple([y.strides[axis]])), -1, axis - 1 if axis < 0 else axis + 1)
slices = [slice(None)] * xw.ndim
slices[axis] = slice(0, None, hop_length)
return np.sqrt(np.mean(np.abs(xw[tuple(slices)]) ** 2, axis=-2, keepdims=True))
class PreProcess:
def __init__(self, sr, exp_dir, per):
self.slicer = Slicer(sr=sr, threshold=-42, min_length=1500, min_interval=400, hop_size=15, max_sil_kept=500)
self.sr = sr
self.b_high, self.a_high = signal.butter(N=5, Wn=HIGH_PASS_CUTOFF, btype="high", fs=self.sr)
self.per = per
self.exp_dir = exp_dir
self.device = "cpu"
self.gt_wavs_dir = os.path.join(exp_dir, "sliced_audios")
self.wavs16k_dir = os.path.join(exp_dir, "sliced_audios_16k")
os.makedirs(self.gt_wavs_dir, exist_ok=True)
os.makedirs(self.wavs16k_dir, exist_ok=True)
def _normalize_audio(self, audio):
tmp_max = np.abs(audio).max()
if tmp_max > 2.5: return None
return (audio / tmp_max * (MAX_AMPLITUDE * ALPHA)) + (1 - ALPHA) * audio
def process_audio_segment(self, normalized_audio, sid, idx0, idx1):
if normalized_audio is None:
logger.debug(f"{sid}-{idx0}-{idx1}-filtered")
return
wavfile.write(os.path.join(self.gt_wavs_dir, f"{sid}_{idx0}_{idx1}.wav"), self.sr, normalized_audio.astype(np.float32))
wavfile.write(os.path.join(self.wavs16k_dir, f"{sid}_{idx0}_{idx1}.wav"), SAMPLE_RATE_16K, librosa.resample(normalized_audio, orig_sr=self.sr, target_sr=SAMPLE_RATE_16K, res_type="soxr_vhq").astype(np.float32))
def process_audio(self, path, idx0, sid, cut_preprocess, process_effects, clean_dataset, clean_strength):
try:
audio = load_audio(logger, path, self.sr)
if process_effects:
audio = signal.lfilter(self.b_high, self.a_high, audio)
audio = self._normalize_audio(audio)
if clean_dataset:
from main.tools.noisereduce import reduce_noise
audio = reduce_noise(y=audio, sr=self.sr, prop_decrease=clean_strength, device=config.device)
idx1 = 0
if cut_preprocess:
for audio_segment in self.slicer.slice(audio):
i = 0
while 1:
start = int(self.sr * (self.per - OVERLAP) * i)
i += 1
if len(audio_segment[start:]) > (self.per + OVERLAP) * self.sr:
self.process_audio_segment(audio_segment[start : start + int(self.per * self.sr)], sid, idx0, idx1)
idx1 += 1
else:
self.process_audio_segment(audio_segment[start:], sid, idx0, idx1)
idx1 += 1
break
else: self.process_audio_segment(audio, sid, idx0, idx1)
except Exception as e:
raise RuntimeError(f"{translations['process_audio_error']}: {e}")
def process_file(args):
pp, file, cut_preprocess, process_effects, clean_dataset, clean_strength = (args)
file_path, idx0, sid = file
pp.process_audio(file_path, idx0, sid, cut_preprocess, process_effects, clean_dataset, clean_strength)
def preprocess_training_set(input_root, sr, num_processes, exp_dir, per, cut_preprocess, process_effects, clean_dataset, clean_strength):
start_time = time.time()
pp = PreProcess(sr, exp_dir, per)
logger.info(translations["start_preprocess"].format(num_processes=num_processes))
files = []
idx = 0
for root, _, filenames in os.walk(input_root):
try:
sid = 0 if root == input_root else int(os.path.basename(root))
for f in filenames:
if f.lower().endswith(("wav", "mp3", "flac", "ogg", "opus", "m4a", "mp4", "aac", "alac", "wma", "aiff", "webm", "ac3")):
files.append((os.path.join(root, f), idx, sid))
idx += 1
except ValueError:
raise ValueError(f"{translations['not_integer']} '{os.path.basename(root)}'.")
with tqdm(total=len(files), ncols=100, unit="f") as pbar:
with ProcessPoolExecutor(max_workers=num_processes) as executor:
futures = [executor.submit(process_file, (pp, file, cut_preprocess, process_effects, clean_dataset, clean_strength)) for file in files]
for future in as_completed(futures):
try:
future.result()
except Exception as e:
raise RuntimeError(f"{translations['process_error']}: {e}")
pbar.update(1)
logger.debug(pbar.format_meter(pbar.n, pbar.total, pbar.format_dict["elapsed"]))
elapsed_time = time.time() - start_time
logger.info(translations["preprocess_success"].format(elapsed_time=f"{elapsed_time:.2f}"))
if __name__ == "__main__":
args = parse_arguments()
experiment_directory = os.path.join("assets", "logs", args.model_name)
num_processes = args.cpu_cores
num_processes = 2 if num_processes is None else int(num_processes)
dataset = args.dataset_path
sample_rate = args.sample_rate
cut_preprocess = args.cut_preprocess
preprocess_effects = args.process_effects
clean_dataset = args.clean_dataset
clean_strength = args.clean_strength
os.makedirs(experiment_directory, exist_ok=True)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join(experiment_directory, "preprocess.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
log_data = {translations['modelname']: args.model_name, translations['export_process']: experiment_directory, translations['dataset_folder']: dataset, translations['pretrain_sr']: sample_rate, translations['cpu_core']: num_processes, translations['split_audio']: cut_preprocess, translations['preprocess_effect']: preprocess_effects, translations['clear_audio']: clean_dataset}
if clean_dataset: log_data[translations['clean_strength']] = clean_strength
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
pid_path = os.path.join(experiment_directory, "preprocess_pid.txt")
with open(pid_path, "w") as pid_file:
pid_file.write(str(os.getpid()))
try:
preprocess_training_set(dataset, sample_rate, num_processes, experiment_directory, 3.7, cut_preprocess, preprocess_effects, clean_dataset, clean_strength)
except Exception as e:
logger.error(f"{translations['process_audio_error']} {e}")
import traceback
logger.debug(traceback.format_exc())
if os.path.exists(pid_path): os.remove(pid_path)
logger.info(f"{translations['preprocess_model_success']} {args.model_name}")123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310import os
import sys
import time
import logging
import argparse
import logging.handlers
from distutils.util import strtobool
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.algorithm.separator import Separator
from main.library.utils import pydub_convert, pydub_load
config = Config()
translations = config.translations
logger = logging.getLogger(__name__)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join("assets", "logs", "separator.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_formatter = logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
file_handler.setFormatter(file_formatter)
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
demucs_models = {"HT-Tuned": "htdemucs_ft.yaml", "HT-Normal": "htdemucs.yaml", "HD_MMI": "hdemucs_mmi.yaml", "HT_6S": "htdemucs_6s.yaml"}
mdx_models = {"Main_340": "UVR-MDX-NET_Main_340.onnx", "Main_390": "UVR-MDX-NET_Main_390.onnx", "Main_406": "UVR-MDX-NET_Main_406.onnx", "Main_427": "UVR-MDX-NET_Main_427.onnx", "Main_438": "UVR-MDX-NET_Main_438.onnx", "Inst_full_292": "UVR-MDX-NET-Inst_full_292.onnx", "Inst_HQ_1": "UVR-MDX-NET_Inst_HQ_1.onnx", "Inst_HQ_2": "UVR-MDX-NET_Inst_HQ_2.onnx", "Inst_HQ_3": "UVR-MDX-NET_Inst_HQ_3.onnx", "Inst_HQ_4": "UVR-MDX-NET-Inst_HQ_4.onnx", "Inst_HQ_5": "UVR-MDX-NET-Inst_HQ_5.onnx", "Kim_Vocal_1": "Kim_Vocal_1.onnx", "Kim_Vocal_2": "Kim_Vocal_2.onnx", "Kim_Inst": "Kim_Inst.onnx", "Inst_187_beta": "UVR-MDX-NET_Inst_187_beta.onnx", "Inst_82_beta": "UVR-MDX-NET_Inst_82_beta.onnx", "Inst_90_beta": "UVR-MDX-NET_Inst_90_beta.onnx", "Voc_FT": "UVR-MDX-NET-Voc_FT.onnx", "Crowd_HQ": "UVR-MDX-NET_Crowd_HQ_1.onnx", "MDXNET_9482": "UVR_MDXNET_9482.onnx", "Inst_1": "UVR-MDX-NET-Inst_1.onnx", "Inst_2": "UVR-MDX-NET-Inst_2.onnx", "Inst_3": "UVR-MDX-NET-Inst_3.onnx", "MDXNET_1_9703": "UVR_MDXNET_1_9703.onnx", "MDXNET_2_9682": "UVR_MDXNET_2_9682.onnx", "MDXNET_3_9662": "UVR_MDXNET_3_9662.onnx", "Inst_Main": "UVR-MDX-NET-Inst_Main.onnx", "MDXNET_Main": "UVR_MDXNET_Main.onnx"}
kara_models = {"Version-1": "UVR_MDXNET_KARA.onnx", "Version-2": "UVR_MDXNET_KARA_2.onnx"}
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--input_path", type=str, required=True)
parser.add_argument("--output_path", type=str, default="./audios")
parser.add_argument("--format", type=str, default="wav")
parser.add_argument("--shifts", type=int, default=2)
parser.add_argument("--segments_size", type=int, default=256)
parser.add_argument("--overlap", type=float, default=0.25)
parser.add_argument("--mdx_hop_length", type=int, default=1024)
parser.add_argument("--mdx_batch_size", type=int, default=1)
parser.add_argument("--clean_audio", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--clean_strength", type=float, default=0.7)
parser.add_argument("--model_name", type=str, default="HT-Normal")
parser.add_argument("--kara_model", type=str, default="Version-1")
parser.add_argument("--backing", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--mdx_denoise", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--reverb", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--backing_reverb", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--sample_rate", type=int, default=44100)
return parser.parse_args()
def main():
start_time = time.time()
pid_path = os.path.join("assets", "separate_pid.txt")
with open(pid_path, "w") as pid_file:
pid_file.write(str(os.getpid()))
try:
args = parse_arguments()
input_path, output_path, export_format, shifts, segments_size, overlap, hop_length, batch_size, clean_audio, clean_strength, model_name, kara_model, backing, mdx_denoise, reverb, backing_reverb, sample_rate = args.input_path, args.output_path, args.format, args.shifts, args.segments_size, args.overlap, args.mdx_hop_length, args.mdx_batch_size, args.clean_audio, args.clean_strength, args.model_name, args.kara_model, args.backing, args.mdx_denoise, args.reverb, args.backing_reverb, args.sample_rate
if backing_reverb and not reverb:
logger.warning(translations["turn_on_dereverb"])
sys.exit(1)
if backing_reverb and not backing:
logger.warning(translations["turn_on_separator_backing"])
sys.exit(1)
input_path = input_path.strip(" ").strip('"').strip("\n").strip('"').strip(" ")
output_path = os.path.dirname(output_path) or output_path
log_data = {translations['audio_path']: input_path, translations['output_path']: output_path, translations['export_format']: export_format, translations['shift']: shifts, translations['segments_size']: segments_size, translations['overlap']: overlap, translations['modelname']: model_name, translations['denoise_mdx']: mdx_denoise, "Hop length": hop_length, translations['batch_size']: batch_size, translations['sr']: sample_rate}
if clean_audio:
log_data[translations['clear_audio']] = clean_audio
log_data[translations['clean_strength']] = clean_strength
if backing:
log_data[translations['backing_model_ver']] = kara_model
log_data[translations['separator_backing']] = backing
if reverb:
log_data[translations['dereveb_audio']] = reverb
log_data[translations['dereveb_backing']] = backing_reverb
for key, value in log_data.items():
logger.debug(f"{key}: {value}")
if os.path.isdir(input_path):
for f in input_path:
separation(f, output_path, export_format, shifts, overlap, segments_size, model_name, sample_rate, mdx_denoise, hop_length, batch_size, backing, reverb, kara_model, backing_reverb, clean_audio, clean_strength)
else: separation(input_path, output_path, export_format, shifts, overlap, segments_size, model_name, sample_rate, mdx_denoise, hop_length, batch_size, backing, reverb, kara_model, backing_reverb, clean_audio, clean_strength)
except Exception as e:
logger.error(f"{translations['separator_error']}: {e}")
import traceback
logger.debug(traceback.format_exc())
if os.path.exists(pid_path): os.remove(pid_path)
elapsed_time = time.time() - start_time
logger.info(translations["separator_success"].format(elapsed_time=f"{elapsed_time:.2f}"))
def separation(input_path, output_path, export_format, shifts, overlap, segments_size, model_name, sample_rate, mdx_denoise, hop_length, batch_size, backing, reverb, kara_model, backing_reverb, clean_audio, clean_strength):
filename, _ = os.path.splitext(os.path.basename(input_path))
output_path = os.path.join(output_path, filename)
os.makedirs(output_path, exist_ok=True)
if model_name in ["HT-Tuned", "HT-Normal", "HD_MMI", "HT_6S"]: vocals, _ = separator_music_demucs(input_path, output_path, export_format, shifts, overlap, segments_size, model_name, sample_rate)
else: vocals, _ = separator_music_mdx(input_path, output_path, export_format, segments_size, overlap, mdx_denoise, model_name, hop_length, batch_size, sample_rate)
if backing: main_vocals, backing_vocals = separator_backing(vocals, output_path, export_format, segments_size, overlap, mdx_denoise, kara_model, hop_length, batch_size, sample_rate)
if reverb: vocals_no_reverb, main_vocals_no_reverb, backing_vocals_no_reverb = separator_reverb(output_path, export_format, segments_size, overlap, mdx_denoise, reverb, backing_reverb, hop_length, batch_size, sample_rate)
original_output = os.path.join(output_path, f"Original_Vocals_No_Reverb.{export_format}") if reverb else os.path.join(output_path, f"Original_Vocals.{export_format}")
main_output = os.path.join(output_path, f"Main_Vocals_No_Reverb.{export_format}") if reverb and backing_reverb else os.path.join(output_path, f"Main_Vocals.{export_format}")
backing_output = os.path.join(output_path, f"Backing_Vocals_No_Reverb.{export_format}") if reverb and backing_reverb else os.path.join(output_path, f"Backing_Vocals.{export_format}")
if clean_audio:
import soundfile as sf
logger.info(f"{translations['clear_audio']}...")
vocal_data, vocal_sr = sf.read(vocals_no_reverb if reverb else vocals)
main_data, main_sr = sf.read(main_vocals_no_reverb if reverb and backing else main_vocals)
backing_data, backing_sr = sf.read(backing_vocals_no_reverb if reverb and backing_reverb else backing_vocals)
from main.tools.noisereduce import reduce_noise
sf.write(original_output, reduce_noise(y=vocal_data, prop_decrease=clean_strength), vocal_sr, format=export_format, device=config.device)
if backing:
sf.write(main_output, reduce_noise(y=main_data, sr=main_sr, prop_decrease=clean_strength), main_sr, format=export_format, device=config.device)
sf.write(backing_output, reduce_noise(y=backing_data, sr=backing_sr, prop_decrease=clean_strength), backing_sr, format=export_format, device=config.device)
logger.info(translations["clean_audio_success"])
def separator_music_demucs(input, output, format, shifts, overlap, segments_size, demucs_model, sample_rate):
if not os.path.exists(input):
logger.warning(translations["input_not_valid"])
sys.exit(1)
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
sys.exit(1)
for i in [f"Original_Vocals.{format}", f"Instruments.{format}"]:
if os.path.exists(os.path.join(output, i)): os.remove(os.path.join(output, i))
logger.info(f"{translations['separator_process_2']}...")
demucs_output = separator_main(audio_file=input, model_filename=demucs_models.get(demucs_model), output_format=format, output_dir=output, demucs_segment_size=(segments_size / 2), demucs_shifts=shifts, demucs_overlap=overlap, sample_rate=sample_rate)
for f in demucs_output:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Drums)_' in f: drums = path
elif '_(Bass)_' in f: bass = path
elif '_(Other)_' in f: other = path
elif '_(Vocals)_' in f: os.rename(path, os.path.join(output, f"Original_Vocals.{format}"))
pydub_convert(pydub_load(drums)).overlay(pydub_convert(pydub_load(bass))).overlay(pydub_convert(pydub_load(other))).export(os.path.join(output, f"Instruments.{format}"), format=format)
for f in [drums, bass, other]:
if os.path.exists(f): os.remove(f)
logger.info(translations["separator_success_2"])
return os.path.join(output, f"Original_Vocals.{format}"), os.path.join(output, f"Instruments.{format}")
def separator_backing(input, output, format, segments_size, overlap, denoise, kara_model, hop_length, batch_size, sample_rate):
if not os.path.exists(input):
logger.warning(translations["input_not_valid"])
sys.exit(1)
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
sys.exit(1)
for f in [f"Main_Vocals.{format}", f"Backing_Vocals.{format}"]:
if os.path.exists(os.path.join(output, f)): os.remove(os.path.join(output, f))
model_2 = kara_models.get(kara_model)
logger.info(f"{translations['separator_process_backing']}...")
backing_outputs = separator_main(audio_file=input, model_filename=model_2, output_format=format, output_dir=output, mdx_segment_size=segments_size, mdx_overlap=overlap, mdx_batch_size=batch_size, mdx_hop_length=hop_length, mdx_enable_denoise=denoise, sample_rate=sample_rate)
main_output = os.path.join(output, f"Main_Vocals.{format}")
backing_output = os.path.join(output, f"Backing_Vocals.{format}")
for f in backing_outputs:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Instrumental)_' in f: os.rename(path, backing_output)
elif '_(Vocals)_' in f: os.rename(path, main_output)
logger.info(translations["separator_process_backing_success"])
return main_output, backing_output
def separator_music_mdx(input, output, format, segments_size, overlap, denoise, mdx_model, hop_length, batch_size, sample_rate):
if not os.path.exists(input):
logger.warning(translations["input_not_valid"])
sys.exit(1)
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
sys.exit(1)
for i in [f"Original_Vocals.{format}", f"Instruments.{format}"]:
if os.path.exists(os.path.join(output, i)): os.remove(os.path.join(output, i))
model_3 = mdx_models.get(mdx_model)
logger.info(f"{translations['separator_process_2']}...")
output_music = separator_main(audio_file=input, model_filename=model_3, output_format=format, output_dir=output, mdx_segment_size=segments_size, mdx_overlap=overlap, mdx_batch_size=batch_size, mdx_hop_length=hop_length, mdx_enable_denoise=denoise, sample_rate=sample_rate)
original_output, instruments_output = os.path.join(output, f"Original_Vocals.{format}"), os.path.join(output, f"Instruments.{format}")
for f in output_music:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Instrumental)_' in f: os.rename(path, instruments_output)
elif '_(Vocals)_' in f: os.rename(path, original_output)
logger.info(translations["separator_process_backing_success"])
return original_output, instruments_output
def separator_reverb(output, format, segments_size, overlap, denoise, original, backing_reverb, hop_length, batch_size, sample_rate):
if not os.path.exists(output):
logger.warning(translations["output_not_valid"])
sys.exit(1)
for i in [f"Original_Vocals_Reverb.{format}", f"Main_Vocals_Reverb.{format}", f"Original_Vocals_No_Reverb.{format}", f"Main_Vocals_No_Reverb.{format}"]:
if os.path.exists(os.path.join(output, i)): os.remove(os.path.join(output, i))
dereveb_path = []
if original:
try:
dereveb_path.append(os.path.join(output, [f for f in os.listdir(output) if 'Original_Vocals' in f][0]))
except IndexError:
logger.warning(translations["not_found_original_vocal"])
sys.exit(1)
if backing_reverb:
try:
dereveb_path.append(os.path.join(output, [f for f in os.listdir(output) if 'Main_Vocals' in f][0]))
except IndexError:
logger.warning(translations["not_found_main_vocal"])
sys.exit(1)
if backing_reverb:
try:
dereveb_path.append(os.path.join(output, [f for f in os.listdir(output) if 'Backing_Vocals' in f][0]))
except IndexError:
logger.warning(translations["not_found_backing_vocal"])
sys.exit(1)
for path in dereveb_path:
if not os.path.exists(path):
logger.warning(translations["not_found"].format(name=path))
sys.exit(1)
if "Original_Vocals" in path:
reverb_path, no_reverb_path = os.path.join(output, f"Original_Vocals_Reverb.{format}"), os.path.join(output, f"Original_Vocals_No_Reverb.{format}")
start_title, end_title = translations["process_original"], translations["process_original_success"]
elif "Main_Vocals" in path:
reverb_path, no_reverb_path = os.path.join(output, f"Main_Vocals_Reverb.{format}"), os.path.join(output, f"Main_Vocals_No_Reverb.{format}")
start_title, end_title = translations["process_main"], translations["process_main_success"]
elif "Backing_Vocals" in path:
reverb_path, no_reverb_path = os.path.join(output, f"Backing_Vocals_Reverb.{format}"), os.path.join(output, f"Backing_Vocals_No_Reverb.{format}")
start_title, end_title = translations["process_backing"], translations["process_backing_success"]
logger.info(start_title)
output_dereveb = separator_main(audio_file=path, model_filename="Reverb_HQ_By_FoxJoy.onnx", output_format=format, output_dir=output, mdx_segment_size=segments_size, mdx_overlap=overlap, mdx_batch_size=batch_size, mdx_hop_length=hop_length, mdx_enable_denoise=denoise, sample_rate=sample_rate)
for f in output_dereveb:
path = os.path.join(output, f)
if not os.path.exists(path): logger.error(translations["not_found"].format(name=path))
if '_(Reverb)_' in f: os.rename(path, reverb_path)
elif '_(No Reverb)_' in f: os.rename(path, no_reverb_path)
logger.info(end_title)
return (os.path.join(output, f"Original_Vocals_No_Reverb.{format}") if original else None), (os.path.join(output, f"Main_Vocals_No_Reverb.{format}") if backing_reverb else None), (os.path.join(output, f"Backing_Vocals_No_Reverb.{format}") if backing_reverb else None)
def separator_main(audio_file=None, model_filename="UVR-MDX-NET_Main_340.onnx", output_format="wav", output_dir=".", mdx_segment_size=256, mdx_overlap=0.25, mdx_batch_size=1, mdx_hop_length=1024, mdx_enable_denoise=True, demucs_segment_size=256, demucs_shifts=2, demucs_overlap=0.25, sample_rate=44100):
try:
separator = Separator(logger=logger, log_formatter=file_formatter, log_level=logging.INFO, output_dir=output_dir, output_format=output_format, output_bitrate=None, normalization_threshold=0.9, output_single_stem=None, invert_using_spec=False, sample_rate=sample_rate, mdx_params={"hop_length": mdx_hop_length, "segment_size": mdx_segment_size, "overlap": mdx_overlap, "batch_size": mdx_batch_size, "enable_denoise": mdx_enable_denoise}, demucs_params={"segment_size": demucs_segment_size, "shifts": demucs_shifts, "overlap": demucs_overlap, "segments_enabled": True})
separator.load_model(model_filename=model_filename)
return separator.separate(audio_file)
except:
logger.debug(translations["default_setting"])
separator = Separator(logger=logger, log_formatter=file_formatter, log_level=logging.INFO, output_dir=output_dir, output_format=output_format, output_bitrate=None, normalization_threshold=0.9, output_single_stem=None, invert_using_spec=False, sample_rate=44100, mdx_params={"hop_length": 1024, "segment_size": 256, "overlap": 0.25, "batch_size": 1, "enable_denoise": mdx_enable_denoise}, demucs_params={"segment_size": 128, "shifts": 2, "overlap": 0.25, "segments_enabled": True})
separator.load_model(model_filename=model_filename)
return separator.separate(audio_file)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980import os
import sys
import glob
import json
import torch
import hashlib
import logging
import argparse
import datetime
import warnings
import logging.handlers
import numpy as np
import soundfile as sf
import matplotlib.pyplot as plt
import torch.distributed as dist
import torch.utils.data as tdata
import torch.multiprocessing as mp
from tqdm import tqdm
from collections import OrderedDict
from random import randint, shuffle
from torch.utils.checkpoint import checkpoint
from torch.cuda.amp import GradScaler, autocast
from torch.utils.tensorboard import SummaryWriter
from time import time as ttime
from torch.nn import functional as F
from distutils.util import strtobool
from librosa.filters import mel as librosa_mel_fn
from torch.nn.parallel import DistributedDataParallel as DDP
from torch.nn.utils.parametrizations import spectral_norm, weight_norm
sys.path.append(os.getcwd())
from main.configs.config import Config
from main.library.algorithm.residuals import LRELU_SLOPE
from main.library.algorithm.synthesizers import Synthesizer
from main.library.algorithm.commons import get_padding, slice_segments, clip_grad_value
MATPLOTLIB_FLAG = False
translations = Config().translations
warnings.filterwarnings("ignore")
logging.getLogger("torch").setLevel(logging.ERROR)
class HParams:
def __init__(self, **kwargs):
for k, v in kwargs.items():
self[k] = HParams(**v) if isinstance(v, dict) else v
def keys(self):
return self.__dict__.keys()
def items(self):
return self.__dict__.items()
def values(self):
return self.__dict__.values()
def __len__(self):
return len(self.__dict__)
def __getitem__(self, key):
return self.__dict__[key]
def __setitem__(self, key, value):
self.__dict__[key] = value
def __contains__(self, key):
return key in self.__dict__
def __repr__(self):
return repr(self.__dict__)
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("--model_name", type=str, required=True)
parser.add_argument("--rvc_version", type=str, default="v2")
parser.add_argument("--save_every_epoch", type=int, required=True)
parser.add_argument("--save_only_latest", type=lambda x: bool(strtobool(x)), default=True)
parser.add_argument("--save_every_weights", type=lambda x: bool(strtobool(x)), default=True)
parser.add_argument("--total_epoch", type=int, default=300)
parser.add_argument("--sample_rate", type=int, required=True)
parser.add_argument("--batch_size", type=int, default=8)
parser.add_argument("--gpu", type=str, default="0")
parser.add_argument("--pitch_guidance", type=lambda x: bool(strtobool(x)), default=True)
parser.add_argument("--g_pretrained_path", type=str, default="")
parser.add_argument("--d_pretrained_path", type=str, default="")
parser.add_argument("--overtraining_detector", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--overtraining_threshold", type=int, default=50)
parser.add_argument("--cleanup", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--cache_data_in_gpu", type=lambda x: bool(strtobool(x)), default=False)
parser.add_argument("--model_author", type=str)
parser.add_argument("--vocoder", type=str, default="Default")
parser.add_argument("--checkpointing", type=lambda x: bool(strtobool(x)), default=False)
return parser.parse_args()
args = parse_arguments()
model_name, save_every_epoch, total_epoch, pretrainG, pretrainD, version, gpus, batch_size, sample_rate, pitch_guidance, save_only_latest, save_every_weights, cache_data_in_gpu, overtraining_detector, overtraining_threshold, cleanup, model_author, vocoder, checkpointing = args.model_name, args.save_every_epoch, args.total_epoch, args.g_pretrained_path, args.d_pretrained_path, args.rvc_version, args.gpu, args.batch_size, args.sample_rate, args.pitch_guidance, args.save_only_latest, args.save_every_weights, args.cache_data_in_gpu, args.overtraining_detector, args.overtraining_threshold, args.cleanup, args.model_author, args.vocoder, args.checkpointing
experiment_dir = os.path.join("assets", "logs", model_name)
training_file_path = os.path.join(experiment_dir, "training_data.json")
config_save_path = os.path.join(experiment_dir, "config.json")
os.environ["CUDA_VISIBLE_DEVICES"] = gpus.replace("-", ",")
n_gpus = len(gpus.split("-"))
torch.backends.cudnn.deterministic = False
torch.backends.cudnn.benchmark = False
lowest_value = {"step": 0, "value": float("inf"), "epoch": 0}
global_step, last_loss_gen_all, overtrain_save_epoch = 0, 0, 0
loss_gen_history, smoothed_loss_gen_history, loss_disc_history, smoothed_loss_disc_history = [], [], [], []
with open(config_save_path, "r") as f:
config = json.load(f)
config = HParams(**config)
config.data.training_files = os.path.join(experiment_dir, "filelist.txt")
logger = logging.getLogger(__name__)
if logger.hasHandlers(): logger.handlers.clear()
else:
console_handler = logging.StreamHandler()
console_handler.setFormatter(logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S"))
console_handler.setLevel(logging.INFO)
file_handler = logging.handlers.RotatingFileHandler(os.path.join(experiment_dir, "train.log"), maxBytes=5*1024*1024, backupCount=3, encoding='utf-8')
file_handler.setFormatter(logging.Formatter(fmt="\n%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s | %(message)s", datefmt="%Y-%m-%d %H:%M:%S"))
file_handler.setLevel(logging.DEBUG)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG)
log_data = {translations['modelname']: model_name, translations["save_every_epoch"]: save_every_epoch, translations["total_e"]: total_epoch, translations["dorg"].format(pretrainG=pretrainG, pretrainD=pretrainD): "", translations['training_version']: version, "Gpu": gpus, translations['batch_size']: batch_size, translations['pretrain_sr']: sample_rate, translations['training_f0']: pitch_guidance, translations['save_only_latest']: save_only_latest, translations['save_every_weights']: save_every_weights, translations['cache_in_gpu']: cache_data_in_gpu, translations['overtraining_detector']: overtraining_detector, translations['threshold']: overtraining_threshold, translations['cleanup_training']: cleanup, translations['memory_efficient_training']: checkpointing}
if model_author: log_data[translations["model_author"].format(model_author=model_author)] = ""
if vocoder != "Default": log_data[translations['vocoder']] = vocoder
for key, value in log_data.items():
logger.debug(f"{key}: {value}" if value != "" else f"{key} {value}")
def main():
global training_file_path, last_loss_gen_all, smoothed_loss_gen_history, loss_gen_history, loss_disc_history, smoothed_loss_disc_history, overtrain_save_epoch, model_author, vocoder, checkpointing
os.environ["MASTER_ADDR"] = "localhost"
os.environ["MASTER_PORT"] = str(randint(20000, 55555))
if torch.cuda.is_available(): device, n_gpus = torch.device("cuda"), torch.cuda.device_count()
elif torch.backends.mps.is_available(): device, n_gpus = torch.device("mps"), 1
else: device, n_gpus = torch.device("cpu"), 1
def start():
children = []
pid_data = {"process_pids": []}
with open(config_save_path, "r") as pid_file:
try:
pid_data.update(json.load(pid_file))
except json.JSONDecodeError:
pass
with open(config_save_path, "w") as pid_file:
for i in range(n_gpus):
subproc = mp.Process(target=run, args=(i, n_gpus, experiment_dir, pretrainG, pretrainD, pitch_guidance, total_epoch, save_every_weights, config, device, model_author, vocoder, checkpointing))
children.append(subproc)
subproc.start()
pid_data["process_pids"].append(subproc.pid)
json.dump(pid_data, pid_file, indent=4)
for i in range(n_gpus):
children[i].join()
def load_from_json(file_path):
if os.path.exists(file_path):
with open(file_path, "r") as f:
data = json.load(f)
return (data.get("loss_disc_history", []), data.get("smoothed_loss_disc_history", []), data.get("loss_gen_history", []), data.get("smoothed_loss_gen_history", []))
return [], [], [], []
def continue_overtrain_detector(training_file_path):
if overtraining_detector and os.path.exists(training_file_path): (loss_disc_history, smoothed_loss_disc_history, loss_gen_history, smoothed_loss_gen_history) = load_from_json(training_file_path)
n_gpus = torch.cuda.device_count()
if not torch.cuda.is_available() and torch.backends.mps.is_available(): n_gpus = 1
if n_gpus < 1:
logger.warning(translations["not_gpu"])
n_gpus = 1
if cleanup:
for root, dirs, files in os.walk(experiment_dir, topdown=False):
for name in files:
file_path = os.path.join(root, name)
_, file_extension = os.path.splitext(name)
if (file_extension == ".0" or (name.startswith("D_") and file_extension == ".pth") or (name.startswith("G_") and file_extension == ".pth") or (file_extension == ".index")): os.remove(file_path)
for name in dirs:
if name == "eval":
folder_path = os.path.join(root, name)
for item in os.listdir(folder_path):
item_path = os.path.join(folder_path, item)
if os.path.isfile(item_path): os.remove(item_path)
os.rmdir(folder_path)
continue_overtrain_detector(training_file_path)
start()
def plot_spectrogram_to_numpy(spectrogram):
global MATPLOTLIB_FLAG
if not MATPLOTLIB_FLAG:
plt.switch_backend("Agg")
MATPLOTLIB_FLAG = True
fig, ax = plt.subplots(figsize=(10, 2))
plt.colorbar(ax.imshow(spectrogram, aspect="auto", origin="lower", interpolation="none"), ax=ax)
plt.xlabel("Frames")
plt.ylabel("Channels")
plt.tight_layout()
fig.canvas.draw()
plt.close(fig)
return np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8).reshape(fig.canvas.get_width_height()[::-1] + (3,))
def verify_checkpoint_shapes(checkpoint_path, model):
checkpoint = torch.load(checkpoint_path, map_location="cpu")
checkpoint_state_dict = checkpoint["model"]
try:
model_state_dict = model.module.load_state_dict(checkpoint_state_dict) if hasattr(model, "module") else model.load_state_dict(checkpoint_state_dict)
except RuntimeError:
logger.warning(translations["checkpointing_err"])
sys.exit(1)
else: del checkpoint, checkpoint_state_dict, model_state_dict
def summarize(writer, global_step, scalars={}, histograms={}, images={}, audios={}, audio_sample_rate=22050):
for k, v in scalars.items():
writer.add_scalar(k, v, global_step)
for k, v in histograms.items():
writer.add_histogram(k, v, global_step)
for k, v in images.items():
writer.add_image(k, v, global_step, dataformats="HWC")
for k, v in audios.items():
writer.add_audio(k, v, global_step, audio_sample_rate)
def load_checkpoint(checkpoint_path, model, optimizer=None, load_opt=1):
assert os.path.isfile(checkpoint_path), translations["not_found_checkpoint"].format(checkpoint_path=checkpoint_path)
checkpoint_dict = replace_keys_in_dict(replace_keys_in_dict(torch.load(checkpoint_path, map_location="cpu"), ".weight_v", ".parametrizations.weight.original1"), ".weight_g", ".parametrizations.weight.original0")
new_state_dict = {k: checkpoint_dict["model"].get(k, v) for k, v in (model.module.state_dict() if hasattr(model, "module") else model.state_dict()).items()}
if hasattr(model, "module"): model.module.load_state_dict(new_state_dict, strict=False)
else: model.load_state_dict(new_state_dict, strict=False)
if optimizer and load_opt == 1: optimizer.load_state_dict(checkpoint_dict.get("optimizer", {}))
logger.debug(translations["save_checkpoint"].format(checkpoint_path=checkpoint_path, checkpoint_dict=checkpoint_dict['iteration']))
return (model, optimizer, checkpoint_dict.get("learning_rate", 0), checkpoint_dict["iteration"])
def save_checkpoint(model, optimizer, learning_rate, iteration, checkpoint_path):
state_dict = (model.module.state_dict() if hasattr(model, "module") else model.state_dict())
torch.save(replace_keys_in_dict(replace_keys_in_dict({"model": state_dict, "iteration": iteration, "optimizer": optimizer.state_dict(), "learning_rate": learning_rate}, ".parametrizations.weight.original1", ".weight_v"), ".parametrizations.weight.original0", ".weight_g"), checkpoint_path)
logger.info(translations["save_model"].format(checkpoint_path=checkpoint_path, iteration=iteration))
def latest_checkpoint_path(dir_path, regex="G_*.pth"):
checkpoints = sorted(glob.glob(os.path.join(dir_path, regex)), key=lambda f: int("".join(filter(str.isdigit, f))))
return checkpoints[-1] if checkpoints else None
def load_wav_to_torch(full_path):
data, sample_rate = sf.read(full_path, dtype='float32')
return torch.FloatTensor(data.astype(np.float32)), sample_rate
def load_filepaths_and_text(filename, split="|"):
with open(filename, encoding="utf-8") as f:
return [line.strip().split(split) for line in f]
def feature_loss(fmap_r, fmap_g):
loss = 0
for dr, dg in zip(fmap_r, fmap_g):
for rl, gl in zip(dr, dg):
loss += torch.mean(torch.abs(rl.float().detach() - gl.float()))
return loss * 2
def discriminator_loss(disc_real_outputs, disc_generated_outputs):
loss = 0
r_losses, g_losses = [], []
for dr, dg in zip(disc_real_outputs, disc_generated_outputs):
dr = dr.float()
dg = dg.float()
r_loss = torch.mean((1 - dr) ** 2)
g_loss = torch.mean(dg**2)
loss += r_loss + g_loss
r_losses.append(r_loss.item())
g_losses.append(g_loss.item())
return loss, r_losses, g_losses
def generator_loss(disc_outputs):
loss = 0
gen_losses = []
for dg in disc_outputs:
l = torch.mean((1 - dg.float()) ** 2)
gen_losses.append(l)
loss += l
return loss, gen_losses
def kl_loss(z_p, logs_q, m_p, logs_p, z_mask):
z_p = z_p.float()
logs_q = logs_q.float()
m_p = m_p.float()
logs_p = logs_p.float()
z_mask = z_mask.float()
kl = logs_p - logs_q - 0.5
kl += 0.5 * ((z_p - m_p) ** 2) * torch.exp(-2.0 * logs_p)
return torch.sum(kl * z_mask) / torch.sum(z_mask)
class TextAudioLoaderMultiNSFsid(tdata.Dataset):
def __init__(self, hparams):
self.audiopaths_and_text = load_filepaths_and_text(hparams.training_files)
self.max_wav_value = hparams.max_wav_value
self.sample_rate = hparams.sample_rate
self.filter_length = hparams.filter_length
self.hop_length = hparams.hop_length
self.win_length = hparams.win_length
self.sample_rate = hparams.sample_rate
self.min_text_len = getattr(hparams, "min_text_len", 1)
self.max_text_len = getattr(hparams, "max_text_len", 5000)
self._filter()
def _filter(self):
audiopaths_and_text_new, lengths = [], []
for audiopath, text, pitch, pitchf, dv in self.audiopaths_and_text:
if self.min_text_len <= len(text) and len(text) <= self.max_text_len:
audiopaths_and_text_new.append([audiopath, text, pitch, pitchf, dv])
lengths.append(os.path.getsize(audiopath) // (3 * self.hop_length))
self.audiopaths_and_text = audiopaths_and_text_new
self.lengths = lengths
def get_sid(self, sid):
try:
sid = torch.LongTensor([int(sid)])
except ValueError as e:
logger.error(translations["sid_error"].format(sid=sid, e=e))
sid = torch.LongTensor([0])
return sid
def get_audio_text_pair(self, audiopath_and_text):
phone, pitch, pitchf = self.get_labels(audiopath_and_text[1], audiopath_and_text[2], audiopath_and_text[3])
spec, wav = self.get_audio(audiopath_and_text[0])
dv = self.get_sid(audiopath_and_text[4])
len_phone = phone.size()[0]
len_spec = spec.size()[-1]
if len_phone != len_spec:
len_min = min(len_phone, len_spec)
len_wav = len_min * self.hop_length
spec, wav, phone = spec[:, :len_min], wav[:, :len_wav], phone[:len_min, :]
pitch, pitchf = pitch[:len_min], pitchf[:len_min]
return (spec, wav, phone, pitch, pitchf, dv)
def get_labels(self, phone, pitch, pitchf):
phone = np.repeat(np.load(phone), 2, axis=0)
n_num = min(phone.shape[0], 900)
return torch.FloatTensor(phone[:n_num, :]), torch.LongTensor(np.load(pitch)[:n_num]), torch.FloatTensor(np.load(pitchf)[:n_num])
def get_audio(self, filename):
audio, sample_rate = load_wav_to_torch(filename)
if sample_rate != self.sample_rate: raise ValueError(translations["sr_does_not_match"].format(sample_rate=sample_rate, sample_rate2=self.sample_rate))
audio_norm = audio.unsqueeze(0)
spec_filename = filename.replace(".wav", ".spec.pt")
if os.path.exists(spec_filename):
try:
spec = torch.load(spec_filename)
except Exception as e:
logger.error(translations["spec_error"].format(spec_filename=spec_filename, e=e))
spec = torch.squeeze(spectrogram_torch(audio_norm, self.filter_length, self.hop_length, self.win_length, center=False), 0)
torch.save(spec, spec_filename, _use_new_zipfile_serialization=False)
else:
spec = torch.squeeze(spectrogram_torch(audio_norm, self.filter_length, self.hop_length, self.win_length, center=False), 0)
torch.save(spec, spec_filename, _use_new_zipfile_serialization=False)
return spec, audio_norm
def __getitem__(self, index):
return self.get_audio_text_pair(self.audiopaths_and_text[index])
def __len__(self):
return len(self.audiopaths_and_text)
class TextAudioCollateMultiNSFsid:
def __init__(self, return_ids=False):
self.return_ids = return_ids
def __call__(self, batch):
_, ids_sorted_decreasing = torch.sort(torch.LongTensor([x[0].size(1) for x in batch]), dim=0, descending=True)
spec_lengths, wave_lengths = torch.LongTensor(len(batch)), torch.LongTensor(len(batch))
spec_padded, wave_padded = torch.FloatTensor(len(batch), batch[0][0].size(0), max([x[0].size(1) for x in batch])), torch.FloatTensor(len(batch), 1, max([x[1].size(1) for x in batch]))
spec_padded.zero_()
wave_padded.zero_()
max_phone_len = max([x[2].size(0) for x in batch])
phone_lengths, phone_padded = torch.LongTensor(len(batch)), torch.FloatTensor(len(batch), max_phone_len, batch[0][2].shape[1])
pitch_padded, pitchf_padded = torch.LongTensor(len(batch), max_phone_len), torch.FloatTensor(len(batch), max_phone_len)
phone_padded.zero_()
pitch_padded.zero_()
pitchf_padded.zero_()
sid = torch.LongTensor(len(batch))
for i in range(len(ids_sorted_decreasing)):
row = batch[ids_sorted_decreasing[i]]
spec = row[0]
spec_padded[i, :, : spec.size(1)] = spec
spec_lengths[i] = spec.size(1)
wave = row[1]
wave_padded[i, :, : wave.size(1)] = wave
wave_lengths[i] = wave.size(1)
phone = row[2]
phone_padded[i, : phone.size(0), :] = phone
phone_lengths[i] = phone.size(0)
pitch = row[3]
pitch_padded[i, : pitch.size(0)] = pitch
pitchf = row[4]
pitchf_padded[i, : pitchf.size(0)] = pitchf
sid[i] = row[5]
return (phone_padded, phone_lengths, pitch_padded, pitchf_padded, spec_padded, spec_lengths, wave_padded, wave_lengths, sid)
class TextAudioLoader(tdata.Dataset):
def __init__(self, hparams):
self.audiopaths_and_text = load_filepaths_and_text(hparams.training_files)
self.max_wav_value = hparams.max_wav_value
self.sample_rate = hparams.sample_rate
self.filter_length = hparams.filter_length
self.hop_length = hparams.hop_length
self.win_length = hparams.win_length
self.sample_rate = hparams.sample_rate
self.min_text_len = getattr(hparams, "min_text_len", 1)
self.max_text_len = getattr(hparams, "max_text_len", 5000)
self._filter()
def _filter(self):
audiopaths_and_text_new, lengths = [], []
for entry in self.audiopaths_and_text:
if len(entry) >= 3:
audiopath, text, dv = entry[:3]
if self.min_text_len <= len(text) and len(text) <= self.max_text_len:
audiopaths_and_text_new.append([audiopath, text, dv])
lengths.append(os.path.getsize(audiopath) // (3 * self.hop_length))
self.audiopaths_and_text = audiopaths_and_text_new
self.lengths = lengths
def get_sid(self, sid):
try:
sid = torch.LongTensor([int(sid)])
except ValueError as e:
logger.error(translations["sid_error"].format(sid=sid, e=e))
sid = torch.LongTensor([0])
return sid
def get_audio_text_pair(self, audiopath_and_text):
phone = self.get_labels(audiopath_and_text[1])
spec, wav = self.get_audio(audiopath_and_text[0])
dv = self.get_sid(audiopath_and_text[2])
len_phone = phone.size()[0]
len_spec = spec.size()[-1]
if len_phone != len_spec:
len_min = min(len_phone, len_spec)
len_wav = len_min * self.hop_length
spec = spec[:, :len_min]
wav = wav[:, :len_wav]
phone = phone[:len_min, :]
return (spec, wav, phone, dv)
def get_labels(self, phone):
phone = np.repeat(np.load(phone), 2, axis=0)
return torch.FloatTensor(phone[:min(phone.shape[0], 900), :])
def get_audio(self, filename):
audio, sample_rate = load_wav_to_torch(filename)
if sample_rate != self.sample_rate: raise ValueError(translations["sr_does_not_match"].format(sample_rate=sample_rate, sample_rate2=self.sample_rate))
audio_norm = audio.unsqueeze(0)
spec_filename = filename.replace(".wav", ".spec.pt")
if os.path.exists(spec_filename):
try:
spec = torch.load(spec_filename)
except Exception as e:
logger.error(translations["spec_error"].format(spec_filename=spec_filename, e=e))
spec = torch.squeeze(spectrogram_torch(audio_norm, self.filter_length, self.hop_length, self.win_length, center=False), 0)
torch.save(spec, spec_filename, _use_new_zipfile_serialization=False)
else:
spec = torch.squeeze(spectrogram_torch(audio_norm, self.filter_length, self.hop_length, self.win_length, center=False), 0)
torch.save(spec, spec_filename, _use_new_zipfile_serialization=False)
return spec, audio_norm
def __getitem__(self, index):
return self.get_audio_text_pair(self.audiopaths_and_text[index])
def __len__(self):
return len(self.audiopaths_and_text)
class TextAudioCollate:
def __init__(self, return_ids=False):
self.return_ids = return_ids
def __call__(self, batch):
_, ids_sorted_decreasing = torch.sort(torch.LongTensor([x[0].size(1) for x in batch]), dim=0, descending=True)
spec_lengths, wave_lengths = torch.LongTensor(len(batch)), torch.LongTensor(len(batch))
spec_padded, wave_padded = torch.FloatTensor(len(batch), batch[0][0].size(0), max([x[0].size(1) for x in batch])), torch.FloatTensor(len(batch), 1, max([x[1].size(1) for x in batch]))
spec_padded.zero_()
wave_padded.zero_()
max_phone_len = max([x[2].size(0) for x in batch])
phone_lengths, phone_padded = torch.LongTensor(len(batch)), torch.FloatTensor(len(batch), max_phone_len, batch[0][2].shape[1])
phone_padded.zero_()
sid = torch.LongTensor(len(batch))
for i in range(len(ids_sorted_decreasing)):
row = batch[ids_sorted_decreasing[i]]
spec = row[0]
spec_padded[i, :, : spec.size(1)] = spec
spec_lengths[i] = spec.size(1)
wave = row[1]
wave_padded[i, :, : wave.size(1)] = wave
wave_lengths[i] = wave.size(1)
phone = row[2]
phone_padded[i, : phone.size(0), :] = phone
phone_lengths[i] = phone.size(0)
sid[i] = row[3]
return (phone_padded, phone_lengths, spec_padded, spec_lengths, wave_padded, wave_lengths, sid)
class DistributedBucketSampler(tdata.distributed.DistributedSampler):
def __init__(self, dataset, batch_size, boundaries, num_replicas=None, rank=None, shuffle=True):
super().__init__(dataset, num_replicas=num_replicas, rank=rank, shuffle=shuffle)
self.lengths = dataset.lengths
self.batch_size = batch_size
self.boundaries = boundaries
self.buckets, self.num_samples_per_bucket = self._create_buckets()
self.total_size = sum(self.num_samples_per_bucket)
self.num_samples = self.total_size // self.num_replicas
def _create_buckets(self):
buckets = [[] for _ in range(len(self.boundaries) - 1)]
for i in range(len(self.lengths)):
idx_bucket = self._bisect(self.lengths[i])
if idx_bucket != -1: buckets[idx_bucket].append(i)
for i in range(len(buckets) - 1, -1, -1):
if len(buckets[i]) == 0:
buckets.pop(i)
self.boundaries.pop(i + 1)
num_samples_per_bucket = []
for i in range(len(buckets)):
len_bucket = len(buckets[i])
total_batch_size = self.num_replicas * self.batch_size
num_samples_per_bucket.append(len_bucket + ((total_batch_size - (len_bucket % total_batch_size)) % total_batch_size))
return buckets, num_samples_per_bucket
def __iter__(self):
g = torch.Generator()
g.manual_seed(self.epoch)
indices, batches = [], []
if self.shuffle:
for bucket in self.buckets:
indices.append(torch.randperm(len(bucket), generator=g).tolist())
else:
for bucket in self.buckets:
indices.append(list(range(len(bucket))))
for i in range(len(self.buckets)):
bucket = self.buckets[i]
len_bucket = len(bucket)
ids_bucket = indices[i]
rem = self.num_samples_per_bucket[i] - len_bucket
ids_bucket = (ids_bucket + ids_bucket * (rem // len_bucket) + ids_bucket[: (rem % len_bucket)])[self.rank :: self.num_replicas]
for j in range(len(ids_bucket) // self.batch_size):
batches.append([bucket[idx] for idx in ids_bucket[j * self.batch_size : (j + 1) * self.batch_size]])
if self.shuffle: batches = [batches[i] for i in torch.randperm(len(batches), generator=g).tolist()]
self.batches = batches
assert len(self.batches) * self.batch_size == self.num_samples
return iter(self.batches)
def _bisect(self, x, lo=0, hi=None):
if hi is None: hi = len(self.boundaries) - 1
if hi > lo:
mid = (hi + lo) // 2
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]: return mid
elif x <= self.boundaries[mid]: return self._bisect(x, lo, mid)
else: return self._bisect(x, mid + 1, hi)
else: return -1
def __len__(self):
return self.num_samples // self.batch_size
class MultiPeriodDiscriminator(torch.nn.Module):
def __init__(self, version, use_spectral_norm=False, checkpointing=False):
super(MultiPeriodDiscriminator, self).__init__()
self.checkpointing = checkpointing
periods = ([2, 3, 5, 7, 11, 17] if version == "v1" else [2, 3, 5, 7, 11, 17, 23, 37])
self.discriminators = torch.nn.ModuleList([DiscriminatorS(use_spectral_norm=use_spectral_norm, checkpointing=checkpointing)] + [DiscriminatorP(p, use_spectral_norm=use_spectral_norm, checkpointing=checkpointing) for p in periods])
def forward(self, y, y_hat):
y_d_rs, y_d_gs, fmap_rs, fmap_gs = [], [], [], []
for d in self.discriminators:
if self.training and self.checkpointing:
def forward_discriminator(d, y, y_hat):
y_d_r, fmap_r = d(y)
y_d_g, fmap_g = d(y_hat)
return y_d_r, fmap_r, y_d_g, fmap_g
y_d_r, fmap_r, y_d_g, fmap_g = checkpoint(forward_discriminator, d, y, y_hat, use_reentrant=False)
else:
y_d_r, fmap_r = d(y)
y_d_g, fmap_g = d(y_hat)
y_d_rs.append(y_d_r); fmap_rs.append(fmap_r)
y_d_gs.append(y_d_g); fmap_gs.append(fmap_g)
return y_d_rs, y_d_gs, fmap_rs, fmap_gs
class DiscriminatorS(torch.nn.Module):
def __init__(self, use_spectral_norm=False, checkpointing=False):
super(DiscriminatorS, self).__init__()
self.checkpointing = checkpointing
norm_f = spectral_norm if use_spectral_norm else weight_norm
self.convs = torch.nn.ModuleList([norm_f(torch.nn.Conv1d(1, 16, 15, 1, padding=7)), norm_f(torch.nn.Conv1d(16, 64, 41, 4, groups=4, padding=20)), norm_f(torch.nn.Conv1d(64, 256, 41, 4, groups=16, padding=20)), norm_f(torch.nn.Conv1d(256, 1024, 41, 4, groups=64, padding=20)), norm_f(torch.nn.Conv1d(1024, 1024, 41, 4, groups=256, padding=20)), norm_f(torch.nn.Conv1d(1024, 1024, 5, 1, padding=2))])
self.conv_post = norm_f(torch.nn.Conv1d(1024, 1, 3, 1, padding=1))
self.lrelu = torch.nn.LeakyReLU(LRELU_SLOPE)
def forward(self, x):
fmap = []
for conv in self.convs:
x = checkpoint(self.lrelu, checkpoint(conv, x, use_reentrant = False), use_reentrant = False) if self.training and self.checkpointing else self.lrelu(conv(x))
fmap.append(x)
x = self.conv_post(x)
fmap.append(x)
return torch.flatten(x, 1, -1), fmap
class DiscriminatorP(torch.nn.Module):
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False, checkpointing=False):
super(DiscriminatorP, self).__init__()
self.period = period
self.checkpointing = checkpointing
norm_f = spectral_norm if use_spectral_norm else weight_norm
self.convs = torch.nn.ModuleList([norm_f(torch.nn.Conv2d(in_ch, out_ch, (kernel_size, 1), (stride, 1), padding=(get_padding(kernel_size, 1), 0))) for in_ch, out_ch in zip([1, 32, 128, 512, 1024], [32, 128, 512, 1024, 1024])])
self.conv_post = norm_f(torch.nn.Conv2d(1024, 1, (3, 1), 1, padding=(1, 0)))
self.lrelu = torch.nn.LeakyReLU(LRELU_SLOPE)
def forward(self, x):
fmap = []
b, c, t = x.shape
if t % self.period != 0: x = torch.nn.functional.pad(x, (0, (self.period - (t % self.period))), "reflect")
x = x.view(b, c, -1, self.period)
for conv in self.convs:
x = checkpoint(self.lrelu, checkpoint(conv, x, use_reentrant = False), use_reentrant = False) if self.training and self.checkpointing else self.lrelu(conv(x))
fmap.append(x)
x = self.conv_post(x)
fmap.append(x)
return torch.flatten(x, 1, -1), fmap
class EpochRecorder:
def __init__(self):
self.last_time = ttime()
def record(self):
now_time = ttime()
elapsed_time = now_time - self.last_time
self.last_time = now_time
return translations["time_or_speed_training"].format(current_time=datetime.datetime.now().strftime("%H:%M:%S"), elapsed_time_str=str(datetime.timedelta(seconds=int(round(elapsed_time, 1)))))
def dynamic_range_compression_torch(x, C=1, clip_val=1e-5):
return torch.log(torch.clamp(x, min=clip_val) * C)
def dynamic_range_decompression_torch(x, C=1):
return torch.exp(x) / C
def spectral_normalize_torch(magnitudes):
return dynamic_range_compression_torch(magnitudes)
def spectral_de_normalize_torch(magnitudes):
return dynamic_range_decompression_torch(magnitudes)
mel_basis, hann_window = {}, {}
def spectrogram_torch(y, n_fft, hop_size, win_size, center=False):
global hann_window
wnsize_dtype_device = str(win_size) + "_" + str(y.dtype) + "_" + str(y.device)
if wnsize_dtype_device not in hann_window: hann_window[wnsize_dtype_device] = torch.hann_window(win_size).to(dtype=y.dtype, device=y.device)
spec = torch.stft(torch.nn.functional.pad(y.unsqueeze(1), (int((n_fft - hop_size) / 2), int((n_fft - hop_size) / 2)), mode="reflect").squeeze(1), n_fft, hop_length=hop_size, win_length=win_size, window=hann_window[wnsize_dtype_device], center=center, pad_mode="reflect", normalized=False, onesided=True, return_complex=True)
return torch.sqrt(spec.real.pow(2) + spec.imag.pow(2) + 1e-6)
def spec_to_mel_torch(spec, n_fft, num_mels, sample_rate, fmin, fmax):
global mel_basis
fmax_dtype_device = str(fmax) + "_" + str(spec.dtype) + "_" + str(spec.device)
if fmax_dtype_device not in mel_basis: mel_basis[fmax_dtype_device] = torch.from_numpy(librosa_mel_fn(sr=sample_rate, n_fft=n_fft, n_mels=num_mels, fmin=fmin, fmax=fmax)).to(dtype=spec.dtype, device=spec.device)
return spectral_normalize_torch(torch.matmul(mel_basis[fmax_dtype_device], spec))
def mel_spectrogram_torch(y, n_fft, num_mels, sample_rate, hop_size, win_size, fmin, fmax, center=False):
return spec_to_mel_torch(spectrogram_torch(y, n_fft, hop_size, win_size, center), n_fft, num_mels, sample_rate, fmin, fmax)
def replace_keys_in_dict(d, old_key_part, new_key_part):
updated_dict = OrderedDict() if isinstance(d, OrderedDict) else {}
for key, value in d.items():
updated_dict[(key.replace(old_key_part, new_key_part) if isinstance(key, str) else key)] = (replace_keys_in_dict(value, old_key_part, new_key_part) if isinstance(value, dict) else value)
return updated_dict
def extract_model(ckpt, sr, pitch_guidance, name, model_path, epoch, step, version, hps, model_author, vocoder):
try:
logger.info(translations["savemodel"].format(model_dir=model_path, epoch=epoch, step=step))
os.makedirs(os.path.dirname(model_path), exist_ok=True)
opt = OrderedDict(weight={key: value.half() for key, value in ckpt.items() if "enc_q" not in key})
opt["config"] = [hps.data.filter_length // 2 + 1, 32, hps.model.inter_channels, hps.model.hidden_channels, hps.model.filter_channels, hps.model.n_heads, hps.model.n_layers, hps.model.kernel_size, hps.model.p_dropout, hps.model.resblock, hps.model.resblock_kernel_sizes, hps.model.resblock_dilation_sizes, hps.model.upsample_rates, hps.model.upsample_initial_channel, hps.model.upsample_kernel_sizes, hps.model.spk_embed_dim, hps.model.gin_channels, hps.data.sample_rate]
opt["epoch"] = f"{epoch}epoch"
opt["step"] = step
opt["sr"] = sr
opt["f0"] = int(pitch_guidance)
opt["version"] = version
opt["creation_date"] = datetime.datetime.now().isoformat()
opt["model_hash"] = hashlib.sha256(f"{str(ckpt)} {epoch} {step} {datetime.datetime.now().isoformat()}".encode()).hexdigest()
opt["model_name"] = name
opt["author"] = model_author
opt["vocoder"] = vocoder
torch.save(replace_keys_in_dict(replace_keys_in_dict(opt, ".parametrizations.weight.original1", ".weight_v"), ".parametrizations.weight.original0", ".weight_g"), model_path)
except Exception as e:
logger.error(f"{translations['extract_model_error']}: {e}")
def run(rank, n_gpus, experiment_dir, pretrainG, pretrainD, pitch_guidance, custom_total_epoch, custom_save_every_weights, config, device, model_author, vocoder, checkpointing):
global global_step
if rank == 0: writer_eval = SummaryWriter(log_dir=os.path.join(experiment_dir, "eval"))
else: writer_eval = None
dist.init_process_group(backend="gloo", init_method="env://", world_size=n_gpus, rank=rank)
torch.manual_seed(config.train.seed)
if torch.cuda.is_available(): torch.cuda.set_device(rank)
train_dataset = TextAudioLoaderMultiNSFsid(config.data)
train_loader = tdata.DataLoader(train_dataset, num_workers=4, shuffle=False, pin_memory=True, collate_fn=TextAudioCollateMultiNSFsid(), batch_sampler=DistributedBucketSampler(train_dataset, batch_size * n_gpus, [100, 200, 300, 400, 500, 600, 700, 800, 900], num_replicas=n_gpus, rank=rank, shuffle=True), persistent_workers=True, prefetch_factor=8)
net_g, net_d = Synthesizer(config.data.filter_length // 2 + 1, config.train.segment_size // config.data.hop_length, **config.model, use_f0=pitch_guidance, sr=sample_rate, vocoder=vocoder, checkpointing=checkpointing), MultiPeriodDiscriminator(version, config.model.use_spectral_norm, checkpointing=checkpointing)
net_g, net_d = (net_g.cuda(rank), net_d.cuda(rank)) if torch.cuda.is_available() else (net_g.to(device), net_d.to(device))
optim_g, optim_d = torch.optim.AdamW(net_g.parameters(), config.train.learning_rate, betas=config.train.betas, eps=config.train.eps), torch.optim.AdamW(net_d.parameters(), config.train.learning_rate, betas=config.train.betas, eps=config.train.eps)
net_g, net_d = (DDP(net_g, device_ids=[rank]), DDP(net_d, device_ids=[rank])) if torch.cuda.is_available() else (DDP(net_g), DDP(net_d))
try:
logger.info(translations["start_training"])
_, _, _, epoch_str = load_checkpoint((os.path.join(experiment_dir, "D_latest.pth") if save_only_latest else latest_checkpoint_path(experiment_dir, "D_*.pth")), net_d, optim_d)
_, _, _, epoch_str = load_checkpoint((os.path.join(experiment_dir, "G_latest.pth") if save_only_latest else latest_checkpoint_path(experiment_dir, "G_*.pth")), net_g, optim_g)
epoch_str += 1
global_step = (epoch_str - 1) * len(train_loader)
except:
epoch_str, global_step = 1, 0
if pretrainG != "" and pretrainG != "None":
if rank == 0:
verify_checkpoint_shapes(pretrainG, net_g)
logger.info(translations["import_pretrain"].format(dg="G", pretrain=pretrainG))
if hasattr(net_g, "module"): net_g.module.load_state_dict(torch.load(pretrainG, map_location="cpu")["model"])
else: net_g.load_state_dict(torch.load(pretrainG, map_location="cpu")["model"])
else: logger.warning(translations["not_using_pretrain"].format(dg="G"))
if pretrainD != "" and pretrainD != "None":
if rank == 0:
verify_checkpoint_shapes(pretrainD, net_d)
logger.info(translations["import_pretrain"].format(dg="D", pretrain=pretrainD))
if hasattr(net_d, "module"): net_d.module.load_state_dict(torch.load(pretrainD, map_location="cpu")["model"])
else: net_d.load_state_dict(torch.load(pretrainD, map_location="cpu")["model"])
else: logger.warning(translations["not_using_pretrain"].format(dg="D"))
scheduler_g, scheduler_d = torch.optim.lr_scheduler.ExponentialLR(optim_g, gamma=config.train.lr_decay, last_epoch=epoch_str - 2), torch.optim.lr_scheduler.ExponentialLR(optim_d, gamma=config.train.lr_decay, last_epoch=epoch_str - 2)
optim_d.step(); optim_g.step()
scaler = GradScaler(enabled=False)
cache = []
for info in train_loader:
phone, phone_lengths, pitch, pitchf, _, _, _, _, sid = info
reference = (phone.cuda(rank, non_blocking=True), phone_lengths.cuda(rank, non_blocking=True), (pitch.cuda(rank, non_blocking=True) if pitch_guidance else None), (pitchf.cuda(rank, non_blocking=True) if pitch_guidance else None), sid.cuda(rank, non_blocking=True)) if device.type == "cuda" else (phone.to(device), phone_lengths.to(device), (pitch.to(device) if pitch_guidance else None), (pitchf.to(device) if pitch_guidance else None), sid.to(device))
break
for epoch in range(epoch_str, total_epoch + 1):
train_and_evaluate(rank, epoch, config, [net_g, net_d], [optim_g, optim_d], scaler, train_loader, writer_eval, cache, custom_save_every_weights, custom_total_epoch, device, reference, model_author, vocoder)
scheduler_g.step(); scheduler_d.step()
def train_and_evaluate(rank, epoch, hps, nets, optims, scaler, train_loader, writer, cache, custom_save_every_weights, custom_total_epoch, device, reference, model_author, vocoder):
global global_step, lowest_value, loss_disc, consecutive_increases_gen, consecutive_increases_disc
if epoch == 1:
lowest_value = {"step": 0, "value": float("inf"), "epoch": 0}
last_loss_gen_all, consecutive_increases_gen, consecutive_increases_disc = 0.0, 0, 0
net_g, net_d = nets
optim_g, optim_d = optims
train_loader.batch_sampler.set_epoch(epoch)
net_g.train(); net_d.train()
if device.type == "cuda" and cache_data_in_gpu:
data_iterator = cache
if cache == []:
for batch_idx, info in enumerate(train_loader):
cache.append((batch_idx, [tensor.cuda(rank, non_blocking=True) for tensor in info]))
else: shuffle(cache)
else: data_iterator = enumerate(train_loader)
epoch_recorder = EpochRecorder()
with tqdm(total=len(train_loader), leave=False) as pbar:
for batch_idx, info in data_iterator:
if device.type == "cuda" and not cache_data_in_gpu: info = [tensor.cuda(rank, non_blocking=True) for tensor in info]
elif device.type != "cuda": info = [tensor.to(device) for tensor in info]
phone, phone_lengths, pitch, pitchf, spec, spec_lengths, wave, _, sid = info
pitch = pitch if pitch_guidance else None
pitchf = pitchf if pitch_guidance else None
with autocast(enabled=False):
y_hat, ids_slice, _, z_mask, (_, z_p, m_p, logs_p, _, logs_q) = net_g(phone, phone_lengths, pitch, pitchf, spec, spec_lengths, sid)
mel = spec_to_mel_torch(spec, config.data.filter_length, config.data.n_mel_channels, config.data.sample_rate, config.data.mel_fmin, config.data.mel_fmax)
y_mel = slice_segments(mel, ids_slice, config.train.segment_size // config.data.hop_length, dim=3)
with autocast(enabled=False):
y_hat_mel = mel_spectrogram_torch(y_hat.float().squeeze(1), config.data.filter_length, config.data.n_mel_channels, config.data.sample_rate, config.data.hop_length, config.data.win_length, config.data.mel_fmin, config.data.mel_fmax)
wave = slice_segments(wave, ids_slice * config.data.hop_length, config.train.segment_size, dim=3)
y_d_hat_r, y_d_hat_g, _, _ = net_d(wave, y_hat.detach())
with autocast(enabled=False):
loss_disc, losses_disc_r, losses_disc_g = discriminator_loss(y_d_hat_r, y_d_hat_g)
optim_d.zero_grad()
scaler.scale(loss_disc).backward()
scaler.unscale_(optim_d)
grad_norm_d = clip_grad_value(net_d.parameters(), None)
scaler.step(optim_d)
with autocast(enabled=False):
y_d_hat_r, y_d_hat_g, fmap_r, fmap_g = net_d(wave, y_hat)
with autocast(enabled=False):
loss_mel = F.l1_loss(y_mel, y_hat_mel) * config.train.c_mel
loss_kl = (kl_loss(z_p, logs_q, m_p, logs_p, z_mask) * config.train.c_kl)
loss_fm = feature_loss(fmap_r, fmap_g)
loss_gen, losses_gen = generator_loss(y_d_hat_g)
loss_gen_all = loss_gen + loss_fm + loss_mel + loss_kl
if loss_gen_all < lowest_value["value"]:
lowest_value["value"] = loss_gen_all
lowest_value["step"] = global_step
lowest_value["epoch"] = epoch
if epoch > lowest_value["epoch"]: logger.warning(translations["training_warning"])
optim_g.zero_grad()
scaler.scale(loss_gen_all).backward()
scaler.unscale_(optim_g)
grad_norm_g = clip_grad_value(net_g.parameters(), None)
scaler.step(optim_g)
scaler.update()
if rank == 0 and global_step % config.train.log_interval == 0:
if loss_mel > 75: loss_mel = 75
if loss_kl > 9: loss_kl = 9
scalar_dict = {"loss/g/total": loss_gen_all, "loss/d/total": loss_disc, "learning_rate": optim_g.param_groups[0]["lr"], "grad/norm_d": grad_norm_d, "grad/norm_g": grad_norm_g, "loss/g/fm": loss_fm, "loss/g/mel": loss_mel, "loss/g/kl": loss_kl}
scalar_dict.update({f"loss/g/{i}": v for i, v in enumerate(losses_gen)})
scalar_dict.update({f"loss/d_r/{i}": v for i, v in enumerate(losses_disc_r)})
scalar_dict.update({f"loss/d_g/{i}": v for i, v in enumerate(losses_disc_g)})
with torch.no_grad():
o, *_ = net_g.module.infer(*reference) if hasattr(net_g, "module") else net_g.infer(*reference)
summarize(writer=writer, global_step=global_step, images={"slice/mel_org": plot_spectrogram_to_numpy(y_mel[0].data.cpu().numpy()), "slice/mel_gen": plot_spectrogram_to_numpy(y_hat_mel[0].data.cpu().numpy()), "all/mel": plot_spectrogram_to_numpy(mel[0].data.cpu().numpy())}, scalars=scalar_dict, audios={f"gen/audio_{global_step:07d}": o[0, :, :]}, audio_sample_rate=config.data.sample_rate)
global_step += 1
pbar.update(1)
def check_overtraining(smoothed_loss_history, threshold, epsilon=0.004):
if len(smoothed_loss_history) < threshold + 1: return False
for i in range(-threshold, -1):
if smoothed_loss_history[i + 1] > smoothed_loss_history[i]: return True
if abs(smoothed_loss_history[i + 1] - smoothed_loss_history[i]) >= epsilon: return False
return True
def update_exponential_moving_average(smoothed_loss_history, new_value, smoothing=0.987):
smoothed_value = new_value if not smoothed_loss_history else (smoothing * smoothed_loss_history[-1] + (1 - smoothing) * new_value)
smoothed_loss_history.append(smoothed_value)
return smoothed_value
def save_to_json(file_path, loss_disc_history, smoothed_loss_disc_history, loss_gen_history, smoothed_loss_gen_history):
with open(file_path, "w") as f:
json.dump({"loss_disc_history": loss_disc_history, "smoothed_loss_disc_history": smoothed_loss_disc_history, "loss_gen_history": loss_gen_history, "smoothed_loss_gen_history": smoothed_loss_gen_history}, f)
model_add, model_del = [], []
done = False
if rank == 0:
if epoch % save_every_epoch == False:
checkpoint_suffix = f"{'latest' if save_only_latest else global_step}.pth"
save_checkpoint(net_g, optim_g, config.train.learning_rate, epoch, os.path.join(experiment_dir, "G_" + checkpoint_suffix))
save_checkpoint(net_d, optim_d, config.train.learning_rate, epoch, os.path.join(experiment_dir, "D_" + checkpoint_suffix))
if custom_save_every_weights: model_add.append(os.path.join("assets", "weights", f"{model_name}_{epoch}e_{global_step}s.pth"))
if overtraining_detector and epoch > 1:
current_loss_disc = float(loss_disc)
loss_disc_history.append(current_loss_disc)
smoothed_value_disc = update_exponential_moving_average(smoothed_loss_disc_history, current_loss_disc)
is_overtraining_disc = check_overtraining(smoothed_loss_disc_history, overtraining_threshold * 2)
if is_overtraining_disc: consecutive_increases_disc += 1
else: consecutive_increases_disc = 0
current_loss_gen = float(lowest_value["value"])
loss_gen_history.append(current_loss_gen)
smoothed_value_gen = update_exponential_moving_average(smoothed_loss_gen_history, current_loss_gen)
is_overtraining_gen = check_overtraining(smoothed_loss_gen_history, overtraining_threshold, 0.01)
if is_overtraining_gen: consecutive_increases_gen += 1
else: consecutive_increases_gen = 0
if epoch % save_every_epoch == 0: save_to_json(training_file_path, loss_disc_history, smoothed_loss_disc_history, loss_gen_history, smoothed_loss_gen_history)
if (is_overtraining_gen and consecutive_increases_gen == overtraining_threshold or is_overtraining_disc and consecutive_increases_disc == (overtraining_threshold * 2)):
logger.info(translations["overtraining_find"].format(epoch=epoch, smoothed_value_gen=f"{smoothed_value_gen:.3f}", smoothed_value_disc=f"{smoothed_value_disc:.3f}"))
done = True
else:
logger.info(translations["best_epoch"].format(epoch=epoch, smoothed_value_gen=f"{smoothed_value_gen:.3f}", smoothed_value_disc=f"{smoothed_value_disc:.3f}"))
for file in glob.glob(os.path.join("assets", "weights", f"{model_name}_*e_*s_best_epoch.pth")):
model_del.append(file)
model_add.append(os.path.join("assets", "weights", f"{model_name}_{epoch}e_{global_step}s_best_epoch.pth"))
if epoch >= custom_total_epoch:
logger.info(translations["success_training"].format(epoch=epoch, global_step=global_step, loss_gen_all=round(loss_gen_all.item(), 3)))
logger.info(translations["training_info"].format(lowest_value_rounded=round(float(lowest_value["value"]), 3), lowest_value_epoch=lowest_value['epoch'], lowest_value_step=lowest_value['step']))
pid_file_path = os.path.join(experiment_dir, "config.json")
with open(pid_file_path, "r") as pid_file:
pid_data = json.load(pid_file)
with open(pid_file_path, "w") as pid_file:
pid_data.pop("process_pids", None)
json.dump(pid_data, pid_file, indent=4)
model_add.append(os.path.join("assets", "weights", f"{model_name}_{epoch}e_{global_step}s.pth"))
done = True
for m in model_del:
os.remove(m)
if model_add:
ckpt = (net_g.module.state_dict() if hasattr(net_g, "module") else net_g.state_dict())
for m in model_add:
extract_model(ckpt=ckpt, sr=sample_rate, pitch_guidance=pitch_guidance == True, name=model_name, model_path=m, epoch=epoch, step=global_step, version=version, hps=hps, model_author=model_author, vocoder=vocoder)
lowest_value_rounded = round(float(lowest_value["value"]), 3)
if epoch > 1 and overtraining_detector: logger.info(translations["model_training_info"].format(model_name=model_name, epoch=epoch, global_step=global_step, epoch_recorder=epoch_recorder.record(), lowest_value_rounded=lowest_value_rounded, lowest_value_epoch=lowest_value['epoch'], lowest_value_step=lowest_value['step'], remaining_epochs_gen=(overtraining_threshold - consecutive_increases_gen), remaining_epochs_disc=((overtraining_threshold * 2) - consecutive_increases_disc), smoothed_value_gen=f"{smoothed_value_gen:.3f}", smoothed_value_disc=f"{smoothed_value_disc:.3f}"))
elif epoch > 1 and overtraining_detector == False: logger.info(translations["model_training_info_2"].format(model_name=model_name, epoch=epoch, global_step=global_step, epoch_recorder=epoch_recorder.record(), lowest_value_rounded=lowest_value_rounded, lowest_value_epoch=lowest_value['epoch'], lowest_value_step=lowest_value['step']))
else: logger.info(translations["model_training_info_3"].format(model_name=model_name, epoch=epoch, global_step=global_step, epoch_recorder=epoch_recorder.record()))
last_loss_gen_all = loss_gen_all
if done: os._exit(0)
if __name__ == "__main__":
torch.multiprocessing.set_start_method("spawn")
try:
main()
except Exception as e:
logger.error(f"{translations['training_error']} {e}")
import traceback
logger.debug(traceback.format_exc())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import torch
def init_weights(m, mean=0.0, std=0.01):
if m.__class__.__name__.find("Conv") != -1: m.weight.data.normal_(mean, std)
def get_padding(kernel_size, dilation=1):
return int((kernel_size * dilation - dilation) / 2)
def convert_pad_shape(pad_shape):
return [item for sublist in pad_shape[::-1] for item in sublist]
def slice_segments(x, ids_str, segment_size = 4, dim = 2):
if dim == 2: ret = torch.zeros_like(x[:, :segment_size])
elif dim == 3: ret = torch.zeros_like(x[:, :, :segment_size])
for i in range(x.size(0)):
idx_str = ids_str[i].item()
idx_end = idx_str + segment_size
if dim == 2: ret[i] = x[i, idx_str:idx_end]
else: ret[i] = x[i, :, idx_str:idx_end]
return ret
def rand_slice_segments(x, x_lengths=None, segment_size=4):
b, _, t = x.size()
if x_lengths is None: x_lengths = t
ids_str = (torch.rand([b]).to(device=x.device) * (x_lengths - segment_size + 1)).to(dtype=torch.long)
return slice_segments(x, ids_str, segment_size, dim=3), ids_str
@torch.jit.script
def fused_add_tanh_sigmoid_multiply(input_a, input_b, n_channels):
n_channels_int = n_channels[0]
in_act = input_a + input_b
return torch.tanh(in_act[:, :n_channels_int, :]) * torch.sigmoid(in_act[:, n_channels_int:, :])
def sequence_mask(length, max_length = None):
if max_length is None: max_length = length.max()
return torch.arange(max_length, dtype=length.dtype, device=length.device).unsqueeze(0) < length.unsqueeze(1)
def clip_grad_value(parameters, clip_value, norm_type=2):
if isinstance(parameters, torch.Tensor): parameters = [parameters]
norm_type = float(norm_type)
if clip_value is not None: clip_value = float(clip_value)
total_norm = 0
for p in list(filter(lambda p: p.grad is not None, parameters)):
total_norm += (p.grad.data.norm(norm_type)).item() ** norm_type
if clip_value is not None: p.grad.data.clamp_(min=-clip_value, max=clip_value)
return total_norm ** (1.0 / norm_type)12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import os
import sys
import torch
sys.path.append(os.getcwd())
from .commons import fused_add_tanh_sigmoid_multiply
class WaveNet(torch.nn.Module):
def __init__(self, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=0, p_dropout=0):
super(WaveNet, self).__init__()
assert kernel_size % 2 == 1
self.hidden_channels = hidden_channels
self.kernel_size = (kernel_size,)
self.dilation_rate = dilation_rate
self.n_layers = n_layers
self.gin_channels = gin_channels
self.p_dropout = p_dropout
self.in_layers = torch.nn.ModuleList()
self.res_skip_layers = torch.nn.ModuleList()
self.drop = torch.nn.Dropout(p_dropout)
if gin_channels != 0: self.cond_layer = torch.nn.utils.parametrizations.weight_norm(torch.nn.Conv1d(gin_channels, 2 * hidden_channels * n_layers, 1), name="weight")
dilations = [dilation_rate**i for i in range(n_layers)]
paddings = [(kernel_size * d - d) // 2 for d in dilations]
for i in range(n_layers):
in_layer = torch.nn.Conv1d(hidden_channels, 2 * hidden_channels, kernel_size, dilation=dilations[i], padding=paddings[i])
in_layer = torch.nn.utils.parametrizations.weight_norm(in_layer, name="weight")
self.in_layers.append(in_layer)
res_skip_channels = (hidden_channels if i == n_layers - 1 else 2 * hidden_channels)
res_skip_layer = torch.nn.Conv1d(hidden_channels, res_skip_channels, 1)
res_skip_layer = torch.nn.utils.parametrizations.weight_norm(res_skip_layer, name="weight")
self.res_skip_layers.append(res_skip_layer)
def forward(self, x, x_mask, g=None, **kwargs):
output = torch.zeros_like(x)
n_channels_tensor = torch.IntTensor([self.hidden_channels])
if g is not None: g = self.cond_layer(g)
for i in range(self.n_layers):
x_in = self.in_layers[i](x)
if g is not None:
cond_offset = i * 2 * self.hidden_channels
g_l = g[:, cond_offset : cond_offset + 2 * self.hidden_channels, :]
else: g_l = torch.zeros_like(x_in)
res_skip_acts = self.res_skip_layers[i](self.drop(fused_add_tanh_sigmoid_multiply(x_in, g_l, n_channels_tensor)))
if i < self.n_layers - 1:
x = (x + (res_skip_acts[:, : self.hidden_channels, :])) * x_mask
output = output + res_skip_acts[:, self.hidden_channels :, :]
else: output = output + res_skip_acts
return output * x_mask
def remove_weight_norm(self):
if self.gin_channels != 0: torch.nn.utils.remove_weight_norm(self.cond_layer)
for l in self.in_layers:
torch.nn.utils.remove_weight_norm(l)
for l in self.res_skip_layers:
torch.nn.utils.remove_weight_norm(l)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170import torch
import numpy as np
import torch.nn.functional as F
from torch.nn.utils import remove_weight_norm
from torch.utils.checkpoint import checkpoint
from torch.nn.utils.parametrizations import weight_norm
LRELU_SLOPE = 0.1
class MRFLayer(torch.nn.Module):
def __init__(self, channels, kernel_size, dilation):
super().__init__()
self.conv1 = weight_norm(torch.nn.Conv1d(channels, channels, kernel_size, padding=(kernel_size * dilation - dilation) // 2, dilation=dilation))
self.conv2 = weight_norm(torch.nn.Conv1d(channels, channels, kernel_size, padding=kernel_size // 2, dilation=1))
def forward(self, x):
return x + self.conv2(F.leaky_relu(self.conv1(F.leaky_relu(x, LRELU_SLOPE)), LRELU_SLOPE))
def remove_weight_norm(self):
remove_weight_norm(self.conv1)
remove_weight_norm(self.conv2)
class MRFBlock(torch.nn.Module):
def __init__(self, channels, kernel_size, dilations):
super().__init__()
self.layers = torch.nn.ModuleList()
for dilation in dilations:
self.layers.append(MRFLayer(channels, kernel_size, dilation))
def forward(self, x):
for layer in self.layers:
x = layer(x)
return x
def remove_weight_norm(self):
for layer in self.layers:
layer.remove_weight_norm()
class SineGenerator(torch.nn.Module):
def __init__(self, samp_rate, harmonic_num=0, sine_amp=0.1, noise_std=0.003, voiced_threshold=0):
super(SineGenerator, self).__init__()
self.sine_amp = sine_amp
self.noise_std = noise_std
self.harmonic_num = harmonic_num
self.dim = self.harmonic_num + 1
self.sampling_rate = samp_rate
self.voiced_threshold = voiced_threshold
def _f02uv(self, f0):
return torch.ones_like(f0) * (f0 > self.voiced_threshold)
def _f02sine(self, f0_values):
rad_values = (f0_values / self.sampling_rate) % 1
rand_ini = torch.rand(f0_values.shape[0], f0_values.shape[2], device=f0_values.device)
rand_ini[:, 0] = 0
rad_values[:, 0, :] = rad_values[:, 0, :] + rand_ini
tmp_over_one = torch.cumsum(rad_values, 1) % 1
tmp_over_one_idx = (tmp_over_one[:, 1:, :] - tmp_over_one[:, :-1, :]) < 0
cumsum_shift = torch.zeros_like(rad_values)
cumsum_shift[:, 1:, :] = tmp_over_one_idx * -1.0
return torch.sin(torch.cumsum(rad_values + cumsum_shift, dim=1) * 2 * np.pi)
def forward(self, f0):
with torch.no_grad():
f0_buf = torch.zeros(f0.shape[0], f0.shape[1], self.dim, device=f0.device)
f0_buf[:, :, 0] = f0[:, :, 0]
for idx in np.arange(self.harmonic_num):
f0_buf[:, :, idx + 1] = f0_buf[:, :, 0] * (idx + 2)
sine_waves = self._f02sine(f0_buf) * self.sine_amp
uv = self._f02uv(f0)
sine_waves = sine_waves * uv + ((uv * self.noise_std + (1 - uv) * self.sine_amp / 3) * torch.randn_like(sine_waves))
return sine_waves
class SourceModuleHnNSF(torch.nn.Module):
def __init__(self, sampling_rate, harmonic_num=0, sine_amp=0.1, add_noise_std=0.003, voiced_threshold=0):
super(SourceModuleHnNSF, self).__init__()
self.sine_amp = sine_amp
self.noise_std = add_noise_std
self.l_sin_gen = SineGenerator(sampling_rate, harmonic_num, sine_amp, add_noise_std, voiced_threshold)
self.l_linear = torch.nn.Linear(harmonic_num + 1, 1)
self.l_tanh = torch.nn.Tanh()
def forward(self, x):
return self.l_tanh(self.l_linear(self.l_sin_gen(x).to(dtype=self.l_linear.weight.dtype)))
class HiFiGANMRFGenerator(torch.nn.Module):
def __init__(self, in_channel, upsample_initial_channel, upsample_rates, upsample_kernel_sizes, resblock_kernel_sizes, resblock_dilations, gin_channels, sample_rate, harmonic_num, checkpointing=False):
super().__init__()
self.num_kernels = len(resblock_kernel_sizes)
self.upp = int(np.prod(upsample_rates))
self.f0_upsample = torch.nn.Upsample(scale_factor=self.upp)
self.m_source = SourceModuleHnNSF(sample_rate, harmonic_num)
self.conv_pre = weight_norm(torch.nn.Conv1d(in_channel, upsample_initial_channel, kernel_size=7, stride=1, padding=3))
self.checkpointing = checkpointing
self.upsamples = torch.nn.ModuleList()
self.upsampler = torch.nn.ModuleList()
self.noise_convs = torch.nn.ModuleList()
stride_f0s = [upsample_rates[1] * upsample_rates[2] * upsample_rates[3], upsample_rates[2] * upsample_rates[3], upsample_rates[3], 1]
for i, (u, k) in enumerate(zip(upsample_rates, upsample_kernel_sizes)):
if self.upp == 441:
self.upsampler.append(torch.nn.Upsample(scale_factor=u, mode="linear"))
self.upsamples.append(weight_norm(torch.nn.Conv1d(upsample_initial_channel // (2**i), upsample_initial_channel // (2 ** (i + 1)), kernel_size=1)))
self.noise_convs.append(torch.nn.Conv1d(in_channels=1, out_channels=upsample_initial_channel // (2 ** (i + 1)), kernel_size = 1))
else:
self.upsampler.append(torch.nn.Identity())
self.upsamples.append(weight_norm(torch.nn.ConvTranspose1d(upsample_initial_channel // (2**i), upsample_initial_channel // (2 ** (i + 1)), kernel_size=k, stride=u, padding=(k - u) // 2)))
self.noise_convs.append(torch.nn.Conv1d(1, upsample_initial_channel // (2 ** (i + 1)), kernel_size=stride_f0s[i] * 2 if stride_f0s[i] > 1 else 1, stride=stride_f0s[i], padding=stride_f0s[i] // 2))
self.mrfs = torch.nn.ModuleList()
for i in range(len(self.upsamples)):
channel = upsample_initial_channel // (2 ** (i + 1))
self.mrfs.append(torch.nn.ModuleList([MRFBlock(channel, kernel_size=k, dilations=d) for k, d in zip(resblock_kernel_sizes, resblock_dilations)]))
self.conv_post = weight_norm(torch.nn.Conv1d(channel, 1, kernel_size=7, stride=1, padding=3))
if gin_channels != 0: self.cond = torch.nn.Conv1d(gin_channels, upsample_initial_channel, 1)
def forward(self, x, f0, g = None):
har_source = self.m_source(self.f0_upsample(f0[:, None, :]).transpose(-1, -2)).transpose(-1, -2)
x = self.conv_pre(x)
if g is not None: x += self.cond(g)
for ups, upr, mrf, noise_conv in zip(self.upsamples, self.upsampler, self.mrfs, self.noise_convs):
x = F.leaky_relu(x, LRELU_SLOPE)
if self.training and self.checkpointing:
if self.upp == 441: x = upr(x)
x = checkpoint(ups, x, use_reentrant=False)
else:
if self.upp == 441: x = upr(x)
x = ups(x)
h = noise_conv(har_source)
if self.upp == 441: h = torch.nn.functional.interpolate(h, size=x.shape[-1], mode="linear")
x += h
def mrf_sum(x, layers):
return sum(layer(x) for layer in layers) / self.num_kernels
x = checkpoint(mrf_sum, x, mrf, use_reentrant=False) if self.training and self.checkpointing else mrf_sum(x, mrf)
return torch.tanh(self.conv_post(F.leaky_relu(x)))
def remove_weight_norm(self):
remove_weight_norm(self.conv_pre)
for up in self.upsamples:
remove_weight_norm(up)
for mrf in self.mrfs:
mrf.remove_weight_norm()
remove_weight_norm(self.conv_post)12345678910111213141516171819202122232425262728293031323334353637383940import os
import sys
import onnx
import json
import torch
import onnxsim
import warnings
sys.path.append(os.getcwd())
from main.library.algorithm.synthesizers import SynthesizerONNX
warnings.filterwarnings("ignore")
def onnx_exporter(input_path, output_path, device="cpu"):
cpt = (torch.load(input_path, map_location="cpu") if os.path.isfile(input_path) else None)
cpt["config"][-3] = cpt["weight"]["emb_g.weight"].shape[0]
model_name, model_author, epochs, steps, version, f0, model_hash, vocoder, creation_date = cpt.get("model_name", None), cpt.get("author", None), cpt.get("epoch", None), cpt.get("step", None), cpt.get("version", "v1"), cpt.get("f0", 1), cpt.get("model_hash", None), cpt.get("vocoder", "Default"), cpt.get("creation_date", None)
text_enc_hidden_dim = 768 if version == "v2" else 256
tgt_sr = cpt["config"][-1]
net_g = SynthesizerONNX(*cpt["config"], use_f0=f0, text_enc_hidden_dim=text_enc_hidden_dim, vocoder=vocoder, checkpointing=False)
net_g.load_state_dict(cpt["weight"], strict=False)
if f0:
args = (torch.rand(1, 200, text_enc_hidden_dim).to(device), torch.tensor([200]).long().to(device), torch.LongTensor([0]).to(device), torch.rand(1, 192, 200).to(device), torch.randint(size=(1, 200), low=5, high=255).to(device), torch.rand(1, 200).to(device))
input_names = ["phone", "phone_lengths", "ds", "rnd", "pitch", "pitchf"]
dynamic_axes = {"phone": [1], "rnd": [2], "pitch": [1], "pitchf": [1]}
else:
args = (torch.rand(1, 200, text_enc_hidden_dim).to(device), torch.tensor([200]).long().to(device), torch.LongTensor([0]).to(device), torch.rand(1, 192, 200).to(device))
input_names = ["phone", "phone_lengths", "ds", "rnd"]
dynamic_axes = {"phone": [1], "rnd": [2]}
torch.onnx.export(net_g, args, output_path, do_constant_folding=False, opset_version=17, verbose=False, input_names=input_names, output_names=["audio"], dynamic_axes=dynamic_axes)
model, _ = onnxsim.simplify(output_path)
model.metadata_props.append(onnx.StringStringEntryProto(key="model_info", value=json.dumps({"model_name": model_name, "author": model_author, "epoch": epochs, "step": steps, "version": version, "sr": tgt_sr, "f0": f0, "model_hash": model_hash, "creation_date": creation_date, "vocoder": vocoder, "text_enc_hidden_dim": text_enc_hidden_dim})))
onnx.save(model, output_path)
return output_path123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import os
import sys
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
from torch.utils.checkpoint import checkpoint
from torch.nn.utils.parametrizations import weight_norm
from torch.nn.utils.parametrize import remove_parametrizations
sys.path.append(os.getcwd())
from .commons import get_padding
class ResBlock(nn.Module):
def __init__(self, *, in_channels, out_channels, kernel_size = 7, dilation = (1, 3, 5), leaky_relu_slope = 0.2):
super(ResBlock, self).__init__()
self.leaky_relu_slope = leaky_relu_slope
self.in_channels = in_channels
self.out_channels = out_channels
self.convs1 = nn.ModuleList([weight_norm(nn.Conv1d(in_channels=in_channels if idx == 0 else out_channels, out_channels=out_channels, kernel_size=kernel_size, stride=1, dilation=d, padding=get_padding(kernel_size, d))) for idx, d in enumerate(dilation)])
self.convs1.apply(self.init_weights)
self.convs2 = nn.ModuleList([weight_norm(nn.Conv1d(in_channels=out_channels, out_channels=out_channels, kernel_size=kernel_size, stride=1, dilation=d, padding=get_padding(kernel_size, d))) for _, d in enumerate(dilation)])
self.convs2.apply(self.init_weights)
def forward(self, x):
for idx, (c1, c2) in enumerate(zip(self.convs1, self.convs2)):
xt = c2(F.leaky_relu_(c1(F.leaky_relu(x, self.leaky_relu_slope)), self.leaky_relu_slope))
x = (xt + x) if idx != 0 or self.in_channels == self.out_channels else xt
return x
def remove_parametrizations(self):
for c1, c2 in zip(self.convs1, self.convs2):
remove_parametrizations(c1)
remove_parametrizations(c2)
def init_weights(self, m):
if type(m) == nn.Conv1d:
m.weight.data.normal_(0, 0.01)
m.bias.data.fill_(0.0)
class AdaIN(nn.Module):
def __init__(self, *, channels, leaky_relu_slope = 0.2):
super().__init__()
self.weight = nn.Parameter(torch.ones(channels))
self.activation = nn.LeakyReLU(leaky_relu_slope, inplace=True)
def forward(self, x):
return self.activation(x + (torch.randn_like(x) * self.weight[None, :, None]))
class ParallelResBlock(nn.Module):
def __init__(self, *, in_channels, out_channels, kernel_sizes = (3, 7, 11), dilation = (1, 3, 5), leaky_relu_slope = 0.2):
super().__init__()
self.in_channels = in_channels
self.out_channels = out_channels
self.input_conv = nn.Conv1d(in_channels=in_channels, out_channels=out_channels, kernel_size=7, stride=1, padding=3)
self.blocks = nn.ModuleList([nn.Sequential(AdaIN(channels=out_channels), ResBlock(in_channels=out_channels, out_channels=out_channels, kernel_size=kernel_size, dilation=dilation, leaky_relu_slope=leaky_relu_slope), AdaIN(channels=out_channels)) for kernel_size in kernel_sizes])
def forward(self, x):
x = self.input_conv(x)
return torch.mean(torch.stack([block(x) for block in self.blocks]), dim=0)
def remove_parametrizations(self):
for block in self.blocks:
block[1].remove_parametrizations()
class SineGenerator(nn.Module):
def __init__(self, samp_rate, harmonic_num=0, sine_amp=0.1, noise_std=0.003, voiced_threshold=0):
super(SineGenerator, self).__init__()
self.sine_amp = sine_amp
self.noise_std = noise_std
self.harmonic_num = harmonic_num
self.dim = self.harmonic_num + 1
self.sampling_rate = samp_rate
self.voiced_threshold = voiced_threshold
self.merge = nn.Sequential(nn.Linear(self.dim, 1, bias=False), nn.Tanh())
def _f02uv(self, f0):
return torch.ones_like(f0) * (f0 > self.voiced_threshold)
def _f02sine(self, f0_values):
rad_values = (f0_values / self.sampling_rate) % 1
rand_ini = torch.rand(f0_values.shape[0], f0_values.shape[2], device=f0_values.device)
rand_ini[:, 0] = 0
rad_values[:, 0, :] = rad_values[:, 0, :] + rand_ini
tmp_over_one = torch.cumsum(rad_values, 1) % 1
tmp_over_one_idx = (tmp_over_one[:, 1:, :] - tmp_over_one[:, :-1, :]) < 0
cumsum_shift = torch.zeros_like(rad_values)
cumsum_shift[:, 1:, :] = tmp_over_one_idx * -1.0
return torch.sin(torch.cumsum(rad_values + cumsum_shift, dim=1) * 2 * np.pi)
def forward(self, f0):
with torch.no_grad():
f0_buf = torch.zeros(f0.shape[0], f0.shape[1], self.dim, device=f0.device)
f0_buf[:, :, 0] = f0[:, :, 0]
for idx in np.arange(self.harmonic_num):
f0_buf[:, :, idx + 1] = f0_buf[:, :, 0] * (idx + 2)
sine_waves = self._f02sine(f0_buf) * self.sine_amp
uv = self._f02uv(f0)
sine_waves = sine_waves * uv + ((uv * self.noise_std + (1 - uv) * self.sine_amp / 3) * torch.randn_like(sine_waves))
return self.merge(sine_waves - sine_waves.mean(dim=1, keepdim=True))
class RefineGANGenerator(nn.Module):
def __init__(self, *, sample_rate = 44100, upsample_rates = (8, 8, 2, 2), leaky_relu_slope = 0.2, num_mels = 128, gin_channels = 256, checkpointing = False, upsample_initial_channel = 512):
super().__init__()
self.upsample_rates = upsample_rates
self.checkpointing = checkpointing
self.leaky_relu_slope = leaky_relu_slope
self.upp = int(np.prod(upsample_rates))
assert self.upp == sample_rate // 100
self.m_source = SineGenerator(sample_rate)
self.pre_conv = weight_norm(nn.Conv1d(in_channels=1, out_channels=upsample_initial_channel // 2, kernel_size=7, stride=1, padding=3, bias=False))
channels = upsample_initial_channel
self.downsample_blocks = nn.ModuleList([])
stride_f0s = [upsample_rates[1] * upsample_rates[2] * upsample_rates[3], upsample_rates[2] * upsample_rates[3], upsample_rates[3], 1]
for i, _ in enumerate(upsample_rates):
if self.upp == 441: self.downsample_blocks.append(nn.Conv1d(in_channels=1, out_channels=channels // 2 ** (i + 2), kernel_size = 1))
else: self.downsample_blocks.append(nn.Conv1d(in_channels=1, out_channels=channels // 2 ** (i + 2), kernel_size=stride_f0s[i] * 2 if stride_f0s[i] > 1 else 1, stride=stride_f0s[i], padding=stride_f0s[i] // 2))
self.mel_conv = weight_norm(nn.Conv1d(in_channels=num_mels, out_channels=channels // 2, kernel_size=7, stride=1, padding=3))
if gin_channels != 0: self.cond = nn.Conv1d(256, channels // 2, 1)
self.upsample_blocks = nn.ModuleList([])
self.upsample_conv_blocks = nn.ModuleList([])
self.filters = nn.ModuleList([])
for rate in upsample_rates:
new_channels = channels // 2
self.upsample_blocks.append(nn.Upsample(scale_factor=rate, mode="linear"))
low_pass = nn.Conv1d(channels, channels, kernel_size=15, padding=7, groups=channels, bias=False)
low_pass.weight.data.fill_(1.0 / 15)
self.filters.append(low_pass)
self.upsample_conv_blocks.append(ParallelResBlock(in_channels=channels + channels // 4, out_channels=new_channels, kernel_sizes=(3, 7, 11), dilation=(1, 3, 5), leaky_relu_slope=leaky_relu_slope))
channels = new_channels
self.conv_post = weight_norm(nn.Conv1d(in_channels=channels, out_channels=1, kernel_size=7, stride=1, padding=3))
def forward(self, mel, f0, g = None):
f0 = F.interpolate(f0.unsqueeze(1), size=mel.shape[-1] * self.upp, mode="linear")
har_source = self.m_source(f0.transpose(1, 2)).transpose(1, 2)
x = F.interpolate(self.pre_conv(har_source), size=mel.shape[-1], mode="linear")
mel = self.mel_conv(mel)
if g is not None: mel += self.cond(g)
x = torch.cat([mel, x], dim=1)
for ups, res, down, flt in zip(self.upsample_blocks, self.upsample_conv_blocks, self.downsample_blocks, self.filters):
x = F.leaky_relu_(x, self.leaky_relu_slope)
if self.training and self.checkpointing:
x = checkpoint(flt, checkpoint(ups, x, use_reentrant=False), use_reentrant=False)
h = down(har_source)
if self.upp == 441: h = F.interpolate(h, size=x.shape[-1], mode="linear")
x = checkpoint(res, torch.cat([x, h], dim=1), use_reentrant=False)
else:
x = flt(ups(x))
h = down(har_source)
if self.upp == 441: h = F.interpolate(h, size=x.shape[-1], mode="linear")
x = res(torch.cat([x, h], dim=1))
return torch.tanh_(self.conv_post(F.leaky_relu_(x, self.leaky_relu_slope)))
def remove_parametrizations(self):
remove_parametrizations(self.source_conv)
remove_parametrizations(self.mel_conv)
remove_parametrizations(self.conv_post)
for block in self.downsample_blocks:
block[1].remove_parametrizations()
for block in self.upsample_conv_blocks:
block.remove_parametrizations()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140import os
import sys
import torch
from torch.nn.utils import remove_weight_norm
from torch.nn.utils.parametrizations import weight_norm
sys.path.append(os.getcwd())
from .modules import WaveNet
from .commons import get_padding, init_weights
LRELU_SLOPE = 0.1
def create_conv1d_layer(channels, kernel_size, dilation):
return weight_norm(torch.nn.Conv1d(channels, channels, kernel_size, 1, dilation=dilation, padding=get_padding(kernel_size, dilation)))
def apply_mask(tensor, mask):
return tensor * mask if mask is not None else tensor
class ResBlockBase(torch.nn.Module):
def __init__(self, channels, kernel_size, dilations):
super(ResBlockBase, self).__init__()
self.convs1 = torch.nn.ModuleList([create_conv1d_layer(channels, kernel_size, d) for d in dilations])
self.convs1.apply(init_weights)
self.convs2 = torch.nn.ModuleList([create_conv1d_layer(channels, kernel_size, 1) for _ in dilations])
self.convs2.apply(init_weights)
def forward(self, x, x_mask=None):
for c1, c2 in zip(self.convs1, self.convs2):
x = c2(apply_mask(torch.nn.functional.leaky_relu(c1(apply_mask(torch.nn.functional.leaky_relu(x, LRELU_SLOPE), x_mask)), LRELU_SLOPE), x_mask)) + x
return apply_mask(x, x_mask)
def remove_weight_norm(self):
for conv in self.convs1 + self.convs2:
remove_weight_norm(conv)
class ResBlock(ResBlockBase):
def __init__(self, channels, kernel_size=3, dilation=(1, 3, 5)):
super(ResBlock, self).__init__(channels, kernel_size, dilation)
class Log(torch.nn.Module):
def forward(self, x, x_mask, reverse=False, **kwargs):
if not reverse:
y = torch.log(torch.clamp_min(x, 1e-5)) * x_mask
return y, torch.sum(-y, [1, 2])
else: return torch.exp(x) * x_mask
class Flip(torch.nn.Module):
def forward(self, x, *args, reverse=False, **kwargs):
x = torch.flip(x, [1])
if not reverse: return x, torch.zeros(x.size(0)).to(dtype=x.dtype, device=x.device)
else: return x
class ElementwiseAffine(torch.nn.Module):
def __init__(self, channels):
super().__init__()
self.channels = channels
self.m = torch.nn.Parameter(torch.zeros(channels, 1))
self.logs = torch.nn.Parameter(torch.zeros(channels, 1))
def forward(self, x, x_mask, reverse=False, **kwargs):
if not reverse: return ((self.m + torch.exp(self.logs) * x) * x_mask), torch.sum(self.logs * x_mask, [1, 2])
else: return (x - self.m) * torch.exp(-self.logs) * x_mask
class ResidualCouplingBlock(torch.nn.Module):
def __init__(self, channels, hidden_channels, kernel_size, dilation_rate, n_layers, n_flows=4, gin_channels=0):
super(ResidualCouplingBlock, self).__init__()
self.channels = channels
self.hidden_channels = hidden_channels
self.kernel_size = kernel_size
self.dilation_rate = dilation_rate
self.n_layers = n_layers
self.n_flows = n_flows
self.gin_channels = gin_channels
self.flows = torch.nn.ModuleList()
for _ in range(n_flows):
self.flows.append(ResidualCouplingLayer(channels, hidden_channels, kernel_size, dilation_rate, n_layers, gin_channels=gin_channels, mean_only=True))
self.flows.append(Flip())
def forward(self, x, x_mask, g = None, reverse = False):
if not reverse:
for flow in self.flows:
x, _ = flow(x, x_mask, g=g, reverse=reverse)
else:
for flow in reversed(self.flows):
x = flow.forward(x, x_mask, g=g, reverse=reverse)
return x
def remove_weight_norm(self):
for i in range(self.n_flows):
self.flows[i * 2].remove_weight_norm()
def __prepare_scriptable__(self):
for i in range(self.n_flows):
for hook in self.flows[i * 2]._forward_pre_hooks.values():
if (hook.__module__ == "torch.nn.utils.parametrizations.weight_norm" and hook.__class__.__name__ == "WeightNorm"): torch.nn.utils.remove_weight_norm(self.flows[i * 2])
return self
class ResidualCouplingLayer(torch.nn.Module):
def __init__(self, channels, hidden_channels, kernel_size, dilation_rate, n_layers, p_dropout=0, gin_channels=0, mean_only=False):
assert channels % 2 == 0, "Channels/2"
super().__init__()
self.channels = channels
self.hidden_channels = hidden_channels
self.kernel_size = kernel_size
self.dilation_rate = dilation_rate
self.n_layers = n_layers
self.half_channels = channels // 2
self.mean_only = mean_only
self.pre = torch.nn.Conv1d(self.half_channels, hidden_channels, 1)
self.enc = WaveNet(hidden_channels, kernel_size, dilation_rate, n_layers, p_dropout=p_dropout, gin_channels=gin_channels)
self.post = torch.nn.Conv1d(hidden_channels, self.half_channels * (2 - mean_only), 1)
self.post.weight.data.zero_()
self.post.bias.data.zero_()
def forward(self, x, x_mask, g=None, reverse=False):
x0, x1 = torch.split(x, [self.half_channels] * 2, 1)
stats = self.post(self.enc((self.pre(x0) * x_mask), x_mask, g=g)) * x_mask
if not self.mean_only: m, logs = torch.split(stats, [self.half_channels] * 2, 1)
else:
m = stats
logs = torch.zeros_like(m)
if not reverse: return torch.cat([x0, (m + x1 * torch.exp(logs) * x_mask)], 1), torch.sum(logs, [1, 2])
else: return torch.cat([x0, ((x1 - m) * torch.exp(-logs) * x_mask)], 1)
def remove_weight_norm(self):
self.enc.remove_weight_norm().gitattributes+4
assets/f0/.gitattributesAdded
assets/languages/en-US.jsonAdded+809
assets/languages/vi-VN.jsonAdded+809
assets/logs/mute/f0/mute.wav.npyAdded+3
assets/logs/mute/f0_voiced/mute.wav.npyAdded+3
assets/logs/mute/sliced_audios/mute32000.wavAdded+3
assets/logs/mute/sliced_audios/mute40000.wavAdded+3
assets/logs/mute/sliced_audios/mute44100.wavAdded+3
assets/logs/mute/sliced_audios/mute48000.wavAdded+3
assets/logs/mute/sliced_audios_16k/mute.wavAdded
assets/logs/mute/v1_extracted/mute.npyAdded+3
assets/logs/mute/v2_extracted/mute.npyAdded+3
assets/models/embedders/.gitattributesAdded
assets/models/predictors/.gitattributesAdded
assets/models/pretrained_custom/.gitattributesAdded
assets/models/pretrained_v1/.gitattributesAdded
assets/models/pretrained_v2/.gitattributesAdded
assets/models/uvr5/.gitattributesAdded
assets/presets/.gitattributesAdded
assets/weights/.gitattributesAdded
audios/.gitattributesAdded
dataset/.gitattributesAdded
main/app/app.pyAdded
main/app/tensorboard.pyAdded+30
main/configs/config.jsonAdded+31
main/configs/config.pyAdded+70
main/configs/decrypt.binAdded+3
main/configs/v1/32000.jsonAdded+46
main/configs/v1/40000.jsonAdded+46
main/configs/v1/44100.jsonAdded+46
main/configs/v1/48000.jsonAdded+46
main/configs/v2/32000.jsonAdded+42
main/configs/v2/40000.jsonAdded+42
main/configs/v2/44100.jsonAdded+42
main/configs/v2/48000.jsonAdded+42
main/inference/audio_effects.pyAdded+180
main/inference/convert.pyAdded+680
main/inference/create_dataset.pyAdded+240
main/inference/create_index.pyAdded+100
main/inference/extract.pyAdded+400
main/inference/preprocess.pyAdded+270
main/inference/separator_music.pyAdded+310
main/inference/train.pyAdded+980
main/library/algorithm/commons.pyAdded+60
main/library/algorithm/modules.pyAdded+70
main/library/algorithm/mrf_hifigan.pyAdded+170
main/library/algorithm/onnx_export.pyAdded+40
main/library/algorithm/refinegan.pyAdded+190
main/library/algorithm/residuals.pyAdded+140