The Official Raspberry Pi Projects Book - Projects_Book_v4

(singke) #1

Tutorial


raspberrypi.org/magpi The Official Raspberry Pi Projects Book 151


SIRICONTROL


#You can import any required modules here

moduleName = "life"

commandWords = ["meaning","life"]

def execute(command):
print("\n")
print("-----------The meaning of life is 42-----------")
print("\n")

life.py


Language
>PYTHON

DOWNLOAD:
magpi.cc/2t3BAwb


STEP-03
Prepare your iOS device
The Notes need to be synced with your Gmail account
so that SiriControl can fetch the voice commands that
you say, through Siri. So navigate to Settings > Notes
Accounts > Add Account on your iOS device, and add
your new Gmail account.
After turning on Notes, ensure that the default
account for creating Notes is the new account.
Now, if you say to Siri, “Note this is awesome,”
it should appear under the Notes section, under your
Gmail account.




STEP-04
Set up SiriControl
Finally, you will need to clone the SiriControl
repository using:



sudo apt-get update

sudo apt-get install git-core

git clone https://github.com/
theraspberryguy/SiriControl-System


Edit siricontrol.py and enter your Gmail account
credentials. This should be self-explanatory once the
script is opened up.
Next, run siricontrol.py and say to Siri: “Note
meaning of life.”
You should get the answer. That’s it! You have
finished the SiriControl setup. Now, let’s add your
own voice commands.



STEP-05
Create your own modules
SiriControl uses a modular approach for adding your
own commands. Each voice command, along with its
action, is separated into different modules, found in
the modules folder.



Every module must have the following:


moduleName – this is the name of the module,
which can be anything you want.


commandWords – this array will contain the words
which need to be spoken in order to call the
execute() function.


execute(command) – this function is called when
all the words in the commandWords array are spoken.
The command parameter is the complete command
spoken by the user.


Take a look at the life.py module, which comes
with SiriControl, to gain a better understanding of
how it works. Also, keep in mind that all modules you


create must be stored in the modules directory for
SiriControl to load when it starts up. The template
Module.py is also included with SiriControl, which
can be used as a reference.

>STEP-06
Next steps
Now you know how to create your own voice
commands, what next? Well, whether it’s as simple
as turning on an LED or controlling your TV using
infrared signals – with the power of Siri behind it,
the possibilities are endless! You could integrate
SiriControl into any project. Due to the nature of
the hack, you can control your Raspberry Pi from
anywhere in the world, as long as you have an internet
connection. This opens up many possibilities, including
home automation and IoT. Anything is possible!

Above IMAP must
be enabled so
that SiriControl
can fetch the
new Notes using
this protocol
Left Access for less
secure apps needs
to be enabled, as
Google identifies
this connection as
being less secure
Free download pdf