ipad3 voice control

Posted on
Sun Apr 08, 2012 2:18 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

ipad3 voice control

the ipad3 has a dictation input, which allows you to input text via voice. I've had an hour or so spare so what a perfect opportunity to test integration with Indigo.

The following script works to control lighting and some of the appliances in my sitting room using a form of logic. It actually takes more key presses this way than switching on/off each appliance but is fun, and can impress. you can also control a number of devices in one sentence.

I created a voice input variable, extract key control words by compairing lists (this allows a form of naturally speaking), convert that data back into a variable and then check the contents of that variable to undertake actions.

A button on the control page opens a variable text input box, you then tap the box so that it has focus, tap the keyboard microphone, dictate commands, tap the microphone to stop, and then hit done on the keyboard.

The number of key presses could be reduced if the variable box gained focus when it pops up, and the second press of the microphone could action "done" on the keyboard. I think this would need an update to the app though.

It will need adjusting to your particular set up, but i thought i would post incase anyone else fancies playing. I have a set of dmx led's and found it useful to extract out the colour control into a separate variable. The speed is great.

it allows you to say "please switch the tv off" or "turn the telly off, i'm going to bed" etc with the same result.

Code: Select all
if value of variable "voicecontrol" = "" then stop

set tempvoice to (value of variable "voicecontrol")

--set variable to list
set AppleScript's text item delimiters to " "
set voicelist to every text item of tempvoice


--replace slang for command words in list
repeat with i from 1 to count voicelist
   if voicelist's item i is "tv" then set item i of voicelist to "television"
   if voicelist's item i is "telly" then set item i of voicelist to "television"
   if voicelist's item i is "half" then set item i of voicelist to "30"
   if voicelist's item i is "big" then set item i of voicelist to "main"
   if voicelist's item i is "coloured" then set item i of voicelist to "colour"
end repeat

--extract key words from voice variable equal to the flollowing list
set itemstoretain to {"on", "off", "television", "lamp", "kitchen", "10", "15", "20", "30", "main", "colour"}

