-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (65 loc) · 2.72 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import argparse
import sys
import text as toSpeech
import sys
def speech(args):
text = args.text
is_file = args.file
voice = args.voice or "gb"
speed = args.speed or 160
show_text = args.echo
listen = args.listen
clear = args.clear
toSpeech.textToSpeech(text, is_file, voice, speed,
show_text, listen, clear)
def main():
try:
if not len(sys.argv) > 1:
raise Exception("Arguments missing, no arguments were passed")
parser = argparse.ArgumentParser(
description='📢 Text to speech CLI tool', formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'text', type=str, help='file path or text string to transform as speech')
parser.add_argument(
'-f', '--file', action='store_false', help='to pass a text string as argument')
parser.add_argument(
'-c', '--clear', action='store_true', help='set flag to have no output, won\'t impact [-e]')
parser.add_argument(
'-l', '--listen', action='store_true', help='to make the script listen for inputs, when listening press "q" to stop')
parser.add_argument(
'-s', '--speed', metavar='', type=int, help='set the reading speed. (the number of words per minute)')
parser.add_argument(
'-v', '--voice',
type=str,
metavar='',
choices=[
'gb', 'gb-female', 'gb-grandpa', 'gb-grandma',
'us', 'us-female', 'us-grandma',
'fr', 'fr-female', 'fr-grandpa', 'fr-grandma',
'it', 'it-female', 'it-grandpa', 'it-grandma',
'es', 'es-female',
'ru',
'jp',
'robot', 'robot-2', 'robot-3', 'robot-4', 'robot-5',
'bells', 'bubbles', 'cellos', 'albert', 'whisper'
],
help='''voice selection:
english - gb, gb-female, gb-grandpa, gb-grandma,
us, us-female, us-grandpa, us-grandma,
french - fr, fr-female, fr-grandpa, fr-grandma,
italian - it, it-female, it-grandpa, it-grandma,
spanish - es, es-female,
russian - ru,
japanese - jp,
other - robot, robot-2, robot-3, robot-4, bells,
bubbles, cellos, albert, whisper
''')
parser.add_argument(
'-e', '--echo', action='store_true', help='echo the text content of the given file')
args = parser.parse_args()
speech(args)
except Exception as e:
print('Error:', e)
if __name__ == '__main__':
main()