-
Notifications
You must be signed in to change notification settings - Fork 1
/
intdz.py
53 lines (44 loc) · 2.26 KB
/
intdz.py
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
import os
import sys
import tts
import bookparser
import argparse
# argparse, and starts run coroutine
def getArgs():
parser = argparse.ArgumentParser(description='Convert .epub into audiobooks via AI Text-to-Speech')
parser.add_argument('chapters', metavar='N', type=str, nargs='*',
help='text/html files to parse')
parser.add_argument('--book', '-b', help='Folder of text files to process', default="")
parser.add_argument('--output', '-o', help='folder to put the resulting audio file', default="audiobook")
parser.add_argument('--format', '-f' ,help='Set the output audio format', default=".ogg"), #doesnt work lol
parser.add_argument('--audio_speed', '-as' ,help='Set the speed of the resulting audio', default=0.9), #doesnt work lol
parser.add_argument('--verbose', '-v', action='count') # doesnt work either lol
args = parser.parse_args()
if len(args.chapters) > 0 and args.book:
print("Don't use file lists and --book at the same time")
if len(args.chapters) == 0 and args.book == "":
print("Set at least one filename or --book")
return args
# I hate this language
if __name__ == "__main__":
args = getArgs()
if args.book != "":
chapterList = bookparser.getChapters(args.book)
else:
chapterList = args.chapters
chapterList.sort()
if not os.path.exists(args.output):
os.makedirs(args.output)
tacotron2, waveglow = tts.initializeTTSEngine()
i = 0
for chapter in chapterList:
i=i+1
chapterTitle= os.path.basename(os.path.splitext(chapter)[0])
# check if we finished transcribing this before
if not os.path.exists(args.output+"/"+chapterTitle+args.format):
plainChapter = bookparser.parseChapter(args.book+chapter)
subsentences = bookparser.splitSentences(plainChapter)
tts.vocalise(subsentences, args.output+"/"+chapterTitle, args.format, args.audio_speed, ".wav", tacotron2, waveglow)
print("[+] TTS on "+chapter+" done, saved to "+args.output+"/"+chapterTitle+args.format+" ["+str(i)+"/"+str(len(chapterList))+"]")
else:
print("[+] "+chapter+" already exists at "+args.output+"/"+chapterTitle+args.format+", skipping! ["+str(i)+"/"+str(len(chapterList))+"]")