]> defiant.homedns.org Git - ros_wild_thumper.git/commitdiff
asr_vosk: Allow to handle keyword and command in one sentence master
authorErik Andresen <erik@vontaene.de>
Sun, 21 Mar 2021 07:47:20 +0000 (08:47 +0100)
committerErik Andresen <erik@vontaene.de>
Sun, 21 Mar 2021 07:47:20 +0000 (08:47 +0100)
scripts/asr_vosk.rb

index b84a2f965494fb36f41b29636a2896f3a2e71a94..42ae5153e41f1768e37e21fbb8a89eab9090464e 100755 (executable)
@@ -24,7 +24,7 @@ class Speak
 
                # Websocket handling
                EM.run do
 
                # 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
                        @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"]
                        # 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
                        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
                        end
                end
        end
@@ -102,7 +104,7 @@ class Speak
                @publisher.publish(msg)
        end
 
                @publisher.publish(msg)
        end
 
-       def keyword_detect(hyp)
+       def keyword_detected(hyp)
                @logger.debug "Got keyword: " + hyp
                enable_commands(true)
        end
                @logger.debug "Got keyword: " + hyp
                enable_commands(true)
        end