Updated to Rafa's latest Voice Changer Colab

This commit is contained in:
Hina 2023-11-03 10:17:57 +08:00
parent 497c7c0678
commit 6d20b3dad2

View File

@ -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 <font color=green>**it's free**</font> 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 <font color=green>**free**</font> 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",
" <!doctype html>\n",
" <html style=\"width:100%;height:100%;overflow:hidden\">\n",
" <head>\n",
" <meta charset=\"utf-8\" />\n",
" <title>Voice Changer Client Demo</title>\n",
" <script defer=\"defer\" src=\"index.js\"></script>\n",
" <style>\n",
" #app {{\n",
" color: {Text_Color};\n",
" background-color: #101010;\n",
" background-image: url(\"{BG_URL}\");\n",
" background-size: cover;\n",
" background-attachment: fixed;\n",
" z-index: 1;\n",
" }}\n",
" </style>\n",
" </head>\n",
" <body style=\"width:100%;height:100%;margin:0\">\n",
" <div id=\"app\" style=\"width:100%;height:100vh\"></div>\n",
" </body>\n",
" </html>\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",
"from IPython.display import clear_output\n",
"\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",
" 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(\"--------- 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",
" print(\"---------------------------------\")\n",
"\n",
"print(PORT)\n",
"\n",
"\n",
"\n",
"threading.Thread(target=iframe_thread, daemon=True, args=(PORT,)).start()\n",
"threading.Thread(target=wait_for_server, daemon=True).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"
]
},
{