forked from devanhurst/ktane_voice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
charlie.rb
144 lines (134 loc) · 5.26 KB
/
charlie.rb
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
require 'bundler/setup'
require 'pocketsphinx-ruby'
require 'pry'
require 'ordinator'
require "espeak"
include ESpeak
require "require_all"
require_relative "bomb"
require_rel "solvers"
include Check
include Wires
include Button
include Keypads
include Memory
include WireSequences
include Words
include ComplicatedWires
include MorseCode
include Mazes
include Passwords
include Simon
include Knobs
@bomb = Bomb.new
def select_module
configuration = Pocketsphinx::Configuration::Grammar.new('grammars/charlie.gram')
recognizer = Pocketsphinx::LiveSpeechRecognizer.new(configuration)
recognizer.recognize do |speech|
case speech
when "charlie bomb check"
Speech.new("Check").speak
Speech.new(Check.check_all(Pocketsphinx::Configuration::Grammar.new('grammars/check.gram'), @bomb)).speak
return select_module
when "defuse wires"
Speech.new("Wires").speak
Speech.new(Wires.solve_wires(Pocketsphinx::Configuration::Grammar.new('grammars/wires.gram'), @bomb)).speak
return select_module
when "defuse button"
Speech.new("Button").speak
Speech.new(Button.solve_button(Pocketsphinx::Configuration::Grammar.new('grammars/button.gram'), @bomb)).speak
return select_module
when "defuse keypads"
Speech.new("Keypads").speak
Speech.new(Keypads.sanitize_input(Pocketsphinx::Configuration::Grammar.new('grammars/keypads.gram'))).speak
return select_module
when "defuse memory"
Speech.new("Round #{@bomb.memory_round}").speak
Speech.new(Memory.solve_memory(Pocketsphinx::Configuration::Grammar.new('grammars/memory.gram'), @bomb)).speak
return select_module
when "defuse sequence"
Speech.new("Sequence").speak
Speech.new(WireSequences.solve_wire_sequences(Pocketsphinx::Configuration::Grammar.new('grammars/wiresequences.gram'), @bomb)).speak
return select_module
when "defuse words"
Speech.new(Words.solve_1(Pocketsphinx::Configuration::Grammar.new('grammars/words1.gram'))).speak
return select_module
when "defuse complicated"
Speech.new("Complicated").speak
Speech.new(ComplicatedWires.solve_complicated(Pocketsphinx::Configuration::Grammar.new('grammars/complicatedwires.gram'), @bomb)).speak
return select_module
when "defuse morse code"
Speech.new("letter.").speak
Speech.new(MorseCode.prompt_morse_code(@bomb)).speak
return select_module
when "defuse maze"
Mazes.prompt_mazes
return select_module
when "defuse password"
Speech.new(Passwords.prompt_user(@bomb)).speak
return select_module
when "defuse simon"
Speech.new("Simon").speak
Speech.new(Simon.solve_simon(Pocketsphinx::Configuration::Grammar.new('grammars/simonsays.gram'), @bomb)).speak
return select_module
when "defuse knobs"
Speech.new("Knob").speak
Speech.new(Knobs.solve_knobs(Pocketsphinx::Configuration::Grammar.new('grammars/knobs.gram'))).speak
return select_module
when "reset wire sequences"
@bomb.wire_sequences_red_count = 0
@bomb.wire_sequences_blue_count = 0
@bomb.wire_sequences_black_count = 0
Speech.new("Wire sequences reset.").speak
return select_module
when "reset password"
Passwords.reset_password(@bomb)
Speech.new("Passwords reset.").speak
return select_module
when "reset memory"
Memory.reset_memory(@bomb)
Speech.new("Memory reset.").speak
return select_module
when "reset morse code"
@bomb.morse_characters = []
Speech.new("Morse reset.").speak
return select_module
when "undo last wire sequence"
if !@bomb.wire_sequences_moves.empty?
WireSequences.undo_wire_sequence(@bomb)
Speech.new("Sequence undone").speak
end
return select_module
when "add a strike"
@bomb.strikes += 1
Speech.new("#{Ordinator.convert(@bomb.strikes)} strike").speak
return select_module
when "remove a strike"
if @bomb.strikes > 0
@bomb.strikes -= 1
Speech.new("Strike removed").speak
return select_module
end
when "charlie the bomb is defused", "charlie we did it", "charlie we're done"
# Speech.new(["It was my pleasure.", "I'm proud of us.", "We did it!", "What a relief.", "Thank goodness.", "Congratulations!", "You deserve a drink."].sample).speak
Speech.new("We all deserve a drink.").speak
return select_module
when "charlie the bomb detonated", "charlie it detonated", "charlie the bomb blew up", "charlie it blew up", "charlie we lost"
Speech.new(["It was all my fault.", "It's not your fault", "It's not my fault.", "I hope you're proud of yourself.", "This can't be happening!"].sample).speak
return select_module
# when "charlie what is your purpose"
# Speech.new("I defuse bombs.").speak
# c = Pocketsphinx::Configuration::Grammar.new('grammars/charliepurpose.gram')
# Pocketsphinx::LiveSpeechRecognizer.new(c).recognize do |r|
# Speech.new("i").speak
# Speech.new("...").speak
# Speech.new("i...").speak
# Speech.new("Oh my god.").speak
# return select_module
# end
end
end
end
Speech.new("My name is Charlie.").speak
Speech.new(["Ready.", "Let's roll.", "Let's do this.", "Let's play."].sample).speak
select_module