Ethan0927 commited on
Commit
6d5b1d0
·
1 Parent(s): d74bb8f

Create setup.py

Browse files
Files changed (1) hide show
  1. setup.py +185 -0
setup.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "name": "tortoise-tts.ipynb",
7
+ "provenance": [],
8
+ "collapsed_sections": []
9
+ },
10
+ "kernelspec": {
11
+ "name": "python3",
12
+ "display_name": "Python 3"
13
+ },
14
+ "language_info": {
15
+ "name": "python"
16
+ },
17
+ "accelerator": "GPU"
18
+ },
19
+ "cells": [
20
+ {
21
+ "cell_type": "markdown",
22
+ "source": [
23
+ "Welcome to Tortoise! 🐢🐢🐢🐢\n",
24
+ "\n",
25
+ "Before you begin, I **strongly** recommend you turn on a GPU runtime.\n",
26
+ "\n",
27
+ "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."
28
+ ],
29
+ "metadata": {
30
+ "id": "_pIZ3ZXNp7cf"
31
+ }
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "metadata": {
37
+ "id": "JrK20I32grP6"
38
+ },
39
+ "outputs": [],
40
+ "source": [
41
+ "!git clone https://github.com/neonbjb/tortoise-tts.git\n",
42
+ "%cd tortoise-tts\n",
43
+ "!pip3 install -r requirements.txt\n",
44
+ "!python3 setup.py install"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "source": [
50
+ "# Imports used through the rest of the notebook.\n",
51
+ "import torch\n",
52
+ "import torchaudio\n",
53
+ "import torch.nn as nn\n",
54
+ "import torch.nn.functional as F\n",
55
+ "\n",
56
+ "import IPython\n",
57
+ "\n",
58
+ "from tortoise.api import TextToSpeech\n",
59
+ "from tortoise.utils.audio import load_audio, load_voice, load_voices\n",
60
+ "\n",
61
+ "# This will download all the models used by Tortoise from the HF hub.\n",
62
+ "tts = TextToSpeech()"
63
+ ],
64
+ "metadata": {
65
+ "id": "Gen09NM4hONQ"
66
+ },
67
+ "execution_count": null,
68
+ "outputs": []
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "source": [
73
+ "# This is the text that will be spoken.\n",
74
+ "text = \"Joining two modalities results in a surprising increase in generalization! What would happen if we combined them all?\"\n",
75
+ "\n",
76
+ "# Here's something for the poetically inclined.. (set text=)\n",
77
+ "\"\"\"\n",
78
+ "Then took the other, as just as fair,\n",
79
+ "And having perhaps the better claim,\n",
80
+ "Because it was grassy and wanted wear;\n",
81
+ "Though as for that the passing there\n",
82
+ "Had worn them really about the same,\"\"\"\n",
83
+ "\n",
84
+ "# Pick a \"preset mode\" to determine quality. Options: {\"ultra_fast\", \"fast\" (default), \"standard\", \"high_quality\"}. See docs in api.py\n",
85
+ "preset = \"fast\""
86
+ ],
87
+ "metadata": {
88
+ "id": "bt_aoxONjfL2"
89
+ },
90
+ "execution_count": null,
91
+ "outputs": []
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "source": [
96
+ "# Tortoise will attempt to mimic voices you provide. It comes pre-packaged\n",
97
+ "# with some voices you might recognize.\n",
98
+ "\n",
99
+ "# Let's list all the voices available. These are just some random clips I've gathered\n",
100
+ "# from the internet as well as a few voices from the training dataset.\n",
101
+ "# Feel free to add your own clips to the voices/ folder.\n",
102
+ "%ls tortoise/voices\n",
103
+ "\n",
104
+ "IPython.display.Audio('tortoise/voices/tom/1.wav')"
105
+ ],
106
+ "metadata": {
107
+ "id": "SSleVnRAiEE2"
108
+ },
109
+ "execution_count": null,
110
+ "outputs": []
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "source": [
115
+ "# Pick one of the voices from the output above\n",
116
+ "voice = 'tom'\n",
117
+ "\n",
118
+ "# Load it and send it through Tortoise.\n",
119
+ "voice_samples, conditioning_latents = load_voice(voice)\n",
120
+ "gen = tts.tts_with_preset(text, voice_samples=voice_samples, conditioning_latents=conditioning_latents, \n",
121
+ " preset=preset)\n",
122
+ "torchaudio.save('generated.wav', gen.squeeze(0).cpu(), 24000)\n",
123
+ "IPython.display.Audio('generated.wav')"
124
+ ],
125
+ "metadata": {
126
+ "id": "KEXOKjIvn6NW"
127
+ },
128
+ "execution_count": null,
129
+ "outputs": []
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "source": [
134
+ "# Tortoise can also generate speech using a random voice. The voice changes each time you execute this!\n",
135
+ "# (Note: random voices can be prone to strange utterances)\n",
136
+ "gen = tts.tts_with_preset(text, voice_samples=None, conditioning_latents=None, preset=preset)\n",
137
+ "torchaudio.save('generated.wav', gen.squeeze(0).cpu(), 24000)\n",
138
+ "IPython.display.Audio('generated.wav')"
139
+ ],
140
+ "metadata": {
141
+ "id": "16Xs2SSC3BXa"
142
+ },
143
+ "execution_count": null,
144
+ "outputs": []
145
+ },
146
+ {
147
+ "cell_type": "code",
148
+ "source": [
149
+ "# You can also combine conditioning voices. Combining voices produces a new voice\n",
150
+ "# with traits from all the parents.\n",
151
+ "#\n",
152
+ "# Lets see what it would sound like if Picard and Kirk had a kid with a penchant for philosophy:\n",
153
+ "voice_samples, conditioning_latents = load_voices(['pat', 'william'])\n",
154
+ "\n",
155
+ "gen = tts.tts_with_preset(\"They used to say that if man was meant to fly, he’d have wings. But he did fly. He discovered he had to.\", \n",
156
+ " voice_samples=None, conditioning_latents=None, preset=preset)\n",
157
+ "torchaudio.save('captain_kirkard.wav', gen.squeeze(0).cpu(), 24000)\n",
158
+ "IPython.display.Audio('captain_kirkard.wav')"
159
+ ],
160
+ "metadata": {
161
+ "id": "fYTk8KUezUr5"
162
+ },
163
+ "execution_count": null,
164
+ "outputs": []
165
+ },
166
+ {
167
+ "cell_type": "code",
168
+ "source": [
169
+ "del tts # Will break other cells, but necessary to conserve RAM if you want to run this cell.\n",
170
+ "\n",
171
+ "# Tortoise comes with some scripts that does a lot of the lifting for you. For example,\n",
172
+ "# read.py will read a text file for you.\n",
173
+ "!python3 tortoise/read.py --voice=train_atkins --textfile=tortoise/data/riding_hood.txt --preset=ultra_fast --output_path=.\n",
174
+ "\n",
175
+ "IPython.display.Audio('train_atkins/combined.wav')\n",
176
+ "# This will take awhile.."
177
+ ],
178
+ "metadata": {
179
+ "id": "t66yqWgu68KL"
180
+ },
181
+ "execution_count": null,
182
+ "outputs": []
183
+ }
184
+ ]
185
+ }