asr_vosk: add comments
authorErik Andresen <erik@vontaene.de>
Sun, 21 Mar 2021 07:28:56 +0000 (08:28 +0100)
committerErik Andresen <erik@vontaene.de>
Sun, 21 Mar 2021 07:28:56 +0000 (08:28 +0100)
scripts/asr_vosk.rb

index bc73949..b84a2f9 100755 (executable)
@@ -19,9 +19,10 @@ CONFIG = {
 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')
@@ -30,6 +31,7 @@ class Speak
                                @ws.send '{"eof" : 1}'
                        end
 
+                       # Loop over all input data
                        def run
                                while true do
                                        data = ARGF.read(16000)
@@ -69,29 +71,32 @@ class Speak
                                @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)
@@ -99,7 +104,7 @@ class Speak
 
        def keyword_detect(hyp)
                @logger.debug "Got keyword: " + hyp
-               enable_jsgf(true)
+               enable_commands(true)
        end
 end