/
phrasesToSay.py
89 lines (73 loc) · 2.64 KB
/
phrasesToSay.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import time
import sys
import ctypes
import IPC
lib=ctypes.CDLL('FakeInputWin')
#FakeInputWin simulates input into the BaldiSync window
#should be a valid key code
def speak(key):
if(key in phrases):
lib.typeInBaldi(phrases[key]) #pass the phrase for BaldiSync to say
time.sleep(delay[key]) #sleeps so that a new phrase isn't started before the other is finished
p.write('ready\n') #tell master controller that it is ready for another phrase
#should be a valid key code, speaks the name after the phrase
def speakName(key, name):
if key in phrases:
lib.typeInBaldi(phrases[key] + " " + name)
time.sleep(.3 + delay[key])
p.write('ready\n')
#method for adding a new key-phrase pair witha given delay
def addPhrase(key, phrase, d):
phrases[key] = phrase
delay[key] = d
#add a new name
def addPerson(name):
names.append(name)
def onLineRead():
message = p.line.strip().split()
if message[0] in phrases and message[0] in delay:
if len(message) > 1:
if int(message[1]) < len(names): #means a valid person ID was passed as well as a key
p.write('not yet\n') #tell master controller that a phrase is still being spoken
speakName(message[0], names[int(message[1])])
else: #person ID was invalid for phrasesToSay
p.write('not yet\n')
speak(message[0])
else: #no person ID given
p.write('not yet\n')
speak(message[0])
#keys for phrases and delay should all match
#set of initial phrases
phrases = {"right": "I am moving to your right"}
phrases["left"] = "I am moving to your left"
phrases["hello"] = "Hello there"
phrases["query"] = "What would you like me to do"
phrases["bye"] = "Good bye"
phrases["follow"] = "I am following you now"
phrases["stopFollow"] = "I am no longer following you"
phrases["lost"] = "I can not see you"
phrases["unrecognized"] = "I am sorry. I do not know you"
phrases["turnAround"] = "I am turning"
#set of initial delays
delay = {"right": 3}
delay["left"] = 3
delay["hello"] = 3
delay["query"] = 3
delay["bye"] = 2
delay["follow"] = 3
delay["stopFollow"] = 3.3
delay["lost"] = 2.5
delay["unrecognized"] = 4
delay["turnAround"] = 3
#set of initial names
names = ["Daniel", "Chris", "Cassie"]
#initial setup for interprocess communication
p = IPC.process(True, "phrasesToSay")
p.setOnReadLine(onLineRead)
IPC.InitSync()
#tell master controller that it is ready to speak
p.write('ready\n')
#main loop to run and communicate with master controller
while True:
p.tryReadLine()
IPC.Sync()