set voicefinal to {""}
repeat with i from 1 to count voicelist
   if {voicelist's item i} is in itemstoretain then set voicefinal's end to voicelist's item i
end repeat

set voicefinal to voicefinal as string

-separate list for coloured LED lights
set itemscolourretain to {"pink", "orange", "purple", "yellow", "red", "green", "blue"}
set voicecolour to {""}
repeat with i from 1 to count voicelist
   if {voicelist's item i} is in itemscolourretain then set voicecolour's end to voicelist's item i
end repeat

set voicecolour to voicecolour as string

if voicefinal contains " television on" or voicefinal contains " on television" then
   turn on "Sitting room TV"
   say "The television has been switched on"
end if

if voicefinal contains " television off" or voicefinal contains " off television" then
   turn off "Sitting room TV"
   say "The television has been switched off"
end if

if voicefinal contains " lamp on" or voicefinal contains " on lamp" then
   turn on "Sitting room lamp"
   say "The lamp has been switched on"
end if

if voicefinal contains " lamp off" or voicefinal contains " off lamp" then
   turn off "Sitting room lamp"
   say "The lamp has been switched off"
end if

if voicefinal contains " colour on" or voicefinal contains " on colour" then
   turn on "Coloured lights"
   say "The coloured lights have been switched on"
end if

if voicefinal contains " colour off" or voicefinal contains " off colour" then
   turn off "Coloured lights"
   say "The coloured lights have been switched off"
end if

if voicecolour = " green" then
   turn on "Coloured lights"
   execute group "DMX100"
   say "The coloured lights are now green"
end if

if voicecolour = " yellow" then
   turn on "Coloured lights"
   execute group "DMX51"
   say "The coloured lights are now yellow"
end if

if voicecolour = " red" then
   turn on "Coloured lights"
   execute group "DMX1"
   say "The coloured lights are now red"
end if

if voicecolour = " orange" then
   turn on "Coloured lights"
   execute group "DMX26"
   say "The coloured lights are now orange"
end if

if voicecolour = " blue" then
   turn on "Coloured lights"
   execute group "DMX192"
   say "The coloured lights are now blue"
end if

if voicecolour = " purple" then
   turn on "Coloured lights"
   execute group "DMX235"
   say "The coloured lights are now purple"
end if

if voicecolour = " pink" then
   turn on "Coloured lights"
   execute group "DMX304"
   say "The coloured lights are now pink"
end if

if voicefinal contains " kitchen off" or voicefinal contains " off kitchen" then
   turn off "Kitchen lights"
   say "The kitchen lights have been switched off"
   enable trigger action "kitchen light off"
end if

if voicefinal contains " kitchen on 30" or voicefinal contains " on kitchen 30" then
   turn on "Kitchen lights"
   brighten "Kitchen lights" to 100
   disable trigger action "kitchen light off" for 30
   say "The kitchen lights have been switched on for 30 minutes"
   
end if

if voicefinal contains " kitchen on 20" or voicefinal contains " on kitchen 20" then
   turn on "Kitchen lights"
   brighten "Kitchen lights" to 100
   disable trigger action "kitchen light off" for 20
   say "The kitchen lights have been switched on for 20 minutes"
   
end if

if voicefinal contains " kitchen on 15" or voicefinal contains " on kitchen 15" then
   turn on "Kitchen lights"
   brighten "Kitchen lights" to 100
   disable trigger action "kitchen light off" for 15
   say "The kitchen lights have been switched on for 15 minutes"
   
end if

if voicefinal contains " kitchen on 10" or voicefinal contains " on kitchen 10" then
   turn on "Kitchen lights"
   brighten "Kitchen lights" to 100
   disable trigger action "kitchen light off" for 10
   say "The kitchen lights have been switched on for 10 minutes"
   
end if

if voicefinal contains " kitchen on" or voicefinal contains " on kitchen" then
   turn on "Kitchen lights"
   brighten "Kitchen lights" to 100
   disable trigger action "kitchen light off" for 10
   say "The kitchen lights have been switched on for 10 minutes"
   
end if

if voicefinal contains " main off" or voicefinal contains " off main" then
   turn off "sitting room ceiling sofa"
   turn off "sitting room ceiling tv"
   say "The sitting room main lights have been switched off"
   
end if

if voicefinal contains " main on" or voicefinal contains " on main" then
   brighten "sitting room ceiling sofa" to 100
   brighten "sitting room ceiling tv" to 100
   say "The sitting room main lights have been switched on"
   
end if


set value of variable "voicecontrol" to ""

Late 2018 mini 10.14

Posted on
Sun Apr 08, 2012 2:22 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: ipad3 voice control

Great and creative tip!

Image

Posted on
Mon Apr 09, 2012 6:44 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

i've also added text support - and presumably siri - via iMessage.

The machine running the indigo server has its own iMessage account added.

Add the following script to iMessage "message received event", where xxxx is the authorised user. further users can be added.

Code: Select all
using terms from application "iChat"
   on message received theText from theBuddy for theChat
      if (theBuddy's name as string = "xxxxxx") then
         tell application "IndigoServer"
            set value of variable "voicecontrol" to (theText as string)
         end tell
      else
         
         say "Message recieved from"
         delay 0.2
         say theBuddy's name as string
         delay 0.5
         say theText
      end if
   end message received
end using terms from

Late 2018 mini 10.14

Posted on
Mon Apr 09, 2012 6:33 pm
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: ipad3 voice control

Thanks for the fun script!

Since I might say "put on some beatles" instead of "play some beatles", I was hoping to use a slang substitute for "put on".

--replace slang for command words in list
repeat with i from 1 to count voicelist
if voicelist's item i is "put on" then set item i of voicelist to "play"

Then instead of having to have multiple statements for each playlist I could just use:

if voicefinal contains " beatles play" or voicefinal contains " play beatles" then
execute group "Beatles Music"
end if

Can't seem to get any variations of it to work. Setting the variable to any version containing "play beatles" works, but not variations of "put on beatles".

Any help?

Thanks,

Carl

Posted on
Tue Apr 10, 2012 12:34 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

Hi Carl,

I believe it's because "put on" is two words, where as each item in the list is one word. You are therefore never getting a replace in the slang section.

As "on" is an obvious key word too, if you just replace "put" with "play" the finalvoice string in part will contain "play on Beatles" which would need an additional control line to check for that occurrence.

OR

Check i for "put" and i+1 for "on", and replace i with "play" and i+1 with "ignore" and leave your actions as they are.

Not tested this....

Code: Select all
--replace slang for command words in list
repeat with i from 1 to count voicelist
if voicelist's item i is "put" and voicelist's item i+1 is "on" then
      set item i of voicelist to "play"
      Set item i+1 of voicelist to "ignore"
End if




I would suggest the easier alternative is to just use the word "Beatles", and ignore "play" or "put". I suspect you are unlikely to say "stop playing the Beatles", therefore could you just use the keyword "Beatles" to play the playlist? You could also have a generic stop playing music command. That would allow you a wider selection of Control choices too, like "I would like to listen to some Beatles"

Code: Select all
if voicefinal contains " Beatles" then
Execute action "Beatles Music"
End if


Hope this helps.

Mat
Last edited by mat on Tue Apr 10, 2012 1:52 am, edited 1 time in total.

Late 2018 mini 10.14

Posted on
Tue Apr 10, 2012 1:42 am
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: ipad3 voice control

Though I don't have the 4S or iPad 3 to test with this, the app "Vocal" may be fun to do further iOS device-to-Mac controlling.

http://mtrbts.me/vocal/

Posted on
Tue Apr 10, 2012 2:29 am
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

It's probably a lot more polished, but the iMessage addition does much the same with text. The difference is, you have to write the Speach logic yourself with my example.

Late 2018 mini 10.14

Posted on
Tue Apr 10, 2012 7:30 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: ipad3 voice control

Thanks Mat. I did think about the one word
activation...knowing me I might say
"I've had enough Beatles".

Can't get this line to compile: Set item i+1 of voicelist to "ignore"

Gets an "access not allowed"

Has anyone tried the new Vocal app? Be cool if you could populate Mat's voicecontrol
variable with it...or for that matter trigger anything in Indigo.


Carl

Posted on
Wed Apr 11, 2012 2:56 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

Hi Carl,

I'm away until Sunday, but will have a look when I get home.

Regards

Mat

Late 2018 mini 10.14

Posted on
Thu Apr 12, 2012 8:37 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: ipad3 voice control

Thanks. You mentioned earlier that it may be possible to include multiple commands
in the same sentence. Been trying variations of, "Turn on the balcony and fly tying lights" etc.
but only the first device in the variable responds.

Any tips on that?

Thanks,

Carl

Posted on
Thu Apr 12, 2012 2:48 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

Include an "on" or "off" for each item. Ie turn off the lamp and switch off the tv. Turn off the lights and turn on the tv.

I've tried to work on some logic with "and", but there is no logic to the English language.

The problem is that you could say, turn on the lights and fish and switch tv off.

The extracted logic would be - on lights fish tv off.

Compared to, turn on the lights and switch fish and tv off.

Wich would also produce - on lights fish tv off - ie same as above, but not what was instructed.

Given the above, I am considering the logic of turning on those items with an on command, turning off those with an off, and toggling those that are neither preceded, or followed by an "on" or "off", as that method would use some form of logic. I'll see how this works when I get home and post an update.

Let me know how you get on with multiple commands. Ie turn off lights and turn tv on.



Mat

Late 2018 mini 10.14

Posted on
Wed Apr 18, 2012 2:04 pm
mat offline
Posts: 769
Joined: Nov 25, 2010
Location: Cambridgeshire - UK

Re: ipad3 voice control

Try

Code: Select all
 Set item (i+1) of voicelist to "ignore"

Late 2018 mini 10.14

Posted on
Mon Apr 22, 2013 5:58 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: ipad3 voice control

Thanks for posting! Love the idea of this, but I'm getting an error right out of the gate and I'm not any sort of applescript guru. Any ideas?

It's snagging on the first " of the first line of code. Getting the error message of - Syntax Error - Expected “then”, etc. but found “"”.

Code: Select all
if value of variable "voicecontrol" = "" then stop

Posted on
Mon Apr 22, 2013 9:29 am
ckeyes888 offline
Posts: 2417
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: ipad3 voice control

I run it as an embedded script. Compiles fine that way.

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests