From: Erik Andresen Date: Sun, 21 Mar 2021 07:47:20 +0000 (+0100) Subject: asr_vosk: Allow to handle keyword and command in one sentence X-Git-Url: https://defiant.homedns.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=ros_wild_thumper.git asr_vosk: Allow to handle keyword and command in one sentence --- diff --git a/scripts/asr_vosk.rb b/scripts/asr_vosk.rb index b84a2f9..42ae515 100755 --- a/scripts/asr_vosk.rb +++ b/scripts/asr_vosk.rb @@ -24,7 +24,7 @@ class Speak # 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 @@ -74,14 +74,16 @@ class Speak # 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 @@ -102,7 +104,7 @@ class Speak @publisher.publish(msg) end - def keyword_detect(hyp) + def keyword_detected(hyp) @logger.debug "Got keyword: " + hyp enable_commands(true) end