Listening to Commands

Below is an example client in Python - run this with your own token and app name substituted in.

Test it out by saying "Note turn on the lights" to Siri.

client.py
import socketio

sio = socketio.Client()

# Replace with your generated token
token = "a598fbce-7cc7-4240-ad35-0b86b2651c59"

# Replace siricontrol-server with the name of your app.
sio.connect('https://siricontrol-server.herokuapp.com/?token=' + token)


@sio.on
def connect():
    print('Connected.')
    
@sio.on('spoken')
def onSpeech(spokenText):
    print(spokenText)

@sio.on('commands')
def command(data):
    print(data)
    print("Command: ", data["command"])
    print("Option: ", data["option"])
    print("Spoken Text: ", data["spoken"])


@sio.on('lights')
def lights(data):
    print(data)

Fork the Repository

To add your own commands, first fork the SiriControl repository. Connect automatic deployment to your forked Github repository, from the deployment tab.

Custom Commands

Here is the basic commands configuration - this should be self-explanatory. Add your own commands in the following manner and push your forked repository. That's it!

{
  "commands": {
    "lights": {
      "required": ["turn", "tv"],
      "options": ["on", "off"]
    },
    "volume": {
      "required": ["turn", "volume"],
      "options": ["up", "down"]
    }
  }
}

Handle custom commands in the following manner (e.g. in Python) :

@sio.on('lights')
def lights(data):
    print(data)

Last updated