forked from dtjchen/spoken-command-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.py
68 lines (52 loc) · 1.85 KB
/
driver.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
import sys, os
import click
DEBUG = False
@click.group()
def cli():
pass
@cli.command()
@click.option('--data', default=None, type=int, help='size of the data used to train the model')
@click.option('--summarize', default=False, type=bool, help='plot the loss function')
@click.argument('model')
@click.argument('action')
def model(**kwargs):
from model import speech2phonemes, phonemes2text
if kwargs['model'] == 'speech2phonemes':
if kwargs['action'] == 'train':
click.echo('Training speech2phonemes...')
speech2phonemes.train(summarize=kwargs['summarize'], data_limit=kwargs['data'])
elif kwargs['action'] == 'test':
click.echo('Testing speech2phonemes...')
speech2phonemes.test()
elif kwargs['model'] == 'phonemes2text':
if kwargs['action'] == 'train':
click.echo('Training phonemes2text...')
phonemes2text.train(summarize=kwargs['summarize'], data_limit=kwargs['data'])
elif kwargs['action'] == 'test':
click.echo('Testing phonemes2text...')
phonemes2text.test()
else:
click.echo('Unrecognized model: %s' % kwargs['model'])
@cli.command()
def register(**kwargs):
from processor import commands
commands.register()
@cli.command()
def parse(**kwargs):
from processor import commands
commands.parse()
@cli.command()
@click.option('--port', type=int, help='listener port')
def setlistener(**kwargs):
from processor import messaging
click.echo('Listening on port %d...' % kwargs['port'])
messaging.listen(kwargs['port'])
if __name__ == '__main__':
# Obtain information about the commands via:
# python driver.py --help
# Suppress stderr from the output
if not DEBUG:
null = open(os.devnull,'wb')
sys.stderr = null
# Activate the command-line interface
cli()