Files
alltalk_tts/googlecolab.ipynb
T
2024-07-27 08:46:29 +01:00

21 KiB

#Install Server Requirements This should be run on a minimum of a T4 runtime, though it will run on a CPU only session, however long TTS generations may time out/error.

This is a work in progress. Known issues:

  • The 1st TTS generation has a brief stutter.
  • RVC is not yet working.
  • Transcoding/ffmpeg isnt working.
  • Things yet to do on selecting your first model and other configuration setups.

If you enable DeepSpeed for XTTS models, DeepSpeed has to compile on the 1st TTS generation which can take about 90 seconds. After that it should be fine.

In [8]:
#@markdown Mounting your Google Drive allows you to drag and drop samples/models via the `drive/Mydrive` path. This allows you<br>
#@markdown to store or use specific audio samples or finetuned models.<br><br>
#@markdown **Audio samples** need to be placed in `alltalk_tts/voices`<br>
#@markdown **XTTS models** need to be placed in `alltalk_tts/models/xtts/{yourmodelfolderhere}`<br>
mount_gdrive = False #@param{type:"boolean"}

if mount_gdrive:
  from google.colab import drive
  drive.mount('/content/drive')
from IPython.display import clear_output
print("*******************************************************************")
print("** Installing server requirements. This will take 5-10 minutes ****")
print("*******************************************************************")
!apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 libaio-dev espeak-ng > '/dev/null' 2>&1
clear_output()
print("************************")
print("*** Cloning AllTalk ****")
print("************************\n")
!git clone -b alltalkbeta https://github.com/erew123/alltalk_tts
clear_output()
print("\n********************************")
print("*** Installing Requirements ****")
print("********************************\n")
!python -m pip install --upgrade "pip<24.1"
!pip install --quiet -r /content/alltalk_tts/system/requirements/requirements_colab.txt
clear_output()
print("\n*****************************")
print("*** Installing DeepSpeed ****")
print("*****************************\n")
!pip install deepspeed
!pip install orjson
!pip install faiss-cpu
!pip install fairseq
clear_output()
print("\n******************************")
print("*** Installing Cloudflare ****")
print("******************************\n")
# Install cloudflare
!wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb > '/dev/null' 2>&1
!apt install ./cloudflared-linux-amd64.deb aria2 > '/dev/null' 2>&1
!rm cloudflared-linux-amd64.deb > '/dev/null' 2>&1
!python -m spacy download en_core_web_md
clear_output()
print("\n***************************")
print("*** Installing Cutlass ****")
print("***************************\n")
# Clone the CUTLASS repository
!git clone https://github.com/NVIDIA/cutlass.git
!export CUTLASSPATH=/content/cutlass
!sudo curl -L https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz -o /usr/local/bin/ffmpeg.tar.xz
clear_output()
%cd /usr/local/bin/
clear_output()
!7z e /usr/local/bin/ffmpeg.tar.xz -y
clear_output()
!7z e /usr/local/bin/ffmpeg.tar -y
clear_output()
!sudo chmod a+rx /usr/local/bin/ffmpeg
clear_output()
!pip uninstall jax -y
clear_output()
print("************************************")
print("** Server requirements installed ***")
print("*** Please proceed to next step ****")
print("************************************\n")
************************************
** Server requirements installed ***
*** Please proceed to next step ****
************************************

Start AllTalk

In [4]:
#@markdown Links to the API and Gradio interface will be shown when AllTalk has loaded in.<br>
#@markdown The API address is what you would use in SillyTavern.<br>
#@markdown Do not start this if you want to run Finetuning.
import re
import time
import json
import threading
import time

def keep_alive():
    while True:
        time.sleep(60)  # Run every 60 seconds (adjust as needed)

keep_alive_thread = threading.Thread(target=keep_alive)
keep_alive_thread.start()

Tunnel = "cloudflare"
host = "127.0.0.1"
ports = [7851, 7852]
tunnel_urls = []

# Starting tunnels for each port.
for port in ports:
    if Tunnel == "cloudflare":
        !nohup cloudflared tunnel --url http://{host}:{port} > lt_{port}.log 2>&1 &
    else:
        !nohup npx lt -p {port} > lt_{port}.log 2>&1 &

# Wait a couple of seconds for the tunnels to initialize.
time.sleep(10)

# Extract URLs for each tunnel.
for port in ports:
    log_file = f'lt_{port}.log'
    with open(log_file, 'r') as testwritefile:
        log_content = testwritefile.read()

        # Use regular expressions to find the URL.
        if Tunnel == "cloudflare":
            url_match = re.search(r'(https://[-a-z0-9]+\.trycloudflare\.com)', log_content)
        else:
            url_match = re.search(r'your url is: (https?://\S+)', log_content)

        if url_match:
            tunnel_url = url_match.group(1)
            tunnel_urls.append(tunnel_url)
        else:
            print(f"URL for port {port} not found.")

