-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech.rb
48 lines (38 loc) · 1.04 KB
/
speech.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
require 'pocketsphinx-ruby'
#Phrase to listen for
listening_keyword = "house elf"
command_list = {
listening_keyword => "Listening",
"living room light" => "pl a1 on",
"Turn off living room light" => "pl a1 off",
"bedroom light" => "pl a2 on",
"Turn off bedroom light" => "pl a2 off",
"Play music" => "PM",
"Stop music" => "SM",
"Forget it" => "Forgotten"
}
puts "Availible Commands:"
command_list.each do |key, value|
puts key
end
configuration = Pocketsphinx::Configuration::Grammar.new do
sentence listening_keyword
command_list.each do |key, value|
sentence key
end
end
configuration['vad_threshold'] = 3
recognizer = Pocketsphinx::LiveSpeechRecognizer.new(configuration)
#By default don't listen for anything but
listening = false
recognizer.recognize do |speech|
if listening then
puts command_list[speech]
puts speech
#Stop listening after the command is done
listening = false
end
#If you hear the word, start listening for the next round
listening = true if speech == listening_keyword.downcase
puts listening
end