forked from thomasweng15/E.V.E.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheve.py
executable file
·75 lines (59 loc) · 1.63 KB
/
eve.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/python
# -*- coding: utf-8 -*-
from brain.brain import Brain
import getopt
import subprocess
import sys
JULIUS_FILE = "./data/julius/julian.jconf"
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "hs",)
except getopt.GetoptError:
usage()
# NOTE current functionality does not require for loop
if opts == []:
start_listening()
else:
for opt in opts:
opt = opt[0]
if opt == '-h':
usage()
elif opt == '-s':
start_text_prompt()
# break will be removed when/if greater functionality
# with cmdline args is required.
break
def start_listening():
"""Initialize the program and start listening for activation commands."""
brn = Brain()
proc = subprocess.Popen(['padsp', 'julius', '-quiet',
'-input', 'mic',
'-C', JULIUS_FILE],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while 1:
line = proc.stdout.readline()
if brn.process_input(line, proc) == True:
proc = subprocess.Popen(['padsp', 'julius', '-quiet',
'-input', 'mic',
'-C', JULIUS_FILE],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
sys.stdout.flush()
def start_text_prompt():
"""Initialize the program and open text prompt for activation commands."""
brn = Brain()
print "Starting standard input mode."
while 1:
line = raw_input("> ")
brn.process_input(line, None)
def usage():
"""Print usage / help message."""
usage = """
Usage: python eve.py [options]
-h Prints this message and exits.
-s Reads from stdin instead of using pocketsphinx for activation.
Please report bugs to thomasweng15 on github.com.
"""
print usage
sys.exit(1)
if __name__ == '__main__':
main()