Spaces:
Runtime error
Runtime error
File size: 150,717 Bytes
5a030e1 |
1 2 |
{"cells":[{"cell_type":"markdown","metadata":{"id":"2q0l56aFQhAM"},"source":["# Terms of Use\n","\n","### Please solve the authorization problem of the dataset on your own. You shall be solely responsible for any problems caused by the use of non-authorized datasets for training and all consequences thereof.The repository and its maintainer, svc develop team, have nothing to do with the consequences!\n","\n","1. This project is established for academic exchange purposes only and is intended for communication and learning purposes. It is not intended for production environments.\n","2. Any videos based on sovits that are published on video platforms must clearly indicate in the description that they are used for voice changing and specify the input source of the voice or audio, for example, using videos or audios published by others and separating the vocals as input source for conversion, which must provide clear original video or music links. If your own voice or other synthesized voices from other commercial vocal synthesis software are used as the input source for conversion, you must also explain it in the description.\n","3. You shall be solely responsible for any infringement problems caused by the input source. When using other commercial vocal synthesis software as input source, please ensure that you comply with the terms of use of the software. Note that many vocal synthesis engines clearly state in their terms of use that they cannot be used for input source conversion.\n","4. Continuing to use this project is deemed as agreeing to the relevant provisions stated in this repository README. This repository README has the obligation to persuade, and is not responsible for any subsequent problems that may arise.\n","5. If you distribute this repository's code or publish any results produced by this project publicly (including but not limited to video sharing platforms), please indicate the original author and code source (this repository).\n","6. If you use this project for any other plan, please contact and inform the author of this repository in advance. Thank you very much.\n"]},{"cell_type":"markdown","metadata":{"id":"M_RcDbVPhivj"},"source":["## **Note:**\n","## **Make sure there is no a directory named `sovits4data` in your google drive at the first time you use this notebook.**\n","## **It will be created to store some necessary files.** \n","## **For sure you can change it to another directory by modifying `sovits_data_dir` variable.**"]},{"cell_type":"markdown","metadata":{"id":"fHaw6hGEa_Nk"},"source":["# **Initialize environment**"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0gQcIZ8RsOkn"},"outputs":[],"source":["#@title Connect to colab runtime and check GPU\n","\n","#@markdown # Connect to colab runtime and check GPU\n","\n","#@markdown\n","\n","!nvidia-smi"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0YUGpYrXhMck"},"outputs":[],"source":["#@title Clone repository and install requirements\n","\n","#@markdown # Clone repository and install requirements\n","\n","#@markdown\n","\n","#@markdown ### After the execution is completed, the runtime will **automatically restart**\n","\n","#@markdown\n","\n","!git clone https://github.com/svc-develop-team/so-vits-svc -b 4.0\n","!pip uninstall torchdata torchtext\n","!pip install --upgrade pip setuptools numpy numba\n","!pip install pyworld praat-parselmouth fairseq tensorboardX torchcrepe librosa==0.9.1\n","!pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117\n","%cd /content/so-vits-svc\n","!curl -L https://github.com/openvpi/vocoders/releases/download/nsf-hifigan-v1/nsf_hifigan_20221211.zip -o /content/so-vits-svc/nsf_hifigan_20221211.zip\n","!unzip nsf_hifigan_20221211.zip\n","!rm -rf pretrain/nsf_hifigan\n","!mv -v nsf_hifigan pretrain\n","!curl -L https://ibm.ent.box.com/shared/static/z1wgl1stco8ffooyatzdwsqn2psd9lrr -o /content/so-vits-svc/hubert/checkpoint_best_legacy_500.pt\n","exit()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"wmUkpUmfn_Hs"},"outputs":[],"source":["#@title Mount google drive and select which directories to sync with google drive\n","\n","#@markdown # Mount google drive and select which directories to sync with google drive\n","\n","#@markdown\n","\n","from google.colab import drive\n","drive.mount(\"/content/drive\")\n","\n","#@markdown Directory to store **necessary files**, dont miss the slash at the end👇.\n","sovits_data_dir = \"/content/drive/MyDrive/sovits4data/\" #@param {type:\"string\"}\n","#@markdown By default it will create a `sovits4data/` folder in your google drive.\n","RAW_DIR = sovits_data_dir + \"raw/\"\n","RESULTS_DIR = sovits_data_dir + \"results/\"\n","FILELISTS_DIR = sovits_data_dir + \"filelists/\"\n","CONFIGS_DIR = sovits_data_dir + \"configs/\"\n","LOGS_DIR = sovits_data_dir + \"logs/44k/\"\n","\n","#@markdown\n","\n","#@markdown ### These folders will be synced with your google drvie\n","\n","#@markdown ### **Strongly recommend to check all.**\n","\n","#@markdown Sync **input audios** and **output audios**\n","sync_raw_and_results = True #@param {type:\"boolean\"}\n","if sync_raw_and_results:\n"," !mkdir -p {RAW_DIR}\n"," !mkdir -p {RESULTS_DIR}\n"," !rm -rf /content/so-vits-svc/raw\n"," !rm -rf /content/so-vits-svc/results\n"," !ln -s {RAW_DIR} /content/so-vits-svc/raw\n"," !ln -s {RESULTS_DIR} /content/so-vits-svc/results\n","\n","#@markdown Sync **config** and **models**\n","sync_configs_and_logs = True #@param {type:\"boolean\"}\n","if sync_configs_and_logs:\n"," !mkdir -p {FILELISTS_DIR}\n"," !mkdir -p {CONFIGS_DIR}\n"," !mkdir -p {LOGS_DIR}\n"," !rm -rf /content/so-vits-svc/filelists\n"," !rm -rf /content/so-vits-svc/configs\n"," !rm -rf /content/so-vits-svc/logs/44k\n"," !ln -s {FILELISTS_DIR} /content/so-vits-svc/filelists\n"," !ln -s {CONFIGS_DIR} /content/so-vits-svc/configs\n"," !ln -s {LOGS_DIR} /content/so-vits-svc/logs/44k"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"G_PMPCN6wvgZ"},"outputs":[],"source":["#@title Get pretrained model(Optional but strongly recommend).\n","\n","#@markdown # Get pretrained model(Optional but strongly recommend).\n","\n","#@markdown\n","\n","#@markdown - Pre-trained model files: `G_0.pth` `D_0.pth`\n","#@markdown - Place them under /sovits4data/logs/44k/ in your google drive manualy\n","\n","#@markdown Get them from svc-develop-team(TBD) or anywhere else.\n","\n","#@markdown Although the pretrained model generally does not cause any copyright problems, please pay attention to it. For example, ask the author in advance, or the author has indicated the feasible use in the description clearly.\n","\n","!pwd"]},{"cell_type":"markdown","metadata":{"id":"k1qadJBFehMo"},"source":["# **Dataset preprocessing**"]},{"cell_type":"markdown","metadata":{"id":"kBlju6Q3lSM6"},"source":["Pack and upload your raw dataset(dataset_raw/) to your google drive.\n","\n","Makesure the file structure in your zip file looks like this:\n","\n","```\n","YourZIPforSingleSpeakers.zip\n","└───speaker\n"," ├───xxx1-xxx1.wav\n"," ├───...\n"," └───Lxx-0xx8.wav\n","```\n","\n","```\n","YourZIPforMultipleSpeakers.zip\n","├───speaker0\n","│ ├───xxx1-xxx1.wav\n","│ ├───...\n","│ └───Lxx-0xx8.wav\n","└───speaker1\n"," ├───xx2-0xxx2.wav\n"," ├───...\n"," └───xxx7-xxx007.wav\n","```\n","\n","**Even if there is only one speaker, a folder named `{speaker_name}` is needed.**\n","\n","\n","\n",""]},{"cell_type":"code","execution_count":null,"metadata":{"id":"U05CXlAipvJR"},"outputs":[],"source":["#@title Get raw dataset from google drive\n","\n","#@markdown # Get raw dataset from google drive\n","\n","#@markdown\n","\n","#@markdown Directory where **your zip file** located in, dont miss the slash at the end👇.\n","sovits_data_dir = \"/content/drive/MyDrive/sovits4data/\" #@param {type:\"string\"}\n","#@markdown Filename of **your zip file**, do NOT be \"dataset.zip\"\n","zip_filename = \"YourZIPFilenameofRawDataset.zip\" #@param {type:\"string\"}\n","ZIP_PATH = sovits_data_dir + zip_filename\n","\n","!unzip -od /content/so-vits-svc/dataset_raw {ZIP_PATH}"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_ThKTzYs5CfL"},"outputs":[],"source":["#@title Resample to 44100Hz and mono\n","\n","#@markdown # Resample to 44100Hz and mono\n","\n","#@markdown\n","\n","%cd /content/so-vits-svc\n","!python resample.py"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"svITReeL5N8K"},"outputs":[],"source":["#@title Divide filelists and generate config.json\n","\n","#@markdown # Divide filelists and generate config.json\n","\n","#@markdown\n","\n","%cd /content/so-vits-svc\n","!python preprocess_flist_config.py"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"xHUXMi836DMe"},"outputs":[],"source":["#@title Generate hubert and f0\n","\n","#@markdown # Generate hubert and f0\n","\n","#@markdown\n","\n","%cd /content/so-vits-svc\n","!python preprocess_hubert_f0.py"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Wo4OTmTAUXgj"},"outputs":[],"source":["#@title Save the preprocessed dataset to google drive\n","\n","#@markdown # Save the preprocessed dataset to google drive\n","\n","#@markdown\n","\n","#@markdown You can save the dataset and related files to your google drive for the next training\n","\n","#@markdown **Directory for saving**, dont miss the slash at the end👇.\n","sovits_data_dir = \"/content/drive/MyDrive/sovits4data/\" #@param {type:\"string\"}\n","\n","#@markdown There will be a `dataset.zip` contained `dataset/` in your google drive, which is preprocessed data.\n","\n","!mkdir -p {sovits_data_dir}\n","!zip -r dataset.zip /content/so-vits-svc/dataset\n","!cp -vr dataset.zip \"{sovits_data_dir}\""]},{"cell_type":"code","execution_count":null,"metadata":{"id":"P2G6v_6zblWK"},"outputs":[],"source":["#@title Unzip preprocessed dataset from google drive directly if you have preprocessed already.\n","\n","#@markdown # Unzip preprocessed dataset from google drive directly if you have preprocessed already.\n","\n","#@markdown\n","\n","#@markdown Directory where **your preprocessed dataset** located in, dont miss the slash at the end👇.\n","sovits_data_dir = \"/content/drive/MyDrive/sovits4data/\" #@param {type:\"string\"}\n","CONFIG = sovits_data_dir + \"configs/\"\n","FILELISTS = sovits_data_dir + \"filelists/\"\n","DATASET = sovits_data_dir + \"dataset.zip\"\n","\n","!cp -vr {CONFIG} /content/so-vits-svc/\n","!cp -vr {FILELISTS} /content/so-vits-svc/\n","!unzip {DATASET} -d /"]},{"cell_type":"markdown","metadata":{"id":"ENoH-pShel7w"},"source":["# **Trainning**"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"-hEFFTCfZf57"},"outputs":[],"source":["#@title Start training\n","\n","#@markdown # Start training\n","\n","#@markdown If you want to use pre-trained models, upload them to /sovits4data/logs/44k/ in your google drive manualy.\n","\n","#@markdown\n","\n","#@markdown Whether to enable tensorboard\n","tensorboard_on = True #@param {type:\"boolean\"}\n","\n","if tensorboard_on:\n"," %load_ext tensorboard\n"," %tensorboard --logdir logs/44k\n","\n","%cd /content/so-vits-svc\n","!python train.py -c configs/config.json -m 44k"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ZThaMxmIJgWy"},"outputs":[],"source":["#@title Train cluster model (Optional)\n","\n","#@markdown # Train cluster model (Optional)\n","\n","#@markdown #### Details see [README.md#cluster-based-timbre-leakage-control](https://github.com/svc-develop-team/so-vits-svc#cluster-based-timbre-leakage-control)\n","\n","#@markdown\n","\n","%cd /content/so-vits-svc\n","!python cluster/train_cluster.py"]},{"cell_type":"markdown","metadata":{"id":"oCnbX-OT897k"},"source":["# **Inference**\n","### Upload wav files from this notebook\n","### **OR**\n","### Upload to `sovits4data/raw/` in your google drive manualy (should be faster)"]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":75},"executionInfo":{"elapsed":94633,"status":"ok","timestamp":1678591088790,"user":{"displayName":"謬紗特","userId":"09445825975794260265"},"user_tz":-480},"id":"XUsmGkgCMD_Q","outputId":"8bbfde13-030a-4ba0-bbdb-7eb6b89c02b4"},"outputs":[{"data":{"text/html":["\n"," <input type=\"file\" id=\"files-248d7a62-b1f9-4a61-a516-b2dc2fd0d57f\" name=\"files[]\" multiple disabled\n"," style=\"border:none\" />\n"," <output id=\"result-248d7a62-b1f9-4a61-a516-b2dc2fd0d57f\">\n"," Upload widget is only available when the cell has been executed in the\n"," current browser session. Please rerun this cell to enable.\n"," </output>\n"," <script>// Copyright 2017 Google LLC\n","//\n","// Licensed under the Apache License, Version 2.0 (the \"License\");\n","// you may not use this file except in compliance with the License.\n","// You may obtain a copy of the License at\n","//\n","// http://www.apache.org/licenses/LICENSE-2.0\n","//\n","// Unless required by applicable law or agreed to in writing, software\n","// distributed under the License is distributed on an \"AS IS\" BASIS,\n","// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n","// See the License for the specific language governing permissions and\n","// limitations under the License.\n","\n","/**\n"," * @fileoverview Helpers for google.colab Python module.\n"," */\n","(function(scope) {\n","function span(text, styleAttributes = {}) {\n"," const element = document.createElement('span');\n"," element.textContent = text;\n"," for (const key of Object.keys(styleAttributes)) {\n"," element.style[key] = styleAttributes[key];\n"," }\n"," return element;\n","}\n","\n","// Max number of bytes which will be uploaded at a time.\n","const MAX_PAYLOAD_SIZE = 100 * 1024;\n","\n","function _uploadFiles(inputId, outputId) {\n"," const steps = uploadFilesStep(inputId, outputId);\n"," const outputElement = document.getElementById(outputId);\n"," // Cache steps on the outputElement to make it available for the next call\n"," // to uploadFilesContinue from Python.\n"," outputElement.steps = steps;\n","\n"," return _uploadFilesContinue(outputId);\n","}\n","\n","// This is roughly an async generator (not supported in the browser yet),\n","// where there are multiple asynchronous steps and the Python side is going\n","// to poll for completion of each step.\n","// This uses a Promise to block the python side on completion of each step,\n","// then passes the result of the previous step as the input to the next step.\n","function _uploadFilesContinue(outputId) {\n"," const outputElement = document.getElementById(outputId);\n"," const steps = outputElement.steps;\n","\n"," const next = steps.next(outputElement.lastPromiseValue);\n"," return Promise.resolve(next.value.promise).then((value) => {\n"," // Cache the last promise value to make it available to the next\n"," // step of the generator.\n"," outputElement.lastPromiseValue = value;\n"," return next.value.response;\n"," });\n","}\n","\n","/**\n"," * Generator function which is called between each async step of the upload\n"," * process.\n"," * @param {string} inputId Element ID of the input file picker element.\n"," * @param {string} outputId Element ID of the output display.\n"," * @return {!Iterable<!Object>} Iterable of next steps.\n"," */\n","function* uploadFilesStep(inputId, outputId) {\n"," const inputElement = document.getElementById(inputId);\n"," inputElement.disabled = false;\n","\n"," const outputElement = document.getElementById(outputId);\n"," outputElement.innerHTML = '';\n","\n"," const pickedPromise = new Promise((resolve) => {\n"," inputElement.addEventListener('change', (e) => {\n"," resolve(e.target.files);\n"," });\n"," });\n","\n"," const cancel = document.createElement('button');\n"," inputElement.parentElement.appendChild(cancel);\n"," cancel.textContent = 'Cancel upload';\n"," const cancelPromise = new Promise((resolve) => {\n"," cancel.onclick = () => {\n"," resolve(null);\n"," };\n"," });\n","\n"," // Wait for the user to pick the files.\n"," const files = yield {\n"," promise: Promise.race([pickedPromise, cancelPromise]),\n"," response: {\n"," action: 'starting',\n"," }\n"," };\n","\n"," cancel.remove();\n","\n"," // Disable the input element since further picks are not allowed.\n"," inputElement.disabled = true;\n","\n"," if (!files) {\n"," return {\n"," response: {\n"," action: 'complete',\n"," }\n"," };\n"," }\n","\n"," for (const file of files) {\n"," const li = document.createElement('li');\n"," li.append(span(file.name, {fontWeight: 'bold'}));\n"," li.append(span(\n"," `(${file.type || 'n/a'}) - ${file.size} bytes, ` +\n"," `last modified: ${\n"," file.lastModifiedDate ? file.lastModifiedDate.toLocaleDateString() :\n"," 'n/a'} - `));\n"," const percent = span('0% done');\n"," li.appendChild(percent);\n","\n"," outputElement.appendChild(li);\n","\n"," const fileDataPromise = new Promise((resolve) => {\n"," const reader = new FileReader();\n"," reader.onload = (e) => {\n"," resolve(e.target.result);\n"," };\n"," reader.readAsArrayBuffer(file);\n"," });\n"," // Wait for the data to be ready.\n"," let fileData = yield {\n"," promise: fileDataPromise,\n"," response: {\n"," action: 'continue',\n"," }\n"," };\n","\n"," // Use a chunked sending to avoid message size limits. See b/62115660.\n"," let position = 0;\n"," do {\n"," const length = Math.min(fileData.byteLength - position, MAX_PAYLOAD_SIZE);\n"," const chunk = new Uint8Array(fileData, position, length);\n"," position += length;\n","\n"," const base64 = btoa(String.fromCharCode.apply(null, chunk));\n"," yield {\n"," response: {\n"," action: 'append',\n"," file: file.name,\n"," data: base64,\n"," },\n"," };\n","\n"," let percentDone = fileData.byteLength === 0 ?\n"," 100 :\n"," Math.round((position / fileData.byteLength) * 100);\n"," percent.textContent = `${percentDone}% done`;\n","\n"," } while (position < fileData.byteLength);\n"," }\n","\n"," // All done.\n"," yield {\n"," response: {\n"," action: 'complete',\n"," }\n"," };\n","}\n","\n","scope.google = scope.google || {};\n","scope.google.colab = scope.google.colab || {};\n","scope.google.colab._files = {\n"," _uploadFiles,\n"," _uploadFilesContinue,\n","};\n","})(self);\n","</script> "],"text/plain":["<IPython.core.display.HTML object>"]},"metadata":{},"output_type":"display_data"},{"name":"stdout","output_type":"stream","text":["Saving YourWAVFile.wav to YourWAVFile.wav\n"]}],"source":["#@title Upload wav files, the filename should not contain any special symbols like `#` `$` `(` `)`\n","\n","#@markdown # Upload wav files, the filename should not contain any special symbols like `#` `$` `(` `)`\n","\n","#@markdown\n","\n","%cd /content/so-vits-svc\n","%run wav_upload.py --type audio"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"dYnKuKTIj3z1"},"outputs":[],"source":["#@title Start inference (and download)\n","\n","#@markdown # Start inference (and download)\n","\n","#@markdown Parameters see [README.MD#Inference](https://github.com/svc-develop-team/so-vits-svc#-inference)\n","\n","#@markdown\n","\n","wav_filename = \"YourWAVFile.wav\" #@param {type:\"string\"}\n","model_filename = \"G_210000.pth\" #@param {type:\"string\"}\n","model_path = \"/content/so-vits-svc/logs/44k/\" + model_filename\n","speaker = \"YourSpeaker\" #@param {type:\"string\"}\n","trans = \"0\" #@param {type:\"string\"}\n","cluster_infer_ratio = \"0\" #@param {type:\"string\"}\n","auto_predict_f0 = False #@param {type:\"boolean\"}\n","apf = \"\"\n","if auto_predict_f0:\n"," apf = \" -a \"\n","f0_mean_pooling = False #@param {type:\"boolean\"}\n","fmp = \"\"\n","if f0_mean_pooling:\n"," fmp = \" -fmp \"\n","enhance = False #@param {type:\"boolean\"}\n","ehc = \"\"\n","if enhance:\n"," ehc = \" -eh \"\n","#@markdown\n","\n","#@markdown Generally keep default:\n","config_filename = \"config.json\" #@param {type:\"string\"}\n","config_path = \"/content/so-vits-svc/configs/\" + config_filename\n","kmeans_filenname = \"kmeans_10000.pt\" #@param {type:\"string\"}\n","kmeans_path = \"/content/so-vits-svc/logs/44k/\" + kmeans_filenname\n","slice_db = \"-40\" #@param {type:\"string\"}\n","wav_format = \"flac\" #@param {type:\"string\"}\n","wav_output = \"/content/so-vits-svc/results/\" + wav_filename + \"_\" + trans + \"key\" + \"_\" + speaker + \".\" + wav_format\n","\n","%cd /content/so-vits-svc\n","!python inference_main.py -n {wav_filename} -m {model_path} -s {speaker} -t {trans} -cr {cluster_infer_ratio} -c {config_path} -cm {kmeans_path} -sd {slice_db} -wf {wav_format} {apf} {fmp} {ehc}\n","\n","#@markdown\n","\n","#@markdown If you dont want to download from here, uncheck this.\n","download_after_inference = True #@param {type:\"boolean\"}\n","\n","if download_after_inference:\n"," from google.colab import files\n"," files.download(wav_output)"]}],"metadata":{"accelerator":"GPU","colab":{"provenance":[{"file_id":"19fxpo-ZoL_ShEUeZIZi6Di-YioWrEyhR","timestamp":1678516497580},{"file_id":"1rCUOOVG7-XQlVZuWRAj5IpGrMM8t07pE","timestamp":1673086970071},{"file_id":"1Ul5SmzWiSHBj0MaKA0B682C-RZKOycwF","timestamp":1670483515921}]},"gpuClass":"standard","kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
|