Spaces:
Build error
Build error
File size: 3,350 Bytes
46a75d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4d50310e-f094-42e0-af30-1e42b13ceb95",
"metadata": {},
"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 TTS.tts.models.tortoise import TextToSpeech\n",
"from TTS.tts.layers.tortoise.audio_utils 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,
"id": "e126c3c3-d90a-492f-b5bb-0d86587f15cc",
"metadata": {},
"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",
"preset = \"fast\" #@param [\"ultra_fast\", \"fast\", \"standard\", \"high_quality\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9413f553-5bd0-4820-bad4-edd7fd7d2370",
"metadata": {},
"outputs": [],
"source": [
"%ls ../TTS/tts/utils/assets/tortoise/voices/\n",
"import IPython\n",
"IPython.display.Audio(filename='../TTS/tts/utils/assets/tortoise/voices/lj/1.wav')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96a98ae5-313b-40d1-9311-5a785f2c9a4e",
"metadata": {},
"outputs": [],
"source": [
"#@markdown Pick one of the voices from the output above\n",
"voice = 'lj' #@param {type:\"string\"}\n",
"\n",
"#@markdown Load it and send it through Tortoise.\n",
"voice_samples, conditioning_latents = load_voice(voice)\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,
"id": "04e473e5-c489-4a78-aa11-03e89a778ed8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.8.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|