# Websocket handling
EM.run do
- Signal.trap("INT") { send_eof }
+ Signal.trap("INT") { send_eof }
@ws = WebSocket::EventMachine::Client.connect(:uri => 'ws://192.168.36.4:2700')
def send_eof
# check for keywords first
text = msg["text"]
@logger.debug "text=" + msg["text"]
- if KEYWORDS.include? text
- keyword_detect(text)
- return
+ KEYWORDS.each do |keyword|
+ if text.include? keyword
+ keyword_detected(keyword)
+ text = text.gsub(keyword, "").strip
+ end
end
# not a keyword, handle command if enabled
- if @commands_enabled
- final_result(msg["text"])
+ if @commands_enabled and text.length > 0
+ final_result(text)
end
end
end
@publisher.publish(msg)
end
- def keyword_detect(hyp)
+ def keyword_detected(hyp)
@logger.debug "Got keyword: " + hyp
enable_commands(true)
end