model exporter improvements.

This commit is contained in:
Mateo Cedillo
2023-06-11 08:59:27 -05:00
parent 6d2e788885
commit cdda0cac0c

View File

@@ -5,7 +5,7 @@
"colab": { "colab": {
"provenance": [], "provenance": [],
"gpuType": "T4", "gpuType": "T4",
"authorship_tag": "ABX9TyMa35BjcTXUjkrGNFRh72WA", "authorship_tag": "ABX9TyPbfBqlDklgh5td/NJaEFPD",
"include_colab_link": true "include_colab_link": true
}, },
"kernelspec": { "kernelspec": {
@@ -49,15 +49,16 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"#@title Install software\n", "#@title Install software\n",
"#@markdown **Note: Please restart the runtime environment if prompted, and then continue to the next cell.**\n", "\n",
"!git clone https://github.com/rhasspy/piper\n", "print(\"Installing...\")\n",
"!git clone -q https://github.com/rhasspy/piper\n",
"%cd /content/piper/src/python\n", "%cd /content/piper/src/python\n",
"!pip install --upgrade pip\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 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",
"!pip install onnx onnxruntime-gpu\n",
"!bash build_monotonic_align.sh\n", "!bash build_monotonic_align.sh\n",
"!apt-get install espeak-ng\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", " button.on_click(create_model_card)\n",
"\n", "\n",
" display(text_area, button)\n", " display(text_area, button)\n",
"else:\n",
" start_process()\n",
"\n", "\n",
"def start_process():\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", " !python -m piper_train.export_onnx \"/content/project/model.ckpt\" \"{export_voice_path}/{export_voice_name}.onnx\"\n",
" print(\"compressing...\")\n", " print(\"compressing...\")\n",
" !tar -czvf \"{packages_path}/voice-{export_voice_name}.tar.gz\" -C \"{export_voice_path}\" .\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": { "metadata": {
"cellView": "form", "cellView": "form",
@@ -152,9 +158,24 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"#@title Download generated voice package\n", "#@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", " from google.colab import files\n",
"files.download(f\"{packages_path}/voice-{export_voice_name}.tar.gz\")" " 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": { "metadata": {
"cellView": "form", "cellView": "form",