class Speak
def initialize(node)
@logger = Logger.new(STDOUT)
- @jsgf_enabled = false
+ @commands_enabled = false
@publisher = node.advertise('asr_result', Std_msgs::String)
+ # Websocket handling
EM.run do
Signal.trap("INT") { send_eof }
@ws = WebSocket::EventMachine::Client.connect(:uri => 'ws://192.168.36.4:2700')
@ws.send '{"eof" : 1}'
end
+ # Loop over all input data
def run
while true do
data = ARGF.read(16000)
@logger.debug "word=" + result["word"]
end
+ # check for keywords first
text = msg["text"]
@logger.debug "text=" + msg["text"]
if KEYWORDS.include? text
keyword_detect(text)
return
end
- if @jsgf_enabled
+
+ # not a keyword, handle command if enabled
+ if @commands_enabled
final_result(msg["text"])
end
end
end
- # Enables/Disables the jsgf pipeline branch
- def enable_jsgf(bEnable)
- @jsgf_enabled = bEnable
+ # Enables/Disables the speech command
+ def enable_commands(bEnable)
+ @commands_enabled = bEnable
end
- # Result of jsgf pipeline branch
+ # Resulting speech command
def final_result(hyp)
@logger.info "final: " + hyp
- enable_jsgf(false)
+ enable_commands(false)
- # Publish pocketsphinx result as ros message
+ # Publish vosk result as ros message
msg = Std_msgs::String.new
msg.data = hyp
@publisher.publish(msg)
def keyword_detect(hyp)
@logger.debug "Got keyword: " + hyp
- enable_jsgf(true)
+ enable_commands(true)
end
end