Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
350 changes: 350 additions & 0 deletions notebooks/Piper_Training.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,350 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4",
"authorship_tag": "ABX9TyMLK8+OPF/URaEggfgBAHja",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/natlamir/piper1-gpl/blob/add-colab-training-notebook/notebooks/Piper_Training.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"0) Colab runtime + GPU check"
],
"metadata": {
"id": "ulTkpdiGQjI4"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Y37QtlLmPuqT"
},
"outputs": [],
"source": [
"# Check GPU\n",
"import torch, platform, sys\n",
"print(\"Python:\", sys.version.split()[0])\n",
"print(\"PyTorch:\", torch.__version__)\n",
"print(\"CUDA available:\", torch.cuda.is_available())\n",
"!nvidia-smi"
]
},
{
"cell_type": "markdown",
"source": [
"1) System packages (incl. eSpeak dev)"
],
"metadata": {
"id": "tRWDRJUpQrfw"
}
},
{
"cell_type": "code",
"source": [
"!sudo apt-get update -y\n",
"!sudo apt-get install -y build-essential cmake ninja-build espeak-ng espeak-ng-data libespeak-ng-dev pkg-config ffmpeg\n",
"!pkg-config --modversion espeak-ng"
],
"metadata": {
"id": "aN5lcQRZQs3D"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"2) Clone repo fresh"
],
"metadata": {
"id": "J_MRPygaQ1cQ"
}
},
{
"cell_type": "code",
"source": [
"%cd /content\n",
"!rm -rf piper1-gpl\n",
"!git clone https://github.com/OHF-voice/piper1-gpl.git\n",
"%cd piper1-gpl\n",
"!pwd"
],
"metadata": {
"id": "w-0x1IWPQ7UB"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"3) Python deps (editable install, no venv in Colab)"
],
"metadata": {
"id": "k_qVUXtoRArT"
}
},
{
"cell_type": "code",
"source": [
"!python3 -m pip install --upgrade pip setuptools wheel\n",
"!python3 -m pip install -e \".[train]\""
],
"metadata": {
"id": "L9ARM5C9RDZ_"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"4) Build the Cython extension used for alignment"
],
"metadata": {
"id": "OXkhMJRkRUGk"
}
},
{
"cell_type": "code",
"source": [
"%cd /content/piper1-gpl\n",
"!chmod +x ./build_monotonic_align.sh\n",
"!./build_monotonic_align.sh"
],
"metadata": {
"id": "EMQF3quvRVe7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"5) Dev build (repo mode)"
],
"metadata": {
"id": "f8P9iQhjRa81"
}
},
{
"cell_type": "code",
"source": [
"!python3 -m pip install --upgrade pip setuptools wheel scikit-build cmake ninja"
],
"metadata": {
"id": "ZIcRcqt6p3kM"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"%cd /content/piper1-gpl\n",
"!python3 setup.py build_ext --inplace -v"
],
"metadata": {
"id": "bTNUkZKmRcJb"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"6) (Optional) Mount Google Drive for datasets and outputs"
],
"metadata": {
"id": "xsmEOdPpRjPo"
}
},
{
"cell_type": "code",
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"metadata": {
"id": "S82oT9EaRlR0"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"7) Set paths and training hyperparams"
],
"metadata": {
"id": "bRewWxitSmSr"
}
},
{
"cell_type": "code",
"source": [
"from pathlib import Path\n",
"\n",
"# ==== CHANGE THESE ====\n",
"VOICE_NAME = \"my_colab_voice\"\n",
"ESPEAK_VOICE = \"en-us\" # run `!espeak-ng --voices` to see options\n",
"SAMPLE_RATE_HZ = 22050\n",
"BATCH_SIZE = 32 # drop to 8 or 4 if you OOM\n",
"\n",
"DATA_ROOT = Path(\"/content/drive/MyDrive/tts_data/myvoice\")\n",
"AUDIO_DIR = DATA_ROOT / \"wavs\"\n",
"CSV_PATH = DATA_ROOT / \"metadata.csv\"\n",
"\n",
"CACHE_DIR = Path(\"/content/piper_cache\")\n",
"CONFIG_PATH = DATA_ROOT / f\"{VOICE_NAME}.json\"\n",
"\n",
"# Optional: start from an existing checkpoint to speed up & stabilize training\n",
"# Get a .ckpt from https://huggingface.co/datasets/rhasspy/piper-checkpoints (medium quality recommended)\n",
"CKPT_PATH = \"\" # e.g., \"/content/drive/MyDrive/piper_ckpts/en_US-lessac-medium.ckpt\"\n",
"\n",
"# Make sure dirs exist\n",
"CACHE_DIR.mkdir(parents=True, exist_ok=True)\n",
"print(\"CSV exists:\", CSV_PATH.exists())\n",
"print(\"Audio dir exists:\", AUDIO_DIR.exists())\n",
"print(\"Cache dir:\", CACHE_DIR)\n",
"print(\"Config will be written to:\", CONFIG_PATH)"
],
"metadata": {
"id": "nyXNxSWFSq2u"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"8) Quick sanity checks"
],
"metadata": {
"id": "YZqVTzcDSwRV"
}
},
{
"cell_type": "code",
"source": [
"!espeak-ng --voices | head -n 20"
],
"metadata": {
"id": "PPTTUbbxSydH"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import pandas as pd, io, os, textwrap\n",
"\n",
"csv_path = str(CSV_PATH)\n",
"if os.path.exists(csv_path):\n",
" # Read as pipe-delimited, two columns\n",
" try:\n",
" df = pd.read_csv(csv_path, sep=\"|\", header=None, names=[\"audio\",\"text\"])\n",
" print(df.head())\n",
" # Check a few audio files exist\n",
" missing = [a for a in df[\"audio\"].head(5) if not (AUDIO_DIR/str(a)).exists()]\n",
" print(\"Missing among first 5:\", missing)\n",
" except Exception as e:\n",
" print(\"CSV read error:\", e)\n",
"else:\n",
" print(\"CSV not found at:\", csv_path)"
],
"metadata": {
"id": "JJImgsKzS1pk"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"9) Kick off training"
],
"metadata": {
"id": "jiggGLHzTxGI"
}
},
{
"cell_type": "code",
"source": [
"!python3 -m piper.train fit \\\n",
" --data.voice_name \"my_colab_voice\" \\\n",
" --data.csv_path \"/content/drive/MyDrive/tts_data/myvoice/metadata.csv\" \\\n",
" --data.audio_dir \"/content/drive/MyDrive/tts_data/myvoice/wavs\" \\\n",
" --model.sample_rate 22050 \\\n",
" --data.espeak_voice \"en-us\" \\\n",
" --data.cache_dir \"/content/piper_cache\" \\\n",
" --data.config_path \"/content/drive/MyDrive/tts_data/myvoice/my_colab_voice.json\" \\\n",
" --data.batch_size 8 \\\n",
" --ckpt_path \"https://huggingface.co/datasets/rhasspy/piper-checkpoints/resolve/main/en/en_US/lessac/medium/epoch%3D2164-step%3D1355540.ckpt\""
],
"metadata": {
"id": "PZigA3tIUSeh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"10. Export to onnx"
],
"metadata": {
"id": "bSUfANcq7jUX"
}
},
{
"cell_type": "code",
"source": [
"!python3 -m piper.train.export_onnx \\\n",
" --checkpoint \"/content/piper1-gpl/lightning_logs/version_2/checkpoints/epoch=2174-step=2680.ckpt\" \\\n",
" --output-file \"/content/model.onnx\""
],
"metadata": {
"id": "oX63f32Q7m98"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!cp /content/drive/MyDrive/tts_data/myvoice/my_colab_voice.json /content/model.onnx.json"
],
"metadata": {
"id": "pOqvuxqM8UrN"
},
"execution_count": null,
"outputs": []
}
]
}