diff --git a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb index ebbab41f..dbcc76ff 100644 --- a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb +++ b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb @@ -1,15 +1,5 @@ { "cells": [ -{ - "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, { "cell_type": "markdown", "metadata": { @@ -147,21 +137,22 @@ "#@markdown ---\n", "import os\n", "import json\n", + "from IPython.display import Image\n", "\n", "\n", "#@markdown #Model Number `(Default is 0)` you can add multiple models as long as you change the number!\n", - "model_number = \"0\" #@param ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199']\n", + "model_number = \"6\" #@param ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '162', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199']\n", "\n", "!rm -rf model_dir/$model_number\n", "#@markdown ---\n", "#@markdown #**[Optional]** Add an icon to the model `(can be any image/leave empty for no image)`\n", - "icon_link = \"https://cdn.donmai.us/original/8a/92/8a924397e9aac922e94bdc1f28ff978a.jpg\" #@param {type:\"string\"}\n", + "icon_link = \"https://cdn.discordapp.com/attachments/1144453160912572506/1144453161210351697/mika.png?ex=65163190&is=6514e010&hm=6cfc987d42e448b2912f5225e2c865df92d688c8dc46a135c2cca32682a3f3ea&\" #@param {type:\"string\"}\n", "#@markdown ---\n", "icon_link = '\"'+icon_link+'\"'\n", "!mkdir model_dir\n", "!mkdir model_dir/$model_number\n", "#@markdown #Put your model's download link here `(must be a zip file)`\n", - "model_link = \"https://huggingface.co/HinaBl/Akatsuki/resolve/main/akatsuki_200epoch.zip\" #@param {type:\"string\"}\n", + "model_link = \"https://huggingface.co/Kit-Lemonfoot/kitlemonfoot_rvc_models/resolve/main/Mika%20Melatika%20(Speaking)(KitLemonfoot).zip\" #@param {type:\"string\"}\n", "model_link = '\"'+model_link+'\"'\n", "!curl -L $model_link > model.zip\n", "\n", @@ -171,6 +162,7 @@ " iconFile = \"icon.png\"\n", " !curl -L $icon_link > model_dir/$model_number/icon.png\n", "else:\n", + " iconFile = \"\"\n", " print(\"icon_link is empty, so no icon file will be downloaded.\")\n", "#@markdown ---\n", "\n", @@ -190,32 +182,83 @@ "Tune = 12 #@param {type:\"slider\",min:-50,max:50,step:1}\n", "Index = 0 #@param {type:\"slider\",min:0,max:1,step:0.1}\n", "#@markdown ---\n", - "#@markdown #Parameter Option `(Ignore if theres a Parameter File)`\n", - "Slot_Index = -1 #@param [-1,0,1] {type:\"raw\"}\n", - "Sampling_Rate = 48000 #@param [32000,40000,48000] {type:\"raw\"}\n", "\n", "# @markdown #**[Optional]** Parameter file for your voice model\n", "#@markdown _(must be named params.json)_ (Leave Empty for Default)\n", "param_link = \"\" #@param {type:\"string\"}\n", "if param_link == \"\":\n", - " model_dir = \"model_dir/\"+model_number+\"/\"\n", + " from voice_changer.RVC.RVCModelSlotGenerator import RVCModelSlotGenerator\n", + " from voice_changer.VoiceChangerParamsManager import VoiceChangerParamsManager\n", + " from voice_changer.utils.LoadModelParams import LoadModelParamFile, LoadModelParams\n", + " from voice_changer.utils.VoiceChangerParams import VoiceChangerParams\n", "\n", - " # Find the .pth and .index files in the model_dir/0 directory\n", - " pth_files = [f for f in os.listdir(model_dir) if f.endswith(\".pth\")]\n", - " index_files = [f for f in os.listdir(model_dir) if f.endswith(\".index\")]\n", + " model_dir1 = \"model_dir/\"+model_number+\"/\"\n", "\n", - " if pth_files and index_files:\n", - " # Take the first .pth and .index file as model and index names\n", + " is_pth = True # Set this to True if you want to search for .pth files, or False for .onnx files\n", + " file_extension = \".pth\" if is_pth else \".onnx\"\n", + "\n", + " # pth_files = [f for f in os.listdir(model_dir1) if f.endswith(file_extension)]\n", + "\n", + " pth_files = [f for f in os.listdir(model_dir1) if f.endswith(\".pth\") or f.endswith(\".onnx\")]\n", + " print(pth_files)\n", + " index_files = [f for f in os.listdir(model_dir1) if f.endswith(\".index\")]\n", + "\n", + "\n", + "\n", + "\n", + " if pth_files:\n", " model_name = pth_files[0].replace(\".pth\", \"\")\n", + "\n", + " else:\n", + " model_name = \"Null\"\n", + " if index_files:\n", " index_name = index_files[0].replace(\".index\", \"\")\n", " else:\n", - " # Set default values if no .pth and .index files are found\n", - " model_name = \"Null\"\n", - " index_name = \"Null\"\n", + " index_name = \"\"\n", "\n", - " # Define the content for params.json\n", + " original_string = str(pth_files)\n", + " string_pth_files = original_string[2:-2]\n", + " print(\"IM A STRING\"+original_string)\n", + "\n", + " print(model_name)\n", + " voiceChangerParams = VoiceChangerParams(\n", + " model_dir=\"./model_dir/\"+model_number,\n", + " content_vec_500=\"\",\n", + " content_vec_500_onnx=\"\",\n", + " content_vec_500_onnx_on=\"\",\n", + " hubert_base=\"\",\n", + " hubert_base_jp=\"\",\n", + " hubert_soft=\"\",\n", + " nsf_hifigan=\"\",\n", + " crepe_onnx_full=\"\",\n", + " crepe_onnx_tiny=\"\",\n", + " rmvpe=\"\",\n", + " rmvpe_onnx=\"\",\n", + " sample_mode=\"\"\n", + " )\n", + " vcparams = VoiceChangerParamsManager.get_instance()\n", + " vcparams.setParams(voiceChangerParams)\n", + "\n", + " file = LoadModelParamFile(\n", + " name=string_pth_files,\n", + " kind=\"rvcModel\",\n", + " dir=\"\",\n", + " )\n", + "\n", + " loadParam = LoadModelParams(\n", + " voiceChangerType=\"RVC\",\n", + " files=[file],\n", + " slot=\"\",\n", + " isSampleMode=False,\n", + " sampleId=\"\",\n", + " params={},\n", + " )\n", + " slotInfo = RVCModelSlotGenerator.loadModel(loadParam)\n", + " print(slotInfo.samplingRate)\n", + "\n", + "#----------------Make the Json File-----------\n", " params_content = {\n", - " \"slotIndex\": Slot_Index,\n", + " \"slotIndex\": -1,\n", " \"voiceChangerType\": \"RVC\",\n", " \"name\": model_name,\n", " \"description\": \"\",\n", @@ -225,14 +268,14 @@ " \"speakers\": {\n", " \"0\": \"target\"\n", " },\n", - " \"modelFile\": f\"{model_name}.pth\",\n", + " \"modelFile\": string_pth_files,\n", " \"indexFile\": f\"{index_name}.index\",\n", " \"defaultTune\": Tune,\n", " \"defaultIndexRatio\": Index,\n", " \"defaultProtect\": 0.5,\n", " \"isONNX\": False,\n", " \"modelType\": \"pyTorchRVCv2\",\n", - " \"samplingRate\": Sampling_Rate,\n", + " \"samplingRate\": slotInfo.samplingRate,\n", " \"f0\": True,\n", " \"embChannels\": 768,\n", " \"embOutputLayer\": 12,\n", @@ -243,16 +286,18 @@ " }\n", "\n", " # Write the content to params.json\n", - " with open(f\"{model_dir}/params.json\", \"w\") as param_file:\n", + " with open(f\"{model_dir1}/params.json\", \"w\") as param_file:\n", " json.dump(params_content, param_file)\n", "\n", + "\n", "# !unzip model.zip -d model_dir/0/\n", "clear_output()\n", - "print(\"\\033[92mModel with the name of \"+model_name+\" has been Imported!\")\n" + "print(\"\\033[92mModel with the name of \"+model_name+\" has been Imported to slot \"+model_number)\n", + "Image(url=icon_link)" ], "metadata": { - "cellView": "form", - "id": "_ZtbKUVUgN3G" + "id": "_ZtbKUVUgN3G", + "cellView": "form" }, "execution_count": null, "outputs": [] @@ -270,7 +315,8 @@ "print(\"\\033[92mSuccessfully removed Model is slot \"+Delete_Slot)\n" ], "metadata": { - "id": "P9g6rG1-KUwt" + "id": "P9g6rG1-KUwt", + "cellView": "form" }, "execution_count": null, "outputs": [] @@ -279,7 +325,8 @@ "cell_type": "code", "execution_count": null, "metadata": { - "id": "lLWQuUd7WW9U" + "id": "lLWQuUd7WW9U", + "cellView": "form" }, "outputs": [], "source": [ @@ -440,4 +487,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file