plamoni / SiriProxy

A (tampering) proxy server for Apple's Siri
GNU General Public License v3.0
2.12k stars 344 forks source link

"On" and "Off" are not matched by Siriproxy #429

Closed sturma closed 11 years ago

sturma commented 11 years ago

I'm a testing a custom plugin, using custom commands. Everything works fine, except with "on" or "off" commands, they are recognized by siriproxy, but it can't match them. All other words/phrases work fine. Is there some limitation for words with e.g. 3 letters or less?

plamoni commented 11 years ago

Can you provide some code (maybe in a gist)?

sturma commented 11 years ago

the plugin code is here: https://github.com/berenyit/Siriproxy-Control4

sturma commented 11 years ago

Here's how the output looks like. I populate commands.yml file with all commands, they all work fine except 'on' and 'off'.

[Info - iPhone] Received Object: Metrics
[Info - iPhone] Received Object: StartSpeechRequest
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: FinishSpeech
[Info - Guzzoni] Received Object: SpeechRecognized
[Info - Plugin Manager] Processing 'Unlock the door '
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Matches (?i-mx:Unlock the door)
[Info - Plugin Manager] Applicable states: 
[Info - Plugin Manager] Current state: 
[Info - Plugin Manager] Matches, executing block
[Info - Plugin Manager] Say: The Door is unlocking
[Info - Plugin Manager] Sending Request Completed
[Info - iPhone] Received Object: Metrics
[Info - iPhone] Received Object: StartSpeechRequest
[Info - iPhone] Received Object: SpeechPacket
[Info - Guzzoni] Received Object: RequestCompleted
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: FinishSpeech
[Info - Guzzoni] Received Object: SpeechRecognized
[Info - Plugin Manager] Processing 'Lock the door '
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Matches (?i-mx:Lock the door)
[Info - Plugin Manager] Applicable states: 
[Info - Plugin Manager] Current state: 
[Info - Plugin Manager] Matches, executing block
[Info - Plugin Manager] Say: The Door is locking
[Info - Plugin Manager] Sending Request Completed
[Info - iPhone] Received Object: Metrics
[Info - iPhone] Received Object: StartSpeechRequest
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: FinishSpeech
[Info - Guzzoni] Received Object: SpeechRecognized
[Info - Plugin Manager] Processing 'On '
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] No matches for 'On '
[Info - Guzzoni] Received Object: AddViews
[Info - Guzzoni] Received Object: RequestCompleted
[Info - iPhone] Received Object: Metrics
[Info - iPhone] Received Object: StartSpeechRequest
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: CancelSpeech
[Info - iPhone] Received Object: StartSpeechRequest
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: SpeechPacket
[Info - iPhone] Received Object: FinishSpeech
[Info - Guzzoni] Received Object: SpeechRecognized
[Info - Plugin Manager] Processing 'Off '
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] Processing plugin #
[Info - Plugin Manager] No matches for 'Off '
[Info - Guzzoni] Received Object: AddViews
[Info - Guzzoni] Received Object: RequestCompleted
[Info - iPhone] Received Object: Metrics

Here's the commands.yml file I'm using:

#set up your voice commands here for all possible events
event01:
  commands:
  - Lights Off 
  - Light Off
  answer: Turning Light off
event02:
  commands:
  - Lights On 
  - Light On
  answer: Turning Light on
event03:
  commands:
  - Lights
  - Light
  answer: Activate scene or switch lights
event04:
  commands:
  - Unlock the door
  answer: The Door is unlocking
event05:
  commands:
  - Lock the door
  answer: The Door is locking
event06:
  commands:
  - Off 
  answer: Turning Off
event07:
  commands:
  - On 
  answer: Turning On
sturma commented 11 years ago

I modified the 'siriproxy-example.rb' file, and instead of 'test siri proxy' i used 'off' or 'on'. The server replied normally. So, I assume this purely a plugin issue. I'll address it to its author.

plamoni commented 11 years ago

Actually, I may have a solution for you. :-)

Looks like your entries with the words "On" and "Off" have spaces after them (see your logs). Can you try removing the spaces and seeing if that resolves the issue? If not, you might consider modifying this line of the plugin code:

https://github.com/berenyit/Siriproxy-Control4/blob/master/lib/siriproxy-control4.rb#L11

To read:

listen_for /#{ @@commands_def[ key ][ "commands" ].join( "[ ]*|" ) }\s*/i do

That might fix the problem. If so, submit the change to the plugin author so others can get the fix.

Good luck!

plamoni commented 11 years ago

Closing because it's a plugin issue, but feel free to continue the conversation if you make progress. Thanks!

sturma commented 11 years ago

That didn't work (and there were no spaces as well in the commands) but I found out that this space appears also with the example plugin. What's also interesting is the following:

lupinglade commented 11 years ago

The problem is that the string passed to listen_for always contains a trailing space, which can sometimes be included in the regex capture, throwing off the plugin. It would be good to ensure that there is no trailing space before passing the recognized speech string to the plugin listen_for method.

lupinglade commented 11 years ago

Marking out line 43 in lib/siriproxy/interpret_siri.rb

[code] object["properties"]["recognition"]["properties"]["phrases"].map { |phraseObj| phraseObj["properties"]["interpretations"].first["properties"]["tokens"].map { |token| tokenProps = token["properties"]

      phrase = phrase[0..-2] if tokenProps["removeSpaceBefore"] and phrase[-1] == " "
      phrase << tokenProps["text"]
      #phrase << " " if !tokenProps["removeSpaceAfter"]
    }
  }

[/code]

Seems to work around the issue, not sure what effects it may have.

lupinglade commented 11 years ago

Of course its also possible to just strip the capture in your listen_for method, but that gets repetitive and is just a workaround as well.