{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "_pIZ3ZXNp7cf" }, "source": [ "Welcome to Tortoise! 🐢🐢🐢🐢\n", "\n", "Before you begin, I **strongly** recommend you turn on a GPU runtime.\n", "\n", "There's a reason this is called \"Tortoise\" - this model takes up to a minute to perform inference for a single sentence on a GPU. Expect waits on the order of hours on a CPU." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 1000 }, "id": "JrK20I32grP6", "outputId": "9711e23e-3bfc-4cb0-c030-25a1cf460972" }, "outputs": [], "source": [ "!git clone https://github.com/DjKesu/tortoise-tts-fast-cloning.git\n", "%cd tortoise-tts-fast-cloning\n", "!pip3 install -r requirements.txt --no-deps\n", "!pip3 install -e .\n", "!pip3 install git+https://github.com/152334H/BigVGAN.git" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip uninstall transformers\n", "!pip install transformers==4.29.2" ] }, { "cell_type": "markdown", "metadata": { "id": "zRW4p3ftjZ3Y" }, "source": [ "## **Restart the runtime!**\n", "## Ctrl+M for Colab" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Gen09NM4hONQ" }, "outputs": [], "source": [ "#@title # Setup\n", "# Imports used through the rest of the notebook.\n", "import torch\n", "import torchaudio\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "\n", "import IPython\n", "\n", "from tortoise.api import TextToSpeech\n", "from tortoise.utils.audio import load_audio, load_voice, load_voices\n", "\n", "# This will download all the models used by Tortoise from the HuggingFace hub.\n", "tts = TextToSpeech()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "bt_aoxONjfL2" }, "outputs": [], "source": [ "# This is the text that will be spoken.\n", "text = \"Joining two modalities results in a surprising increase in generalization! What would happen if we combined them all?\" #@param {type:\"string\"}\n", "#@markdown Show code for multiline text input\n", "# Here's something for the poetically inclined.. (set text=)\n", "\"\"\"\n", "Then took the other, as just as fair,\n", "And having perhaps the better claim,\n", "Because it was grassy and wanted wear;\n", "Though as for that the passing there\n", "Had worn them really about the same,\"\"\"\n", "\n", "# Pick a \"preset mode\" to determine quality. Options: {\"ultra_fast\", \"fast\" (default), \"standard\", \"high_quality\"}. See docs in api.py\n", "# added very_fast preset param option, since it involves resulution with dpm++2m, expected to give best,fastest results\n", "preset = \"ultra_fast\" #@param [\"ultra_fast\", \"fast\", \"standard\", \"high_quality\", \"very_fast\"]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 211 }, "id": "SSleVnRAiEE2", "outputId": "45b950c7-5c39-4075-bb34-0a76bf19e1bc" }, "outputs": [], "source": [ "#@markdown Tortoise will attempt to mimic voices you provide. It comes pre-packaged\n", "#@markdown with some voices you might recognize.\n", "\n", "#@markdown Let's list all the voices available. These are just some random clips I've gathered\n", "#@markdown from the internet as well as a few voices from the training dataset.\n", "#@markdown Feel free to add your own clips to the voices/ folder.\n", "#@markdown Currently stored my voice clips under voices/krish/ and displaying the random rumblings of my voice.\n", "#@markdown each cell is the samples used, skip unless you wanna listen to them\n", "%cd tortoise-tts-fast-cloning\n", "%ls tortoise/voices/krish\n", "import IPython\n", "IPython.display.Audio('tortoise/voices/krish/1.wav')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%cd tortoise-tts-fast-cloning\n", "%ls tortoise/voices/krish\n", "import IPython\n", "IPython.display.Audio('tortoise/voices/krish/2.wav')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%cd tortoise-tts-fast-cloning\n", "%ls tortoise/voices/krish\n", "import IPython\n", "IPython.display.Audio('tortoise/voices/krish/3.wav')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%cd tortoise-tts-fast-cloning\n", "%ls tortoise/voices/krish\n", "import IPython\n", "IPython.display.Audio('tortoise/voices/krish/4.wav')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "colab": { "base_uri": "https://localhost:8080/", "height": 192 }, "id": "KEXOKjIvn6NW", "outputId": "90c803f3-0b9b-4f24-ccbc-d3f3dcbde48c" }, "outputs": [], "source": [ "#@markdown Pick one of the voices from the output above\n", "voice = 'krish' #@param {type:\"string\"}\n", "\n", "#@markdown Load it and send it through Tortoise.\n", "voice_samples, conditioning_latents = load_voice(voice)\n", "print(voice_samples)\n", "# conditioning_latents = tts.get_conditioning_latents(\n", "# voice_samples,\n", "# return_mels=False, # Set to True if you want mel spectrograms to be returned\n", "# latent_averaging_mode=1, # Choose the mode (0, 1, or 2) as needed\n", "# original_tortoise=False, # Set to True or False as needed\n", "# )\n", "gen = tts.tts_with_preset(text, voice_samples=voice_samples, conditioning_latents=conditioning_latents, \n", " preset=preset)\n", "torchaudio.save('generated.wav', gen.squeeze(0).cpu(), 24000)\n", "IPython.display.Audio('generated.wav')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 41 }, "id": "VQgw3KeV8Yqb", "outputId": "13db770e-3fcc-4b27-ab78-07a603a299d9" }, "outputs": [], "source": [ "#@markdown Optionally, upload use your own voice by running the next two cells. Change the name of the voice to a voice you want before running\n", "#@markdown you upload at least 2 audio clips. They must be a WAV file, 6-10 seconds long.\n", "CUSTOM_VOICE_NAME = \"custom\"\n", "\n", "import os\n", "from google.colab import files\n", "\n", "custom_voice_folder = f\"tortoise/voices/{CUSTOM_VOICE_NAME}\"\n", "os.makedirs(custom_voice_folder)\n", "for i, file_data in enumerate(files.upload().values()):\n", " with open(os.path.join(custom_voice_folder, f'{i}.wav'), 'wb') as f:\n", " f.write(file_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "jJnJwv3R9uWT" }, "outputs": [], "source": [ "# Generate speech with the custotm voice.\n", "voice_samples, conditioning_latents = load_voices(CUSTOM_VOICE_NAME)\n", "gen = tts.tts_with_preset(text, voice_samples=voice_samples, conditioning_latents=conditioning_latents, \n", " preset=preset)\n", "torchaudio.save(f'generated-{CUSTOM_VOICE_NAME}.wav', gen.squeeze(0).cpu(), 24000)\n", "IPython.display.Audio(f'generated-{CUSTOM_VOICE_NAME}.wav')" ] } ], "metadata": { "accelerator": "GPU", "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 4 }