diff --git a/notebooks/piper_model_exporter.ipynb b/notebooks/piper_model_exporter.ipynb index be234d0..35b449f 100644 --- a/notebooks/piper_model_exporter.ipynb +++ b/notebooks/piper_model_exporter.ipynb @@ -5,7 +5,7 @@ "colab": { "provenance": [], "gpuType": "T4", - "authorship_tag": "ABX9TyMa35BjcTXUjkrGNFRh72WA", + "authorship_tag": "ABX9TyPbfBqlDklgh5td/NJaEFPD", "include_colab_link": true }, "kernelspec": { @@ -49,15 +49,16 @@ "outputs": [], "source": [ "#@title Install software\n", - "#@markdown **Note: Please restart the runtime environment if prompted, and then continue to the next cell.**\n", - "!git clone https://github.com/rhasspy/piper\n", + "\n", + "print(\"Installing...\")\n", + "!git clone -q https://github.com/rhasspy/piper\n", "%cd /content/piper/src/python\n", - "!pip install --upgrade pip\n", - "!pip install cython>=0.29.0 espeak-phonemizer>=1.1.0 librosa>=0.9.2 numpy>=1.19.0 pytorch-lightning~=1.7.0 torch~=1.11.0\n", - "!pip install onnx onnxruntime-gpu\n", + "!pip install -q cython>=0.29.0 espeak-phonemizer>=1.1.0 librosa>=0.9.2 numpy>=1.19.0 pytorch-lightning~=1.7.0 torch~=1.11.0\n", + "!pip install -q onnx onnxruntime-gpu\n", "!bash build_monotonic_align.sh\n", "!apt-get install espeak-ng\n", - "!pip install torchtext==0.12.0" + "!pip install -q torchtext==0.12.0\n", + "print(\"Done!\")" ] }, { @@ -135,12 +136,17 @@ " button.on_click(create_model_card)\n", "\n", " display(text_area, button)\n", + "else:\n", + " start_process()\n", "\n", "def start_process():\n", + " if not os.path.exists(\"/content/project/model.ckpt\"):\n", + " raise Exception(\"Could not download model! make sure the file is shareable to everyone\")\n", " !python -m piper_train.export_onnx \"/content/project/model.ckpt\" \"{export_voice_path}/{export_voice_name}.onnx\"\n", " print(\"compressing...\")\n", " !tar -czvf \"{packages_path}/voice-{export_voice_name}.tar.gz\" -C \"{export_voice_path}\" .\n", - " output.eval_js(f'new Audio(\"{guideurl}/success.wav?raw=true\").play()')" + " output.eval_js(f'new Audio(\"{guideurl}/success.wav?raw=true\").play()')\n", + " print(\"Done!\")" ], "metadata": { "cellView": "form", @@ -152,9 +158,24 @@ { "cell_type": "code", "source": [ - "#@title Download generated voice package\n", - "from google.colab import files\n", - "files.download(f\"{packages_path}/voice-{export_voice_name}.tar.gz\")" + "#@title Download/export your generated voice package\n", + "\n", + "#@markdown #### How do you want to export your model?\n", + "export_mode = \"Download the voice package on my device (may take some time)\" #@param [\"Download the voice package on my device (may take some time)\", \"upload it to my Google Drive\"]\n", + "print(\"Exporting package...\")\n", + "if export_mode == \"Download the voice package on my device (may take some time)\":\n", + " from google.colab import files\n", + " files.download(f\"{packages_path}/voice-{export_voice_name}.tar.gz\")\n", + " msg = \"Please wait a moment while the package is being downloaded.\"\n", + "else:\n", + " voicepacks_folder = \"/content/drive/MyDrive/piper voice packages\"\n", + " from google.colab import drive\n", + " drive.mount('/content/drive', force_remount=True)\n", + " if not os.path.exists(voicepacks_folder):\n", + " os.makedirs(voicepacks_folder)\n", + " !cp \"{packages_path}/voice-{export_voice_name}.tar.gz\" \"{voicepacks_folder}\"\n", + " msg = f\"You can find the generated voice packet at: {voicepacks_folder}.\"\n", + "print(f\"Done! {msg}\")" ], "metadata": { "cellView": "form",