Matthew Kutarna commited on
Commit
6bab300
1 Parent(s): a87d216

Exploration (#3)

Browse files

* Added MIT license file

* Added dummy test file for CI

* Added gitignore file and exploration notebook

* Added notebook for epub import, html stripping

* Work in exploration notebook

* Deleted corrupted notebooks

* Deleted corrupted notebook

* Notebook work on proof of concept

* Testing end to end conversion

* Testing Nvidia pre-trained model

* Nvidia exmaples added

* Epub to partial audio files achieved

* Text tokenization added, further tweaks needed

* Whole book conversion

* Output files added, first chapter combined

* Proof of concept notebook created

* Cleaned up repo, annotated notebooks

* Epub import now truncates sentence length

* Pydub audio testing

* Silero model testing

* Silero GPU testing

* Silero CPU testing

* Fixed corrupted notebook

* Fixed corrupted notebooks

* Proof of concept working, removed outputs

* Notebook clean-up on Silero proof of concept

* Flake8 check

* Notebook output cleanup, PR change requests

.gitignore CHANGED
@@ -8,6 +8,7 @@ token
8
  docs/
9
  conda/
10
  tmp/
 
11
 
12
  tags
13
  *~
@@ -124,4 +125,4 @@ venv.bak/
124
  .mypy_cache/
125
 
126
  # Mac stuff
127
- .DS_Store
 
8
  docs/
9
  conda/
10
  tmp/
11
+ notesbooks/outputs/
12
 
13
  tags
14
  *~
 
125
  .mypy_cache/
126
 
127
  # Mac stuff
128
+ .DS_Store
notebooks/audiobook_gen_silero.ipynb ADDED
@@ -0,0 +1,694 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "\n",
9
+ "# Audiobook Generator - Proof of Concept Notebook\n",
10
+ "\n",
11
+ "This notebook is intended to be a proof of concept for the end-to-end work of generating an audiobook file from an ebook. This includes converting the .epub book files into raw python text strings, splitting into items and sentences, then tokenizing and batching them to run through the Silero text-to-speech (TTS) implementation.\n",
12
+ "\n",
13
+ "*Updated: September 2, 2022*\n",
14
+ "\n",
15
+ "---\n",
16
+ "\n",
17
+ "### Overview\n",
18
+ "\n",
19
+ "1. Setup\n",
20
+ " - Needed libraries and packages\n",
21
+ " - Variables\n",
22
+ " - Silero model selection\n",
23
+ "2. Ebook Import\n",
24
+ " - Target file selection\n",
25
+ " - File (.epub) import\n",
26
+ " - String parsing\n",
27
+ " - String length wrapping\n",
28
+ "3. Text-to-Speech\n",
29
+ " - Silero implementation\n",
30
+ " - Results\n",
31
+ "\n",
32
+ "---"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "markdown",
37
+ "metadata": {},
38
+ "source": [
39
+ "### Step 1 - Setup\n",
40
+ "\n",
41
+ "This proof-of-concept relies on PyTorch and TorchAudio for its implementation. OmegaConf is used to support providing the latest model from Silero in a consistent manner. A seed is created, and used for all random function that are needed.\n",
42
+ "\n",
43
+ "We will also use the TQDM package to provide progress bars while running the proof-of-concept within this notebook."
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 1,
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "import os\n",
53
+ "import torch\n",
54
+ "import torchaudio\n",
55
+ "from omegaconf import OmegaConf\n",
56
+ "from tqdm.notebook import tqdm\n",
57
+ "\n",
58
+ "torch.hub.download_url_to_file('https://raw.githubusercontent.com/snakers4/silero-models/master/models.yml',\n",
59
+ " 'latest_silero_models.yml',\n",
60
+ " progress=False)\n",
61
+ "models = OmegaConf.load('latest_silero_models.yml')\n",
62
+ "\n",
63
+ "seed = 1337\n",
64
+ "torch.manual_seed(seed)\n",
65
+ "torch.cuda.manual_seed(seed)\n",
66
+ "\n",
67
+ "device = 'cuda' if torch.cuda.is_available() else 'cpu'"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "markdown",
72
+ "metadata": {},
73
+ "source": [
74
+ "We also need to set some variables for later use during the text processing steps, and the audio output in the TTS step.\n",
75
+ "\n",
76
+ "- `max_char_len` is set based on the results of performance testing done by the Silero devs. Larger values enable sentence structure to be better preserved, but negatively affect performance.\n",
77
+ "- `sample_rate` is also set based on recommendations from the Silero team for performance vs. quality. Using 16k or 8k audio will improve performance, but result in lower quality audio. Silero estimates a decrease of ~0.5 MOS (from 3.7 to 3.2)."
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": 2,
83
+ "metadata": {},
84
+ "outputs": [],
85
+ "source": [
86
+ "max_char_len = 150\n",
87
+ "sample_rate = 24000"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "markdown",
92
+ "metadata": {},
93
+ "source": [
94
+ "The Silero implementation comes with models trained on various languages, the most common being Russian, but we will use the latest English model for this proof of concept. There are also a number of English speaker choices available."
95
+ ]
96
+ },
97
+ {
98
+ "cell_type": "code",
99
+ "execution_count": null,
100
+ "metadata": {},
101
+ "outputs": [],
102
+ "source": [
103
+ "language = 'en'\n",
104
+ "model_id = 'v3_en'\n",
105
+ "speaker = 'en_0'\n",
106
+ "\n",
107
+ "model, example_text = torch.hub.load(repo_or_dir='snakers4/silero-models',\n",
108
+ " model='silero_tts',\n",
109
+ " language=language,\n",
110
+ " speaker=model_id)\n",
111
+ "model.to(device) # gpu or cpu"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "markdown",
116
+ "metadata": {},
117
+ "source": [
118
+ "### Step 2 - Ebook Import\n",
119
+ "\n",
120
+ "Below is a representative ebook (`Protrait of Dorian Gray`), taken from Project Gutenberg - a free directory of public-domain works."
121
+ ]
122
+ },
123
+ {
124
+ "cell_type": "code",
125
+ "execution_count": 4,
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "ebook_path = 'pg174.epub'"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "markdown",
134
+ "metadata": {},
135
+ "source": [
136
+ "The function below - `read_ebook()` - performs the following steps:\n",
137
+ "- Takes in the ebook, located at `ebook_path`\n",
138
+ "- Strips out any html tags\n",
139
+ "- Uses the nltk packages to download and use the `punkt` sentence-level tokenizer\n",
140
+ "- Calls the TextWrapper package to wrap sentences to the `max_char_len`, with care to fix sentence endings\n",
141
+ "- I.e. sentences are not split in the middle of a word, but rather words are preserved\n",
142
+ "- Finally sentences are appended to a chapter, and the chapters to a complete list: `corpus`"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": 5,
148
+ "metadata": {},
149
+ "outputs": [],
150
+ "source": [
151
+ "def read_ebook(ebook_path):\n",
152
+ "\n",
153
+ " import ebooklib\n",
154
+ " from ebooklib import epub\n",
155
+ " from bs4 import BeautifulSoup\n",
156
+ " from tqdm.notebook import tqdm\n",
157
+ " from nltk import tokenize, download\n",
158
+ " from textwrap import TextWrapper\n",
159
+ "\n",
160
+ " download('punkt')\n",
161
+ " wrapper = TextWrapper(max_char_len, fix_sentence_endings=True)\n",
162
+ "\n",
163
+ " book = epub.read_epub(ebook_path)\n",
164
+ "\n",
165
+ " ebook_title = book.get_metadata('DC', 'title')[0][0]\n",
166
+ " ebook_title = ebook_title.lower().replace(' ', '_')\n",
167
+ "\n",
168
+ " corpus = []\n",
169
+ " for item in tqdm(list(book.get_items())):\n",
170
+ " if item.get_type() == ebooklib.ITEM_DOCUMENT:\n",
171
+ " input_text = BeautifulSoup(item.get_content(), \"html.parser\").text\n",
172
+ " text_list = []\n",
173
+ " for paragraph in input_text.split('\\n'):\n",
174
+ " paragraph = paragraph.replace('—', '-')\n",
175
+ " sentences = tokenize.sent_tokenize(paragraph)\n",
176
+ "\n",
177
+ " # Truncate sentences to maximum character limit\n",
178
+ " sentence_list = []\n",
179
+ " for sentence in sentences:\n",
180
+ " wrapped_sentences = wrapper.wrap(sentence)\n",
181
+ " sentence_list.append(wrapped_sentences)\n",
182
+ " # Flatten list of list of sentences\n",
183
+ " trunc_sentences = [phrase for sublist in sentence_list for phrase in sublist]\n",
184
+ "\n",
185
+ " text_list.append(trunc_sentences)\n",
186
+ " text_list = [text for sentences in text_list for text in sentences]\n",
187
+ " corpus.append(text_list)\n",
188
+ "\n",
189
+ " return corpus, ebook_title"
190
+ ]
191
+ },
192
+ {
193
+ "cell_type": "markdown",
194
+ "metadata": {},
195
+ "source": [
196
+ "Here we use the above function to read in the chosen ebook."
197
+ ]
198
+ },
199
+ {
200
+ "cell_type": "code",
201
+ "execution_count": 6,
202
+ "metadata": {},
203
+ "outputs": [
204
+ {
205
+ "data": {
206
+ "application/vnd.jupyter.widget-view+json": {
207
+ "model_id": "7c7a0d27b2984cac933f97c68905d393",
208
+ "version_major": 2,
209
+ "version_minor": 0
210
+ },
211
+ "text/plain": [
212
+ " 0%| | 0/28 [00:00<?, ?it/s]"
213
+ ]
214
+ },
215
+ "metadata": {},
216
+ "output_type": "display_data"
217
+ }
218
+ ],
219
+ "source": [
220
+ "ebook, title = read_ebook(ebook_path)"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {},
226
+ "source": [
227
+ "And here, let us take a peak at the contents of the ebook:"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "code",
232
+ "execution_count": 7,
233
+ "metadata": {},
234
+ "outputs": [
235
+ {
236
+ "name": "stdout",
237
+ "output_type": "stream",
238
+ "text": [
239
+ "Title of ebook (path name):the_picture_of_dorian_gray\n",
240
+ "First paragraph (truncated for display): \n",
241
+ " ['CHAPTER I.', 'The studio was filled with the rich odour of roses, and when the light summer wind stirred amidst the trees of the garden, there came through the open', 'door the heavy scent of the lilac, or the more delicate perfume of the pink-flowering thorn.', 'From the corner of the divan of Persian saddle-bags on which he was lying, smoking, as was his custom, innumerable cigarettes, Lord Henry Wotton could', 'just catch the gleam of the honey-sweet and honey-coloured blossoms of a laburnum, whose tremulous branches seemed hardly able to bear the burden of a']\n"
242
+ ]
243
+ }
244
+ ],
245
+ "source": [
246
+ "print(f'Title of ebook (path name):{title}')\n",
247
+ "print(f'First paragraph (truncated for display): \\n {ebook[2][0:5]}')"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "markdown",
252
+ "metadata": {},
253
+ "source": [
254
+ "### Step 3 - Text-to-Speech\n",
255
+ "\n",
256
+ "The ebook is fed through the Silero TTS implementation sentence by sentence. We will also check that each tensor being created is valid (i.e. non-zero).\n",
257
+ "\n",
258
+ "Finally, the output tensors are exported as `.wav` files on a chapter by chapter basis - consistent with the file structure of common audiobooks."
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "code",
263
+ "execution_count": 8,
264
+ "metadata": {},
265
+ "outputs": [
266
+ {
267
+ "data": {
268
+ "application/vnd.jupyter.widget-view+json": {
269
+ "model_id": "4dd296c9abb941d6817b8d5c075b0c7c",
270
+ "version_major": 2,
271
+ "version_minor": 0
272
+ },
273
+ "text/plain": [
274
+ " 0%| | 0/23 [00:00<?, ?it/s]"
275
+ ]
276
+ },
277
+ "metadata": {},
278
+ "output_type": "display_data"
279
+ },
280
+ {
281
+ "data": {
282
+ "application/vnd.jupyter.widget-view+json": {
283
+ "model_id": "a7e3d37537f9495b93a092bd2125bb15",
284
+ "version_major": 2,
285
+ "version_minor": 0
286
+ },
287
+ "text/plain": [
288
+ " 0%| | 0/38 [00:00<?, ?it/s]"
289
+ ]
290
+ },
291
+ "metadata": {},
292
+ "output_type": "display_data"
293
+ },
294
+ {
295
+ "data": {
296
+ "application/vnd.jupyter.widget-view+json": {
297
+ "model_id": "a16db529b19d4e86b79e056106cfa5c1",
298
+ "version_major": 2,
299
+ "version_minor": 0
300
+ },
301
+ "text/plain": [
302
+ " 0%| | 0/36 [00:00<?, ?it/s]"
303
+ ]
304
+ },
305
+ "metadata": {},
306
+ "output_type": "display_data"
307
+ },
308
+ {
309
+ "data": {
310
+ "application/vnd.jupyter.widget-view+json": {
311
+ "model_id": "324fac7d6d7d44a9b38f7fc9cddb7abb",
312
+ "version_major": 2,
313
+ "version_minor": 0
314
+ },
315
+ "text/plain": [
316
+ " 0%| | 0/383 [00:00<?, ?it/s]"
317
+ ]
318
+ },
319
+ "metadata": {},
320
+ "output_type": "display_data"
321
+ },
322
+ {
323
+ "data": {
324
+ "application/vnd.jupyter.widget-view+json": {
325
+ "model_id": "8b5e5cfc28da4e1d996a39d0b9254c57",
326
+ "version_major": 2,
327
+ "version_minor": 0
328
+ },
329
+ "text/plain": [
330
+ " 0%| | 0/517 [00:00<?, ?it/s]"
331
+ ]
332
+ },
333
+ "metadata": {},
334
+ "output_type": "display_data"
335
+ },
336
+ {
337
+ "data": {
338
+ "application/vnd.jupyter.widget-view+json": {
339
+ "model_id": "95408c5358d64cff8cadf82d3b34d18e",
340
+ "version_major": 2,
341
+ "version_minor": 0
342
+ },
343
+ "text/plain": [
344
+ " 0%| | 0/385 [00:00<?, ?it/s]"
345
+ ]
346
+ },
347
+ "metadata": {},
348
+ "output_type": "display_data"
349
+ },
350
+ {
351
+ "data": {
352
+ "application/vnd.jupyter.widget-view+json": {
353
+ "model_id": "e3322b1b54da4c949c5ad708044c84e3",
354
+ "version_major": 2,
355
+ "version_minor": 0
356
+ },
357
+ "text/plain": [
358
+ " 0%| | 0/491 [00:00<?, ?it/s]"
359
+ ]
360
+ },
361
+ "metadata": {},
362
+ "output_type": "display_data"
363
+ },
364
+ {
365
+ "data": {
366
+ "application/vnd.jupyter.widget-view+json": {
367
+ "model_id": "41f7e5fda2f24e079be210224b36ff63",
368
+ "version_major": 2,
369
+ "version_minor": 0
370
+ },
371
+ "text/plain": [
372
+ " 0%| | 0/440 [00:00<?, ?it/s]"
373
+ ]
374
+ },
375
+ "metadata": {},
376
+ "output_type": "display_data"
377
+ },
378
+ {
379
+ "data": {
380
+ "application/vnd.jupyter.widget-view+json": {
381
+ "model_id": "007f22618ee140058eff80b29e86501e",
382
+ "version_major": 2,
383
+ "version_minor": 0
384
+ },
385
+ "text/plain": [
386
+ " 0%| | 0/254 [00:00<?, ?it/s]"
387
+ ]
388
+ },
389
+ "metadata": {},
390
+ "output_type": "display_data"
391
+ },
392
+ {
393
+ "data": {
394
+ "application/vnd.jupyter.widget-view+json": {
395
+ "model_id": "84c45b18ed994291b28ee259f2610019",
396
+ "version_major": 2,
397
+ "version_minor": 0
398
+ },
399
+ "text/plain": [
400
+ " 0%| | 0/419 [00:00<?, ?it/s]"
401
+ ]
402
+ },
403
+ "metadata": {},
404
+ "output_type": "display_data"
405
+ },
406
+ {
407
+ "data": {
408
+ "application/vnd.jupyter.widget-view+json": {
409
+ "model_id": "d9f08d28db034576a6c8d3a1ef9c7e83",
410
+ "version_major": 2,
411
+ "version_minor": 0
412
+ },
413
+ "text/plain": [
414
+ " 0%| | 0/463 [00:00<?, ?it/s]"
415
+ ]
416
+ },
417
+ "metadata": {},
418
+ "output_type": "display_data"
419
+ },
420
+ {
421
+ "data": {
422
+ "application/vnd.jupyter.widget-view+json": {
423
+ "model_id": "72e658ae2a2c4c76967aa6e8f8fc5cf5",
424
+ "version_major": 2,
425
+ "version_minor": 0
426
+ },
427
+ "text/plain": [
428
+ " 0%| | 0/361 [00:00<?, ?it/s]"
429
+ ]
430
+ },
431
+ "metadata": {},
432
+ "output_type": "display_data"
433
+ },
434
+ {
435
+ "data": {
436
+ "application/vnd.jupyter.widget-view+json": {
437
+ "model_id": "a9c88220cfda402a9dbfd5cf3d8f0f46",
438
+ "version_major": 2,
439
+ "version_minor": 0
440
+ },
441
+ "text/plain": [
442
+ " 0%| | 0/253 [00:00<?, ?it/s]"
443
+ ]
444
+ },
445
+ "metadata": {},
446
+ "output_type": "display_data"
447
+ },
448
+ {
449
+ "data": {
450
+ "application/vnd.jupyter.widget-view+json": {
451
+ "model_id": "229cd86f85d1458887b0a80c758c8dcc",
452
+ "version_major": 2,
453
+ "version_minor": 0
454
+ },
455
+ "text/plain": [
456
+ " 0%| | 0/401 [00:00<?, ?it/s]"
457
+ ]
458
+ },
459
+ "metadata": {},
460
+ "output_type": "display_data"
461
+ },
462
+ {
463
+ "data": {
464
+ "application/vnd.jupyter.widget-view+json": {
465
+ "model_id": "b7d361cc2287451d886bae67da5151a9",
466
+ "version_major": 2,
467
+ "version_minor": 0
468
+ },
469
+ "text/plain": [
470
+ " 0%| | 0/256 [00:00<?, ?it/s]"
471
+ ]
472
+ },
473
+ "metadata": {},
474
+ "output_type": "display_data"
475
+ },
476
+ {
477
+ "data": {
478
+ "application/vnd.jupyter.widget-view+json": {
479
+ "model_id": "c93a785804ea461398046c2cae64db00",
480
+ "version_major": 2,
481
+ "version_minor": 0
482
+ },
483
+ "text/plain": [
484
+ " 0%| | 0/233 [00:00<?, ?it/s]"
485
+ ]
486
+ },
487
+ "metadata": {},
488
+ "output_type": "display_data"
489
+ },
490
+ {
491
+ "data": {
492
+ "application/vnd.jupyter.widget-view+json": {
493
+ "model_id": "269e5f35fd064d2888e62a3f6f34bdf0",
494
+ "version_major": 2,
495
+ "version_minor": 0
496
+ },
497
+ "text/plain": [
498
+ " 0%| | 0/405 [00:00<?, ?it/s]"
499
+ ]
500
+ },
501
+ "metadata": {},
502
+ "output_type": "display_data"
503
+ },
504
+ {
505
+ "data": {
506
+ "application/vnd.jupyter.widget-view+json": {
507
+ "model_id": "69469c02db574342a4bb434cf80f422b",
508
+ "version_major": 2,
509
+ "version_minor": 0
510
+ },
511
+ "text/plain": [
512
+ " 0%| | 0/279 [00:00<?, ?it/s]"
513
+ ]
514
+ },
515
+ "metadata": {},
516
+ "output_type": "display_data"
517
+ },
518
+ {
519
+ "data": {
520
+ "application/vnd.jupyter.widget-view+json": {
521
+ "model_id": "6979dd4c8479420198686d5a44c00887",
522
+ "version_major": 2,
523
+ "version_minor": 0
524
+ },
525
+ "text/plain": [
526
+ " 0%| | 0/275 [00:00<?, ?it/s]"
527
+ ]
528
+ },
529
+ "metadata": {},
530
+ "output_type": "display_data"
531
+ },
532
+ {
533
+ "data": {
534
+ "application/vnd.jupyter.widget-view+json": {
535
+ "model_id": "356e20b91da44f93a0d7ad220fb00e79",
536
+ "version_major": 2,
537
+ "version_minor": 0
538
+ },
539
+ "text/plain": [
540
+ " 0%| | 0/216 [00:00<?, ?it/s]"
541
+ ]
542
+ },
543
+ "metadata": {},
544
+ "output_type": "display_data"
545
+ },
546
+ {
547
+ "data": {
548
+ "application/vnd.jupyter.widget-view+json": {
549
+ "model_id": "1d73c481c8ef45d1add550bdbf278775",
550
+ "version_major": 2,
551
+ "version_minor": 0
552
+ },
553
+ "text/plain": [
554
+ " 0%| | 0/323 [00:00<?, ?it/s]"
555
+ ]
556
+ },
557
+ "metadata": {},
558
+ "output_type": "display_data"
559
+ },
560
+ {
561
+ "data": {
562
+ "application/vnd.jupyter.widget-view+json": {
563
+ "model_id": "ae4e72fab47c4f60bb097a7dc5bca43e",
564
+ "version_major": 2,
565
+ "version_minor": 0
566
+ },
567
+ "text/plain": [
568
+ " 0%| | 0/352 [00:00<?, ?it/s]"
569
+ ]
570
+ },
571
+ "metadata": {},
572
+ "output_type": "display_data"
573
+ },
574
+ {
575
+ "data": {
576
+ "application/vnd.jupyter.widget-view+json": {
577
+ "model_id": "dd1a2bed58474658977fcb6d7fa06ab1",
578
+ "version_major": 2,
579
+ "version_minor": 0
580
+ },
581
+ "text/plain": [
582
+ " 0%| | 0/374 [00:00<?, ?it/s]"
583
+ ]
584
+ },
585
+ "metadata": {},
586
+ "output_type": "display_data"
587
+ },
588
+ {
589
+ "data": {
590
+ "application/vnd.jupyter.widget-view+json": {
591
+ "model_id": "c5deadfd7a9a4861868632f754c8bbc9",
592
+ "version_major": 2,
593
+ "version_minor": 0
594
+ },
595
+ "text/plain": [
596
+ "0it [00:00, ?it/s]"
597
+ ]
598
+ },
599
+ "metadata": {},
600
+ "output_type": "display_data"
601
+ },
602
+ {
603
+ "name": "stdout",
604
+ "output_type": "stream",
605
+ "text": [
606
+ "Chapter chapter022 is empty.\n"
607
+ ]
608
+ }
609
+ ],
610
+ "source": [
611
+ "os.mkdir(f'outputs/{title}')\n",
612
+ "\n",
613
+ "for chapter in tqdm(ebook):\n",
614
+ " chapter_index = f'chapter{ebook.index(chapter):03}'\n",
615
+ " audio_list = []\n",
616
+ " for sentence in tqdm(chapter):\n",
617
+ " audio = model.apply_tts(text=sentence,\n",
618
+ " speaker=speaker,\n",
619
+ " sample_rate=sample_rate)\n",
620
+ " if len(audio) > 0 and isinstance(audio, torch.Tensor):\n",
621
+ " audio_list.append(audio)\n",
622
+ " else:\n",
623
+ " print(f'Tensor for sentence is not valid: \\n {sentence}')\n",
624
+ "\n",
625
+ " sample_path = f'outputs/{title}/{chapter_index}.wav'\n",
626
+ "\n",
627
+ " if len(audio_list) > 0:\n",
628
+ " audio_file = torch.cat(audio_list).reshape(1, -1)\n",
629
+ " torchaudio.save(sample_path, audio_file, sample_rate)\n",
630
+ " else:\n",
631
+ " print(f'Chapter {chapter_index} is empty.')"
632
+ ]
633
+ },
634
+ {
635
+ "cell_type": "markdown",
636
+ "metadata": {},
637
+ "source": [
638
+ "### Results\n",
639
+ "\n",
640
+ "##### CPU (i7-4790k)\n",
641
+ "\n",
642
+ "Running \"Pride and Prejudice\" through the Silero model took **34m42s** to convert. This book is a good representation of the average book length: the average audiobook length on Audible is between 10 & 12 hours, while Pride and Prejudice is 11h20m.\n",
643
+ "\n",
644
+ "This is approximately a 20:1 ratio of audio length to processing time.\n",
645
+ "\n",
646
+ "Pride and Prejudice: **34m42s** - 1h39m33s on i7-4650u\n",
647
+ "\n",
648
+ "Portrait of Dorian Gray: **18m18s** - 18m50s w/output - 1h06hm04s on i7-4650u\n",
649
+ "\n",
650
+ "Crime and Punishment: **Unknown** - error converting ebook at 7/50, 19/368\n",
651
+ "\n",
652
+ "##### GPU (P4000)\n",
653
+ "\n",
654
+ "Running the same book through the Silero model on GPU took **5m39s** to convert.\n",
655
+ "\n",
656
+ "This is approximately a 122:1 ratio of audio length to processing time.\n",
657
+ "\n",
658
+ "Pride and Prejudice: **5m39s**\n",
659
+ "\n",
660
+ "Portrait of Dorian Gray: **4m26s**\n",
661
+ "\n",
662
+ "Crime and Punishment: **Unknown** - error converting ebook"
663
+ ]
664
+ },
665
+ {
666
+ "cell_type": "code",
667
+ "execution_count": null,
668
+ "metadata": {},
669
+ "outputs": [],
670
+ "source": []
671
+ }
672
+ ],
673
+ "metadata": {
674
+ "kernelspec": {
675
+ "display_name": "Python 3 (ipykernel)",
676
+ "language": "python",
677
+ "name": "python3"
678
+ },
679
+ "language_info": {
680
+ "codemirror_mode": {
681
+ "name": "ipython",
682
+ "version": 3
683
+ },
684
+ "file_extension": ".py",
685
+ "mimetype": "text/x-python",
686
+ "name": "python",
687
+ "nbconvert_exporter": "python",
688
+ "pygments_lexer": "ipython3",
689
+ "version": "3.9.12"
690
+ }
691
+ },
692
+ "nbformat": 4,
693
+ "nbformat_minor": 4
694
+ }
notebooks/pg174.epub ADDED
Binary file (255 kB). View file