-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobospeak.py
176 lines (162 loc) · 5.01 KB
/
robospeak.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import sys
# abcdefghijklmnopqrstuvwxyz
def FromNums(numarray):
RetVal = ""
for num in numarray:
# lowercase alphabet mappings
if num == [0, 0, 0, 0,]:
RetVal += "a"
elif num == [0, 0, 0, 1]:
RetVal += "b"
elif num == [0, 0, 0, 2]:
RetVal += "c"
elif num == [0, 0, 0, 3]:
RetVal += "d"
elif num == [0, 0, 1, 0]:
RetVal += "e"
elif num == [0, 0, 1, 1]:
RetVal += "f"
elif num == [0, 0, 1, 2]:
RetVal += "g"
elif num == [0, 0, 1, 3]:
RetVal += "h"
elif num == [0, 0, 2, 0]:
RetVal += "i"
elif num == [0, 0, 2, 1]:
RetVal += "j"
elif num == [0, 0, 2, 2]:
RetVal += "k"
elif num == [0, 0, 2, 3]:
RetVal += "l"
elif num == [0, 0, 3, 0]:
RetVal += "m"
elif num == [0, 0, 3, 1]:
RetVal += "n"
elif num == [0, 0, 3, 2]:
RetVal += "o"
elif num == [0, 0, 3, 3]:
RetVal += "p"
elif num == [0, 1, 0, 0]:
RetVal += "q"
elif num == [0, 1, 0, 1]:
RetVal += "r"
elif num == [0, 1, 0, 2]:
RetVal += "s"
elif num == [0, 1, 0, 3]:
RetVal += "t"
elif num == [0, 1, 1, 0]:
RetVal += "u"
elif num == [0, 1, 1, 1]:
RetVal += "v"
elif num == [0, 1, 1, 2]:
RetVal += "w"
elif num == [0, 1, 1, 3]:
RetVal += "x"
elif num == [0, 1, 2, 0]:
RetVal += "y"
elif num == [0, 1, 2, 1]:
RetVal += "z"
# WIP: special character mappings
elif num == [3, 0, 0, 0]:
RetVal += " "
elif num == [3, 0, 0, 1]:
RetVal += "?"
elif num == [3, 0, 0, 2]:
RetVal += "."
elif num == [3, 0, 0, 3]:
RetVal += "!"
else:
RetVal += "?"
return RetVal
class NotDivisibleBy4(Exception):
pass
class NotRobo(Exception):
pass
def ToNum(string):
if string.strip() == "beep":
return 0
elif string.strip() == "boop":
return 1
elif string.strip() == "bop":
return 2
elif string.strip() == "bleep":
return 3
else:
raise NotRobo
def ToNums(string):
RetVal = []
if not len(string.split(" ")) % 4 == 0:
raise NotDivisibleBy4
i = 3
while i <= len(string.split(" ")):
RetVal += [[ToNum(string.split(" ")[i - 3]), ToNum(string.split(" ")[i - 2]), ToNum(string.split(" ")[i - 1]), ToNum(string.split(" ")[i])]]
i += 4
return RetVal
def ToRobo(string):
RetVal = ""
for char in string:
if char == "a":
RetVal += "beep beep beep beep "
elif char == "b":
RetVal += "beep beep beep boop "
elif char == "c":
RetVal += "beep beep beep bop "
elif char == "d":
RetVal += "beep beep beep bleep "
elif char == "e":
RetVal += "beep beep boop beep "
elif char == "f":
RetVal += "beep beep boop boop "
elif char == "g":
RetVal += "beep beep boop bop "
elif char == "h":
RetVal += "beep beep boop bleep "
elif char == "i":
RetVal += "beep beep bop beep "
elif char == "j":
RetVal += "beep beep bop boop "
elif char == "k":
RetVal += "beep beep bop bop "
elif char == "l":
RetVal += "beep beep bop bleep "
elif char == "m":
RetVal += "beep beep bleep beep "
elif char == "n":
RetVal += "beep beep bleep boop "
elif char == "o":
RetVal += "beep beep bleep bop "
elif char == "p":
RetVal += "beep beep bleep bleep "
elif char == "q":
RetVal += "beep boop beep beep "
elif char == "r":
RetVal += "beep boop beep boop "
elif char == "s":
RetVal += "beep boop beep bop "
elif char == "t":
RetVal += "beep boop beep bleep "
elif char == "u":
RetVal += "beep boop boop beep "
elif char == "v":
RetVal += "beep boop boop boop "
elif char == "w":
RetVal += "beep boop boop bop "
elif char == "x":
RetVal += "beep boop boop bleep "
elif char == "y":
RetVal += "beep boop bop beep "
elif char == "z":
RetVal += "beep boop bop boop "
# WIP: special character mappings
elif char == " ":
RetVal += "bleep beep beep beep "
elif char == "?":
RetVal += "bleep beep beep boop "
elif char == ".":
RetVal += "bleep beep beep bop "
elif char == "!":
RetVal += "bleep beep beep bleep "
# return question mark if mapping not found
else:
RetVal += "bleep beep beep boop "
return RetVal.strip()