# Save the tunnel URLs to a JSON file.
try:
    # Try to open the JSON file for reading.
    with open('/content/alltalk_tts/googlecolab.json', 'r') as f:
        data = json.load(f)
except FileNotFoundError:
    # If the file doesn't exist, create an empty dictionary.
    data = {}

data['google_ip_address'] = tunnel_urls

# Write the modified data (or newly created data) back to the file.
with open('/content/alltalk_tts/googlecolab.json', 'w') as f:
    json.dump(data, f)

host = "0.0.0.0"

if Tunnel == "localtunnel":
    print("Before you copy the link above click on it and copy that ip:")
    !curl ipv4.icanhazip.com

# Start API server.
!python /content/alltalk_tts/script.py
[AllTalk TTS]     _    _ _ _____     _ _       _____ _____ ____  
[AllTalk TTS]    / \  | | |_   _|_ _| | | __  |_   _|_   _/ ___| 
[AllTalk TTS]   / _ \ | | | | |/ _` | | |/ /    | |   | | \___ \ 
[AllTalk TTS]  / ___ \| | | | | (_| | |   <     | |   | |  ___) |
[AllTalk TTS] /_/   \_\_|_| |_|\__,_|_|_|\_\    |_|   |_| |____/ 
[AllTalk TTS]
[AllTalk TTS] Config file update: No Updates required
[AllTalk TTS] Start-up Mode     : Standalone mode
[AllTalk TTS]
[AllTalk TTS] This is the first time startup. Please download a start TTS model.
[AllTalk TTS]
[AllTalk TTS]    Available First Time Start-up models:
[AllTalk TTS]
[AllTalk TTS]    1. piper - piper
[AllTalk TTS]    2. vits - tts_models--en--vctk--vits
[AllTalk TTS]    3. xtts - xttsv2_2.0.3
[AllTalk TTS]    4. I have my own models already
[AllTalk TTS]
[AllTalk TTS]    In 60 seconds a Piper model will be downloaded automatically.
[AllTalk TTS]
[AllTalk TTS]    Enter your choice 1-4:  
[AllTalk TTS]
[AllTalk TTS] No input received. Proceeding with the default model (piper).
/content/alltalk_tts/models/piper/en_US-ljspeech-high.onnx: 100% 114M/114M [00:01<00:00, 80.8MiB/s]
/content/alltalk_tts/models/piper/en_US-ljspeech-high.onnx.json: 100% 4.97k/4.97k [00:00<00:00, 14.9MiB/s]
[AllTalk TTS] piper model downloaded and configuration updated successfully.
[AllTalk TTS]
[AllTalk TTS] If you have you have UPGRADED from v1 ensure you have re-installed
[AllTalk TTS] the requirements. Otherwise you will get failures and errors!
[AllTalk TTS] On Linux ignore the 'sparse_attn requires a torch version' and
[AllTalk TTS] 'using untested triton version' messages.
[AllTalk TTS]
[AllTalk TTS] WAV file deletion : Disabled
[AllTalk TTS] Github updated    : 1st July 2024 at 08:57
[AllTalk TTS]
[AllTalk TTS] Google Colab Detected
[AllTalk TTS]
[AllTalk ENG] Transcoding       : ffmpeg found
 [WARNING]  Please specify the CUTLASS repo directory as environment variable $CUTLASS_PATH
 [WARNING]  NVIDIA Inference is only supported on Ampere and newer architectures
 [WARNING]  sparse_attn requires a torch version >= 1.5 and < 2.0 but detected 2.3
 [WARNING]  using untested triton version (2.3.1), only 1.0.0 is known to be compatible
[AllTalk ENG] DeepSpeed version : 0.14.4 
[AllTalk ENG] Python Version    : 3.10.12
[AllTalk ENG] PyTorch Version   : 2.3.1+cu121
[AllTalk ENG] CUDA Version      : 12.1
[AllTalk ENG]
[AllTalk ENG] Model/Engine : Piper Ready
[AllTalk ENG] Load time : 0.00 seconds.
[AllTalk TTS]
[AllTalk TTS] API Address : https://refresh-jackson-firefox-elementary.trycloudflare.com
[AllTalk TTS] Gradio Light: https://lawsuit-effectively-assessing-z.trycloudflare.com
[AllTalk TTS] Gradio Dark : https://lawsuit-effectively-assessing-z.trycloudflare.com?__theme=dark
[AllTalk TTS]
themes/theme_schema@0.0.1.json: 100% 13.1k/13.1k [00:00<00:00, 45.7MB/s]
[AllTalk TTS] Please use Ctrl+C when exiting AllTalk otherwise a
[AllTalk TTS] subprocess may continue running in the background.
[AllTalk TTS]
[AllTalk TTS] AllTalk Server Ready
Downloading LICENSE.txt...
100% 4.01k/4.01k [00:00<00:00, 11.6MiB/s]
Downloading README.md...
100% 4.26k/4.26k [00:00<00:00, 13.0MiB/s]
Downloading config.json...
100% 4.37k/4.37k [00:00<00:00, 12.1MiB/s]
Downloading model.pth...
100% 1.87G/1.87G [00:30<00:00, 61.2MiB/s]
Downloading dvae.pth...
100% 211M/211M [00:04<00:00, 50.7MiB/s]
Downloading mel_stats.pth...
100% 1.07k/1.07k [00:00<00:00, 2.90MiB/s]
Downloading speakers_xtts.pth...
100% 7.75M/7.75M [00:00<00:00, 77.9MiB/s]
Downloading vocab.json...
100% 361k/361k [00:00<00:00, 26.4MiB/s]
[AllTalk Shutdown] Received Ctrl+C, terminating subprocess. Kill your Python processes if this fails to exit.
[AllTalk Shutdown] Received Ctrl+C, terminating subprocess. Kill your Python processes if this fails to exit.
^C

Start Finetuning

In [7]:
#@markdown Starts the Finetuning application for XTTS models.<br><br>
#@markdown You can either run the `Start AllTalk` to download the base XTTS model(s) for finetuning. Or you can use the folder icon on the left hand<br>
#@markdown side of the screen and upload an XTTS model that you want to finetune. If you are manually uploading a model, you would place your model<br>
#@markdown files in `models/xtts/{yourmodelfolderhere}` and you will need all the models files in that folder `config.json, dvae.pth, mel_stats.pth,`<br>
#@markdown `model.pth, speakers_xtts.pth, vocab.json`. Without 1x model available, Finetuning will not start.<br><br>
#@markdown Likewise you can download your finetuned model from there, OR copy it to your Google Drive after finetuning, for later use in AllTalk.<br><br>
#@markdown To access the Finetuning Gradio interface, connect to the `Google Colab Finetuning url` when Finetuning has started.<br>
import re
import time
import json
import threading
import time

def keep_alive():
    while True:
        time.sleep(60)  # Run every 60 seconds (adjust as needed)

keep_alive_thread = threading.Thread(target=keep_alive)
keep_alive_thread.start()

Tunnel = "cloudflare"
host = "127.0.0.1"
ports = [7052]
tunnel_urls = []

# Starting tunnels for each port.
for port in ports:
    if Tunnel == "cloudflare":
        !nohup cloudflared tunnel --url http://{host}:{port} > lt_{port}.log 2>&1 &
    else:
        !nohup npx lt -p {port} > lt_{port}.log 2>&1 &

# Wait a couple of seconds for the tunnels to initialize.
time.sleep(10)

# Extract URLs for each tunnel.
for port in ports:
    log_file = f'lt_{port}.log'
    with open(log_file, 'r') as testwritefile:
        log_content = testwritefile.read()

        # Use regular expressions to find the URL.
        if Tunnel == "cloudflare":
            url_match = re.search(r'(https://[-a-z0-9]+\.trycloudflare\.com)', log_content)
        else:
            url_match = re.search(r'your url is: (https?://\S+)', log_content)

        if url_match:
            tunnel_url = url_match.group(1)
            tunnel_urls.append(tunnel_url)
            print(f"Google Colab Finetuning url: {tunnel_url}\n")
            print(f"********************************************************************")
            print(f"**** Use the above URL to connect to Finetuning on Google Colab ****")
            print(f"********************************************************************")
            print(f"************* Now starting the Finetuning Application **************")
            print(f"********************************************************************\n")
        else:
            print(f"URL for port {port} not found.")

# Save the tunnel URLs to a JSON file.
try:
    # Try to open the JSON file for reading.
    with open('/content/alltalk_tts/googlecolab.json', 'r') as f:
        data = json.load(f)
except FileNotFoundError:
    # If the file doesn't exist, create an empty dictionary.
    data = {}

data['google_ip_address'] = tunnel_urls

# Write the modified data (or newly created data) back to the file.
with open('/content/alltalk_tts/googlecolab.json', 'w') as f:
    json.dump(data, f)

host = "0.0.0.0"

if Tunnel == "localtunnel":
    print("Before you copy the link above click on it and copy that ip:")
    !curl ipv4.icanhazip.com

# Start API server.
!python /content/alltalk_tts/finetune.py
Google Colab Finetuning url: https://assistance-amazing-periods-payday.trycloudflare.com

********************************************************************
**** Use the above URL to connect to Finetuning on Google Colab ****
********************************************************************

[FINETUNE] HTTP Request: GET https://checkip.amazonaws.com/ "HTTP/1.1 200 "
[FINETUNE] HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
Running on local URL:  http://127.0.0.1:7052
[FINETUNE] HTTP Request: GET http://127.0.0.1:7052/startup-events "HTTP/1.1 200 OK"
[FINETUNE] HTTP Request: HEAD http://127.0.0.1:7052/ "HTTP/1.1 200 OK"

To create a public link, set `share=True` in `launch()`.
[FINETUNE] Received interrupt signal. Cleaning up and exiting...