From 6d20b3dad2525857df4a585cd2e420a2fe223042 Mon Sep 17 00:00:00 2001 From: Hina <79749008+hinabl@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:17:57 +0800 Subject: [PATCH] Updated to Rafa's latest Voice Changer Colab --- ...fied_Realtime_Voice_Changer_on_Colab.ipynb | 181 +++++++----------- 1 file changed, 65 insertions(+), 116 deletions(-) diff --git a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb index b2660d8f..61a27ce0 100644 --- a/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb +++ b/Hina_Modified_Realtime_Voice_Changer_on_Colab.ipynb @@ -84,8 +84,9 @@ }, "outputs": [], "source": [ + "#=================Updated=================\n", "# @title **[1]** Clone repository and install dependencies\n", - "# @markdown This first step will download the latest version of Voice Changer and install the dependencies. **It will take around 2 minutes to complete.**\n", + "# @markdown This first step will download the latest version of Voice Changer and install the dependencies. **It can take some time to complete.**\n", "import os\n", "import time\n", "import subprocess\n", @@ -94,12 +95,12 @@ "import base64\n", "import codecs\n", "\n", - "from IPython.display import clear_output, Javascript\n", "\n", "externalgit=codecs.decode('uggcf://tvguho.pbz/j-bxnqn/ibvpr-punatre.tvg','rot_13')\n", "rvctimer=codecs.decode('uggcf://tvguho.pbz/uvanoy/eipgvzre.tvg','rot_13')\n", - "pathloc=codecs.decode('ibvpr-punatre','rot_13')\n", - "!git clone --depth 1 $externalgit &> /dev/null\n", + "pathloc=codecs.decode('/pbagrag/ibvpr-punatre','rot_13')\n", + "\n", + "from IPython.display import clear_output, Javascript\n", "\n", "def update_timer_and_print():\n", " global timer\n", @@ -113,42 +114,30 @@ "timer = 0\n", "threading.Thread(target=update_timer_and_print, daemon=True).start()\n", "\n", - "# os.system('cls')\n", - "clear_output()\n", - "!rm -rf rvctimer\n", - "!git clone --depth 1 $rvctimer\n", - "\n", + "!pip install colorama --quiet\n", + "from colorama import Fore, Style\n", "\n", + "print(f\"{Fore.CYAN}> Cloning the repository...{Style.RESET_ALL}\")\n", + "!git clone --depth 1 $externalgit &> /dev/null\n", + "print(f\"{Fore.GREEN}> Successfully cloned the repository!{Style.RESET_ALL}\")\n", "%cd $pathloc/server/\n", "\n", - "print(\"\\033[92mSuccessfully cloned the repository\")\n", - "\n", - "\n", - "\n", - "!apt-get install libportaudio2 &> /dev/null --quiet\n", - "# !pip install pyworld onnxruntime-gpu uvicorn faiss-gpu fairseq jedi google-colab moviepy decorator==4.4.2 sounddevice pyngrok --quiet\n", - "\n", - "# Install dependencies that are missing from requirements.txt and pyngrok\n", - "!pip install faiss-gpu fairseq pyngrok --quiet\n", - "!pip install pyworld --no-build-isolation --quiet\n", - "\n", - "\n", - "print(\"\\033[92mInstalling Requirements!\")\n", - "clear_output()\n", + "print(f\"{Fore.CYAN}> Installing libportaudio2...{Style.RESET_ALL}\")\n", + "!apt-get -y install libportaudio2 -qq\n", "\n", "!sed -i '/torch==/d' requirements.txt\n", "!sed -i '/torchaudio==/d' requirements.txt\n", "!sed -i '/numpy==/d' requirements.txt\n", "\n", "\n", - "!pip install -r requirements.txt --no-build-isolation --quiet\n", - "# Maybe install Tensor packages?\n", - "#!pip install torch-tensorrt\n", - "#!pip install TensorRT\n", - "print(\"\\033[92mSuccessfully installed all packages!\")\n", - "# os.system('cls')\n", - "clear_output()\n", - "print(\"\\033[92mFinished, please continue to the next cell\")" + "print(f\"{Fore.CYAN}> Installing pre-dependencies...{Style.RESET_ALL}\")\n", + "# Install dependencies that are missing from requirements.txt and pyngrok\n", + "!pip install faiss-gpu fairseq pyngrok --quiet\n", + "!pip install pyworld --no-build-isolation --quiet\n", + "print(f\"{Fore.CYAN}> Installing dependencies from requirements.txt...{Style.RESET_ALL}\")\n", + "!pip install -r requirements.txt --quiet\n", + "\n", + "print(f\"{Fore.GREEN}> Successfully installed all packages!{Style.RESET_ALL}\")" ] }, { @@ -354,108 +343,67 @@ }, "outputs": [], "source": [ - "# @title **[2]** Start Server **using ngrok** (Recommended | **need a ngrok account**)\n", + "\n", + "#=======================Updated=========================\n", + "\n", + "# @title Start Server **using ngrok**\n", "# @markdown This cell will start the server, the first time that you run it will download the models, so it can take a while (~1-2 minutes)\n", "\n", "# @markdown ---\n", - "# @markdown You'll need a ngrok account, but **it's free**!\n", + "# @markdown You'll need a ngrok account, but **it's free** and easy to create!\n", "# @markdown ---\n", - "# @markdown **1** - Create a **free** account at [ngrok](https://dashboard.ngrok.com/signup)\\\n", - "# @markdown **2** - If you didn't logged in with Google or Github, you will need to **verify your e-mail**!\\\n", - "# @markdown **3** - Click [this link](https://dashboard.ngrok.com/get-started/your-authtoken) to get your auth token, copy it and place it here:\n", - "from pyngrok import conf, ngrok\n", - "\n", - "f0_det= \"rmvpe_onnx\" #@param [\"rmvpe_onnx\",\"rvc\"]\n", - "Token = 'Token_Here' # @param {type:\"string\"}\n", - "# @markdown **4** - Still need further tests, but maybe region can help a bit on latency?\\\n", + "# @markdown **1** - Create a **free** account at [ngrok](https://dashboard.ngrok.com/signup) or **login with Google/Github account**\\\n", + "# @markdown **2** - If you didn't logged in with Google/Github, you will need to **verify your e-mail**!\\\n", + "# @markdown **3** - Click [this link](https://dashboard.ngrok.com/get-started/your-authtoken) to get your auth token, and place it here:\n", + "Token = '' # @param {type:\"string\"}\n", + "# @markdown **4** - *(optional)* Change to a region near to you or keep at United States if increase latency\\\n", "# @markdown `Default Region: us - United States (Ohio)`\n", - "Region = \"us - United States (Ohio)\" # @param [\"ap - Asia/Pacific (Singapore)\", \"au - Australia (Sydney)\",\"eu - Europe (Frankfurt)\", \"in - India (Mumbai)\",\"jp - Japan (Tokyo)\",\"sa - South America (Sao Paulo)\", \"us - United States (Ohio)\"]\n", - "MyConfig = conf.PyngrokConfig()\n", + "Region = \"jp - Japan (Tokyo)\" # @param [\"ap - Asia/Pacific (Singapore)\", \"au - Australia (Sydney)\",\"eu - Europe (Frankfurt)\", \"in - India (Mumbai)\",\"jp - Japan (Tokyo)\",\"sa - South America (Sao Paulo)\", \"us - United States (Ohio)\"]\n", "\n", + "#@markdown **5** - *(optional)* Other options:\n", + "ClearConsole = True # @param {type:\"boolean\"}\n", + "\n", + "# ---------------------------------\n", + "# DO NOT TOUCH ANYTHING DOWN BELOW!\n", + "# ---------------------------------\n", + "\n", + "%cd $pathloc/server//server\n", + "\n", + "from pyngrok import conf, ngrok\n", + "MyConfig = conf.PyngrokConfig()\n", "MyConfig.auth_token = Token\n", "MyConfig.region = Region[0:2]\n", - "\n", - "conf.get_default().authtoken = Token\n", - "conf.get_default().region = Region[0:2]\n", - "\n", + "#conf.get_default().authtoken = Token\n", + "#conf.get_default().region = Region\n", "conf.set_default(MyConfig);\n", "\n", - "# @markdown ---\n", - "# @markdown If you want to automatically clear the output when the server loads, check this option.\n", - "Clear_Output = True # @param {type:\"boolean\"}\n", - "\n", - "#@markdown ---\n", - "#@markdown If you want to use a custom background for the voice changer\n", - "Use_Custom_BG=False #@param{type:\"boolean\"}\n", - "BG_URL=\"https://w.wallha.com/ws/14/cMmpo5vn.jpg\" #@param{type:\"string\"}\n", - "#@markdown Text colors can be hex ``#101010`` or name of color ``black`` (css)\n", - "Text_Color=\"green\" #@param{type:\"string\"}\n", - "if Use_Custom_BG==True:\n", - " if BG_URL==\"\":\n", - " !cp -f rvctimer/index.html $pathloc/client/demo/dist/\n", - " else:\n", - " html_template = f'''\n", - " \n", - " \n", - " \n", - " \n", - " Voice Changer Client Demo\n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \n", - " '''\n", - " with open('index.html', 'w') as file:\n", - " file.write(html_template)\n", - " !mkdir ../client/demo/dist/temp/\n", - " !mv ../client/demo/dist/index.html ../client/demo/dist/temp/index.html\n", - " !mv index.html ../client/demo/dist/\n", - "else:\n", - " !cp -f ../client/demo/dist/temp/index.html ../client/demo/dist/index.html\n", - "\n", - "mainpy=codecs.decode('ZZIPFreireFVB.cl','rot_13')\n", - "\n", - "import portpicker, socket, urllib.request\n", - "PORT = portpicker.pick_unused_port()\n", + "import subprocess, threading, time, socket, urllib.request\n", + "PORT = 8000\n", "\n", "from pyngrok import ngrok\n", - "# Edited ⏬⏬\n", "ngrokConnection = ngrok.connect(PORT)\n", "public_url = ngrokConnection.public_url\n", "\n", - "def iframe_thread(port):\n", - " while True:\n", - " time.sleep(0.5)\n", - " sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n", - " result = sock.connect_ex(('127.0.0.1', port))\n", - " if result == 0:\n", - " break\n", - " sock.close()\n", - " clear_output()\n", - " print(\"------- SERVER READY! -------\")\n", - " print(\"Your server is available at:\")\n", - " print(public_url)\n", - " print(\"-----------------------------\")\n", - " # display(Javascript('window.open(\"{url}\", \\'_blank\\');'.format(url=public_url)))\n", + "from IPython.display import clear_output\n", "\n", - "print(PORT)\n", + "def wait_for_server():\n", + " while True:\n", + " time.sleep(0.5)\n", + " sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n", + " result = sock.connect_ex(('127.0.0.1', PORT))\n", + " if result == 0:\n", + " break\n", + " sock.close()\n", + " if ClearConsole:\n", + " clear_output()\n", + " print(\"--------- SERVER READY! ---------\")\n", + " print(\"Your server is available at:\")\n", + " print(public_url)\n", + " print(\"---------------------------------\")\n", "\n", + "threading.Thread(target=wait_for_server, daemon=True).start()\n", "\n", - "\n", - "threading.Thread(target=iframe_thread, daemon=True, args=(PORT,)).start()\n", - "\n", + "mainpy=codecs.decode('ZZIPFreireFVB.cl','rot_13')\n", "\n", "!python3 $mainpy \\\n", " -p {PORT} \\\n", @@ -472,7 +420,8 @@ " --rmvpe pretrain/rmvpe.pt \\\n", " --model_dir model_dir \\\n", " --samples samples.json\n", - "\n" + "\n", + "ngrok.disconnect(ngrokConnection.public_url)\n" ] }, {