I've been slowly getting into X10 home automation lately. It works like this, you get an X10 control module that plugs into the wall near the computer and a cable comes from it and plugs into your computer. Then you get software to control the control module. The control module controls whatever other modules you want to use throughout the house.
The most basic module is the lamp module, which is a small box that plugs into a wall outlet, then your lamp plugs into the module. From the computer, you tell that module to turn on or off.
What happens is that the control module sends a special signal through the wires in your house. The signal is picked up by all the X10 modules you have. The modules themselves have dials where you can select identification letters and numbers on them. You take a module and select, let's say, B4, so that module is now identified as B4. When you send the signal "B4 on," it turns itself on, which turns the lamp on.
There are numerous different modules to do different things. There are wall switches, modules for plug-in electronics like the lamp module and a similar appliance module, security modules, camera modules, dimmers, timers, weather sensors. Anything you can think of, the possibilities are endless.
You can also use them with remote controls and there are a few apps in the Android Market to run them from your phone, but I like setting them up to control from my phone over ssh. There is a Linux program called Heyu for use with the CM11A control module. Heyu can perform nearly two hundred different commands and uses simple command line syntax like heyu on B4. This makes it extremely simple to script, which in turn makes it extremely simple to control through the phone using the basic ssh command I've posted many times:
ssh USER@IP -i /PATH/TO/SSH/KEY 'heyu on B4'
This can be set up as a script to be ran from a terminal, through a GScript shortcut, or with Tasker. Of course, Tasker and X10 make an extremely useful pair.
I really haven't set much up yet except to manually turn a couple of lights on. I plan on getting a module to control the garage door next. This is done by using a "universal module" that acts like a single state button instead of an on/off switch. When the module is activated, it just does it's thing once and there is no way to reverse it. Every time it is activated, it is the same as pushing the garage door opening button so there is no way to know if it is up or down.
I plan to set it up with Tasker to activate it when I am close to home so the door will be open by the time I pull into the driveway. I'm not sure how reliable that will be, so I'll probably add a statusbar reminder that the door is open in case it is activated accidentally.
I've also considered getting a camera for the front door and a doorbell sensor. When someone rings the doorbell, the computer could tell the camera to take a photo then send it to me via MMS. If it looks like someone trying to sell something, I can ignore them. If it's a family member with a birthday present and I'm at work, I can open the garage door so they can come in.
I have no plans to do this, but this would be a cool setup...
Send a notification to the phone when the door is open
Have Tasker silence/ignore the notification if I'm at home and end the task.
If I'm not at home have Tasker say "Sir, I've detected that your garage door is open but you don't appear to be near your house. Would you like me to close it?"
Pop up the voice command window.
Using yes/no, open/closed, up/down as the keyword, I could answer in a natural voice and say "yes please close it for me" or "sure, close that sucker, I must have forgotten" or "nah, leave it up" or "it's ok, I want it open"
It could then say "Ok, closing it now," run the command to close the door and once the sensor detects that the door is closed say "It's closed, sir"
Like I said, I'm not going to do that, but it illustrates how well Tasker and X10 gear could work together to both perform really cool actions like opening doors for you and also make your phone behave somewhat like an intelligent assistant.
Android and Linux
Tuesday, December 28, 2010
Wednesday, December 22, 2010
Happy Holidays!
I haven't been around much lately but I wanted to drop in and wish everyone Happy Holidays. I also wanted to let everyone know that the current economic climate has not affected my Christmas budget and all of the readers of this little blog can expect to receive the same thing I got you last year!
Sunday, November 7, 2010
ssh error and fix
I've helped several people with this so I might as well post it here for others to stumble across. ssh can sometimes give this error:
stderr: ssh: Warning: failed creating //.ssh:
Read-only file system
stderr: Host '[my PC's ip address]' is not in the trusted hosts file
For some reason, ssh is trying to create it's hosts file in /.ssh, which is read-only, giving the error. For me, it happened when trying to use it in a script executed through GScript, but I believe it happens in other circumstances as well.
The solution that has worked for me and a few others is to replace the stock ssh binary in /system/xbin with a link to the ssh binary from Better Terminal Emulator Pro. Unfortunately, BTEP costs money but if you're using ssh or anything else from a terminal, I highly recommend buying it.
After you install Better Terminal Emulator Pro, back up the stock binary by typing this in a terminal:
mv /system/xbin/ssh /system/xbin/ssh.bak
Then put a link in /system/xbin to the BTEP ssh binary:
ln -s /data/data/com.magicandroidapps.bettertermpro/bin/ssh /system/xbin
This has been necessary every time I install an update because they always contain the stock ssh binary. Luckily, this fix has worked every time.
stderr: ssh: Warning: failed creating //.ssh:
Read-only file system
stderr: Host '[my PC's ip address]' is not in the trusted hosts file
For some reason, ssh is trying to create it's hosts file in /.ssh, which is read-only, giving the error. For me, it happened when trying to use it in a script executed through GScript, but I believe it happens in other circumstances as well.
The solution that has worked for me and a few others is to replace the stock ssh binary in /system/xbin with a link to the ssh binary from Better Terminal Emulator Pro. Unfortunately, BTEP costs money but if you're using ssh or anything else from a terminal, I highly recommend buying it.
After you install Better Terminal Emulator Pro, back up the stock binary by typing this in a terminal:
mv /system/xbin/ssh /system/xbin/ssh.bak
Then put a link in /system/xbin to the BTEP ssh binary:
ln -s /data/data/com.magicandroidapps.bettertermpro/bin/ssh /system/xbin
This has been necessary every time I install an update because they always contain the stock ssh binary. Luckily, this fix has worked every time.
Thursday, November 4, 2010
Finally, a use for twitter
I've never had much use for Twitter but I've recently found myself using my phone to log into my computer to check various things throughout the day. While I have those things set up with GScript shortcuts for quick checking, there's no reason I need to manually be logging in to check them.
You used to be able to post to twitter with curl, but not since they switched to OAuth. Now the simplest way is with TTYtter, the command line Perl Twitter posting script.
Once you run TTYtter and set up your login info, you can post to Twitter using ttytter -status="blah blah blah", but I usually like setting up things to use either pipes or argument type input, plus I'll never remember the name ttytter, so I use this little script named "twit"
command | twit
or
twit blah blah blah
I set up a private twitter account and use TTYter to push various information to it. Some information comes from and hourly cron and for others that run at unexpected times, I just added "| twit" to them.
I use LauncherPro on the phone and it comes with a twitter widget. Set to update every 30 minutes, I just look at the widget to get an update on pretty much anything I may be interested in.
You used to be able to post to twitter with curl, but not since they switched to OAuth. Now the simplest way is with TTYtter, the command line Perl Twitter posting script.
Once you run TTYtter and set up your login info, you can post to Twitter using ttytter -status="blah blah blah", but I usually like setting up things to use either pipes or argument type input, plus I'll never remember the name ttytter, so I use this little script named "twit"
#! /bin/shwhich can be used in two ways:
if test -z "$1"
then
in=$(cat /dev/stdin)
ttytter -status="$in"
else
ttytter -status="$@"
fi
command | twit
or
twit blah blah blah
I set up a private twitter account and use TTYter to push various information to it. Some information comes from and hourly cron and for others that run at unexpected times, I just added "| twit" to them.
I use LauncherPro on the phone and it comes with a twitter widget. Set to update every 30 minutes, I just look at the widget to get an update on pretty much anything I may be interested in.
Monday, November 1, 2010
Simple "to do list" voice script for Tasker/voice
I had to do something at work today which required me to examine several things to see if they needed done, do something to them, and mark them off my mental list of things that needed done.
This is something that nearly everyone does on a daily basis but there were just too many items on my todo list to remember them all so I took 10 minutes and whipped up this little script which I named "list".
I created a new task in Tasker with the following actions:
1- Variable set %LIST to EOF
2- Locale Execute Plugin: @ list
3- Wait 500ms
4- Read Paragraph /sdcard/list to var %LIST
5- Flash %LIST
I set this to trigger on the keyword "list**" with the Tasker voice command I've been talking about in the last few posts. The end result is this:
I say "list add go to work"
It flashes:
go to work
I say "list add pay bills"
It flashes:
go to work
pay bills
I say "list delete work"
It flashes:
pay bills
I say "list add go on vacation"
It flashes:
pay bills
go on vacation
I say "list delete bills"
It flashes:
go on vacation
I say "list add sleep late"
It flashes:
go on vacation
sleep late
I added a line in the script to make this loopable. The line I added will add "list" to the beginning if it's not there already and execute normally. If called by the normal voice task, you still have to say "list add/delete blah blah blah" because "list" is the trigger word, but when called in a loop, you can just say "add/delete blah blah blah" and the script will recognize it. This makes it possible to keep using the list while performing your duties.
This is something that nearly everyone does on a daily basis but there were just too many items on my todo list to remember them all so I took 10 minutes and whipped up this little script which I named "list".
#! /system/bin/shThis simply adds or deletes things from a list based on whether it finds "add blah blah blah" or "delete blah blah blah" in the file at /sdcard/.voice.
grep -E -i -q "add|delete" /sdcard/.voice || exec echo sorry
grep -E -i -q "^add|^delete" /sdcard/.voice && sed -i 's/^/list /' /sdcard/.voice
COMMAND=$(awk '{ print $2}' /sdcard/.voice)
ARG=$(cut -f3- -d ' ' < /sdcard/.voice)
if [ $COMMAND == "add" ]; then
echo $ARG >> /sdcard/list
echo "Added: $ARG"
elif [ $COMMAND == "delete" ]; then
sed -i "/$ARG/d" /sdcard/list
echo "Deleted: $ARG"
fi
I created a new task in Tasker with the following actions:
1- Variable set %LIST to EOF
2- Locale Execute Plugin: @ list
3- Wait 500ms
4- Read Paragraph /sdcard/list to var %LIST
5- Flash %LIST
I set this to trigger on the keyword "list**" with the Tasker voice command I've been talking about in the last few posts. The end result is this:
I say "list add go to work"
It flashes:
go to work
I say "list add pay bills"
It flashes:
go to work
pay bills
I say "list delete work"
It flashes:
pay bills
I say "list add go on vacation"
It flashes:
pay bills
go on vacation
I say "list delete bills"
It flashes:
go on vacation
I say "list add sleep late"
It flashes:
go on vacation
sleep late
I added a line in the script to make this loopable. The line I added will add "list" to the beginning if it's not there already and execute normally. If called by the normal voice task, you still have to say "list add/delete blah blah blah" because "list" is the trigger word, but when called in a loop, you can just say "add/delete blah blah blah" and the script will recognize it. This makes it possible to keep using the list while performing your duties.
Saturday, October 30, 2010
Speech recognition on Linux, through cheating
Speech recognition on Linux is hard to come by. I've been looking for a long time and never found anything that is very useful.
Most of the solutions available are nothing more than libraries for developing speech recognition programs which require you to build your own language models. They're mostly meant to be used in other software. Many of them look like they're very well done but I'm not a credit card company looking to set up a call canter so incorporating them are well above my ability. After playing around with a few of these, I decided they were a no-go.
I was hoping there would be a solution in the cloud, like an API to Google's online voice recognition engine, but Google doesn't have one and there don't appear to be any others available either.
So I decided to cheat. All I really need is to be able to say a few simple words and have it translated to a text file. I have voice recognition on my phone that does that, so why not use it?
To avoid repeating myself, this, like everything else on my blog lately, uses ssh with keys, Tasker with the Locale Execute Plugin, the Google voice recognition API called with Python that appear in my last few posts and a short script on the phone.
The short script we need is this, which I will call "vhome" for my examples:
The "&& ..." is optional and used for executing a script on the computer which will do something with the text. This example assumes you do want to use that because I didn't pre-filter it on the phone so the file on the computer will literally contain "computer [commands to be carried out]".
The script on the computer would get rid of the first word and parse the rest for keywords linked to commands to execute. It could be as simple as one if/elif loop to look for matches and run commands. This can then be easily added to for new commands by inserting a new elif/then line for the keywords to match and commands to run.
Now it's as simple as setting up the Tasker task to trigger the script on a keyword, like "computer" for example and say "computer [commands to be carried out]".
An example of using this would be saying "computer search more common hades." The script on the computer would get rid of "computer" and using an if/then loop would recognize "search" as a keyword, read the rest of the text into a variable and run this command:
1- Write File .voice (this is used to zero out the file)
2- Run Script voice.py
3- Read Paragraph file: .voice to %VOICE
4- Goto Action 3 if %VOICE matches EOF
5- Stop If %VOICE matches halt
6- Locale Execute Plugin execute vhome If %VOICE matches computer
7 Goto 1
This task would show the voice recognition prompt. When you say "computer [commands to carry out]", it will execute vhome then show the voice recognition prompt again, unless you said "halt", in which case it dumps out of the loop and exits. Using this, you can place the phone on your desk and have voice commands at the ready.
So, that's about all. You now have speech recognition on Linux, thanks to cheating.
If you're also interested in speech synthesis on Linux, I suggest grabbing a good TTS engine like Festival and replacing the default diphone voice with a better one. Some of the most popular are the ARCTIC voices from Carnegie Mellon's Language Technologies Institute or the HTS version of those voices from the HTS working group at Nagoya Institute of Technology. The voice I use is "cmu_us_slt_arctic_hts". I haven't tried many TTS engines because Festival seems to do everything I want, especially taking text piped to it from a shell. This makes it pretty easy to set up a script that can be called to make the computer talk on certain events. You can add it to the examples above so your computer says "Yes sir, I'm opening the search results for More Common Hades."
Most of the solutions available are nothing more than libraries for developing speech recognition programs which require you to build your own language models. They're mostly meant to be used in other software. Many of them look like they're very well done but I'm not a credit card company looking to set up a call canter so incorporating them are well above my ability. After playing around with a few of these, I decided they were a no-go.
I was hoping there would be a solution in the cloud, like an API to Google's online voice recognition engine, but Google doesn't have one and there don't appear to be any others available either.
So I decided to cheat. All I really need is to be able to say a few simple words and have it translated to a text file. I have voice recognition on my phone that does that, so why not use it?
To avoid repeating myself, this, like everything else on my blog lately, uses ssh with keys, Tasker with the Locale Execute Plugin, the Google voice recognition API called with Python that appear in my last few posts and a short script on the phone.
The short script we need is this, which I will call "vhome" for my examples:
#! /system/bin/shAll this script does is place the text from the /sdcard/.voice file into a file on your computer. From my previous posts, it should be clear how Tasker/Python/Google all work together to get your words into a file on your phone and this simply gets that file to your computer.
cat /sdcard/.voice | ssh USER@IP -i /PATH/TO/SSH/KEY 'cat > /PATH/TO/A/FILE && /PC/COMMAND/SCRIPT'
The "&& ..." is optional and used for executing a script on the computer which will do something with the text. This example assumes you do want to use that because I didn't pre-filter it on the phone so the file on the computer will literally contain "computer [commands to be carried out]".
The script on the computer would get rid of the first word and parse the rest for keywords linked to commands to execute. It could be as simple as one if/elif loop to look for matches and run commands. This can then be easily added to for new commands by inserting a new elif/then line for the keywords to match and commands to run.
Now it's as simple as setting up the Tasker task to trigger the script on a keyword, like "computer" for example and say "computer [commands to be carried out]".
An example of using this would be saying "computer search more common hades." The script on the computer would get rid of "computer" and using an if/then loop would recognize "search" as a keyword, read the rest of the text into a variable and run this command:
firefox "http://www.google.com/search?q=$VAR"The biggest downside is speed. It takes about 8-9 seconds from start of the voice API to command execution on the computer. One way to make this useful may be to set up a task in Tasker that keeps looping until you say a keyword to stop it. A quick example would be:
1- Write File .voice (this is used to zero out the file)
2- Run Script voice.py
3- Read Paragraph file: .voice to %VOICE
4- Goto Action 3 if %VOICE matches EOF
5- Stop If %VOICE matches halt
6- Locale Execute Plugin execute vhome If %VOICE matches computer
7 Goto 1
This task would show the voice recognition prompt. When you say "computer [commands to carry out]", it will execute vhome then show the voice recognition prompt again, unless you said "halt", in which case it dumps out of the loop and exits. Using this, you can place the phone on your desk and have voice commands at the ready.
So, that's about all. You now have speech recognition on Linux, thanks to cheating.
If you're also interested in speech synthesis on Linux, I suggest grabbing a good TTS engine like Festival and replacing the default diphone voice with a better one. Some of the most popular are the ARCTIC voices from Carnegie Mellon's Language Technologies Institute or the HTS version of those voices from the HTS working group at Nagoya Institute of Technology. The voice I use is "cmu_us_slt_arctic_hts". I haven't tried many TTS engines because Festival seems to do everything I want, especially taking text piped to it from a shell. This makes it pretty easy to set up a script that can be called to make the computer talk on certain events. You can add it to the examples above so your computer says "Yes sir, I'm opening the search results for More Common Hades."
Monday, October 25, 2010
Voice command/Tasker errata
More natural commands
Having played around with voice commands a little after my last post, I decided my speech wasn't natural enough. Wait, what? With voice commands and speech synthesis, isn't it usually the computer that doesn't sound natural? Well in this case, it certainly doesn't feel natural to look at my phone and say "Forecast. Tuesday."
Based on the commands and tasks in my last post, I would say "forecast tuesday" and the word "forecast" would trigger the forecast task and the second word would be used to prepare the forecast for the correct day.
I've gravitated toward this solution for filtering my voice commands, when they need filtering.
5- Perform Action WXDAY if %VOICE matches forecast**
to this:
5- Perform Action WXDAY if %VOICE matches **forecast**
No big difference, but where it did depend on the first and second word before, now the first word can be anywhere in the sentence and the second word only needs to be at the end. Now "What's the forecast for friday?" or "Boy, I sure do wish my phone could tell me what the forecast is supposed to be for the day of the 29th, which just happens to be a friday" will both work and sound a lot better than "Forecast. Friday."
I'm only using the weather task as an example since it's been posted here. This can be used with any command which needs to extract a trigger and a variable from your speech.
I haven't had the need to input multiple variables yet, but I did whip up a couple scripts to give that flexibility:
I'm not sure what use this is, but I hate being constrained to only being able to use a single word so I hammered this out and put it on my sdcard in case I need it.
Another approach, if you need more flexibility, would be to say the number, and execute either of these commands:
Using this, you can say "Please google more common hades three" and using google as a keyword to open a search URL, it will input the last three words "more common hades."
Of course, this is more easily accomplished by using "google" as a variable split point and using VAR2 as the search term, but, who knows, it might come in handy for a flexible task where you need to input a different number of items on the fly without changing a handful of actions in the task.
Temp files
You may have noticed I used .voice and .voicetmp as temp files. You can bypass temp files by putting the words directly into the system clipboard by editing the Python script to this:
Now that the human side sounds better...
Oh yeah, I haven't really mentioned speech synthesis here. The only thing worth mentioning is that the best voices I've heard are made by Svox and are available in the Market. They have many voices and a free app that gives a sample of them all. I personally like the British female voice. When using Tasker, I set the tone to 6 and speed to 10 and o-la-la does she sound good.
Do I have any cool voice tasks?
Probably not. I actually have 15 tasks that are controlled by voice, but some are for controlling my home computer over ssh and are probably only interesting to me. Here are a few that may be useful. I won't post the whole task, just the idea. The rest should be easy to figure out.
Saying "pic" takes a photo.
Saying "text" runs the voice script twice more, once to get the SMS recipient, again to get the SMS body, then opens the SMS app and fills out the text.
Saying "map [address]" opens the map to the address I specify.
Saying "search [phrase]" opens google search of the phrase.
I'm trying to buy a house so saying "mls search [number]" opens the browser to http://www.realtor.com/realestateandhomes-search?mlslid=[number] to look up homes by their MLS listing.
I have all those in a separate task which the voice task executes. After that, it executes another task which is just for loading apps. I have a dozen set up to open on command, like saying "terminal" opens the terminal, saying "mail" opens gmail, etc. I haven't really used them, but it's another example of using voice control. Other voice apps can open apps by name, but how can they possibly interpret names like "BTEP" or "QuickSSHD?" Using your own voice control, you can open them by nicknames, which is much more powerful.
Having played around with voice commands a little after my last post, I decided my speech wasn't natural enough. Wait, what? With voice commands and speech synthesis, isn't it usually the computer that doesn't sound natural? Well in this case, it certainly doesn't feel natural to look at my phone and say "Forecast. Tuesday."
Based on the commands and tasks in my last post, I would say "forecast tuesday" and the word "forecast" would trigger the forecast task and the second word would be used to prepare the forecast for the correct day.
I've gravitated toward this solution for filtering my voice commands, when they need filtering.
awk '{print $NF}' /sdcard/.voice > /sdcard/.voicetmpthen changing the task from this:5- Perform Action WXDAY if %VOICE matches forecast**
to this:
5- Perform Action WXDAY if %VOICE matches **forecast**
No big difference, but where it did depend on the first and second word before, now the first word can be anywhere in the sentence and the second word only needs to be at the end. Now "What's the forecast for friday?" or "Boy, I sure do wish my phone could tell me what the forecast is supposed to be for the day of the 29th, which just happens to be a friday" will both work and sound a lot better than "Forecast. Friday."
I'm only using the weather task as an example since it's been posted here. This can be used with any command which needs to extract a trigger and a variable from your speech.
I haven't had the need to input multiple variables yet, but I did whip up a couple scripts to give that flexibility:
#! /system/bin/shYou can execute this script followed by the number of items you want to extract, or followed by nothing for extracting one item. For example, if you want to extract three items and the script is named "vfilter," you'd put "vfilter 3" in the Locale Execute Plugin then set up your task accordingly.
if test -z "$1"
then
tr ' ' '\n' < /sdcard/.voice | tail -n1 > /sdcard/.voicetmp
else
tr ' ' '\n' < /sdcard/.voice | tail -n${1} > /sdcard/.voicetmp
fi
I'm not sure what use this is, but I hate being constrained to only being able to use a single word so I hammered this out and put it on my sdcard in case I need it.
Another approach, if you need more flexibility, would be to say the number, and execute either of these commands:
#! /system/bin/shor
awk '{ for(i=$NF;(NF-i)<NF;i--) { printf "%s%s",$(NF-i),FS } printf RS }' /sdcard/.voice > /sdcard/.voicetmp
awk '{ for(i=$NF;(NF-i)<NF;i--) { printf "%s%s",$(NF-i),FS } printf RS }' /sdcard/.voice | tr ' ' '\n' > /sdcard/.voicetmpThe only difference is that the first one will output everything on one line and the second will output each word on it's own line.Using this, you can say "Please google more common hades three" and using google as a keyword to open a search URL, it will input the last three words "more common hades."
Of course, this is more easily accomplished by using "google" as a variable split point and using VAR2 as the search term, but, who knows, it might come in handy for a flexible task where you need to input a different number of items on the fly without changing a handful of actions in the task.
Temp files
You may have noticed I used .voice and .voicetmp as temp files. You can bypass temp files by putting the words directly into the system clipboard by editing the Python script to this:
import androidI toyed around with this and decided it was simpler to use files. Other tasks may set or use the clipboard and there may be something important in the clipboard that I don't want to erase by an unrelated task, and it's easier to set up tasks without worrying about backing up the clipboard every time.
droid = android.Android()
Speech = droid.recognizeSpeech()[1]
droid.setClipboard(Speech)
Now that the human side sounds better...
Oh yeah, I haven't really mentioned speech synthesis here. The only thing worth mentioning is that the best voices I've heard are made by Svox and are available in the Market. They have many voices and a free app that gives a sample of them all. I personally like the British female voice. When using Tasker, I set the tone to 6 and speed to 10 and o-la-la does she sound good.
Do I have any cool voice tasks?
Probably not. I actually have 15 tasks that are controlled by voice, but some are for controlling my home computer over ssh and are probably only interesting to me. Here are a few that may be useful. I won't post the whole task, just the idea. The rest should be easy to figure out.
Saying "pic" takes a photo.
Saying "text" runs the voice script twice more, once to get the SMS recipient, again to get the SMS body, then opens the SMS app and fills out the text.
Saying "map [address]" opens the map to the address I specify.
Saying "search [phrase]" opens google search of the phrase.
I'm trying to buy a house so saying "mls search [number]" opens the browser to http://www.realtor.com/realestateandhomes-search?mlslid=[number] to look up homes by their MLS listing.
I have all those in a separate task which the voice task executes. After that, it executes another task which is just for loading apps. I have a dozen set up to open on command, like saying "terminal" opens the terminal, saying "mail" opens gmail, etc. I haven't really used them, but it's another example of using voice control. Other voice apps can open apps by name, but how can they possibly interpret names like "BTEP" or "QuickSSHD?" Using your own voice control, you can open them by nicknames, which is much more powerful.
Subscribe to:
Comments (Atom)