- Using Perl with HAL -

  

 

 

 

 

Using Perl - Page 4

 

Using Temperature with HAL

Once the PERL program is complete, test run it from the command line as we did the hello program. Then type out the file Temperature.TXT. This should look like this:

__________________________________

C:\Perl>perl temperature.pl

C:\Perl>type temperature.txt

at 9:54 pm Pacific Time the temperature was 53 degrees, according to yahoo

__________________________________

We can create several programs using Temperature.pl as a template, and retrieve all sorts of interesting weather data one item at a time. But making them available to HAL still requires some macros in HAL to operate them.

At it’s simplest, what is required is a macro that will recognize a voice command, in this case, “What is the outside temperature?” and invoke the program. This is where the new HAL v. 2 feature of being able to provide arguments to external programs becomes helpful. We tell HAL to run the PERL interpreter located in C:\perl\bin\ and pass the cmd line argument C:\perl\temperature.pl to it.

___________________________________________

MACRO Weather Temp Yahoo “What's the outside temperature”

Run Program C:\perl\bin\perl.exe {C:\perl\temperature.pl}

TTS: “Let me ask my computer buddy over at yahoo weather”

In 10 seconds Speak text File temperature.txt

In five minutes Run Program C:\bin\notemperature.bat

HAL then responds:

at 9:54 pm Pacific Time the temperature was 53 degrees, according to yahoo

___________________________________________

Unfortunately, HAL makes no provision to notify us when the program is complete. The time to access the web is variable and could be very short, or it could be fairly long, and we have no way to know when it is done. This causes us a problem, because we don’t know when to read the file. Fortunately, waiting 10 seconds and then just blindly reading the file seems to work most of the time.

Is it live or is it Memorex?

The only other remaining problem is knowing whether the data is real or not. That is, since the data stays around in a text file long after it’s spoken, we could, for example, fail to reach yahoo, and then read yesterday’s file and not know it. There is an easy fix though. Simply create a file named noyahoo.txt. In it place a line of text something like “I’m sorry, but I can’t reach yahoo right now”.

What we want to have happen is that sometime after we read out the temperature, we copy our noyahoo.txt file onto temperature.txt, This way, if the temperature program fails, HAL will tell us he couldn't get the data.

Unfortunately, HAL does not allow us to execute MSDOS commands. So we have to create a batch file which we can then have HAL run as a program. This is very easy to do, and for those not familiar with the process, see the example. I should point out that I use a special directory to hold small utilities and batch files, called C:\bin. It’s a good idea to keep these sorts of things together. Then add one more action to our Macro (shown in italics) to invoke the batch file in five minutes.

___________________________________________

Creating a batch file to overwrite the temperature file

C:\>cd \bin

C:\BIN>copy con notemperature.bat

copy noyahoo.txt temperature.txt

^Z

1 file(s) copied.

C:\BIN>

___________________________________________

What did he say?

Why wait five minutes to change the file? Actually, for the purposes we’ve discussed herein, we could invoke the batch file immediately. However, that deprives us of a valuable option, the option to ask for a repeat. I find that when others are in the house, invariably just as HAL begins to speak, someone will try to interrupt. Or the dog will bark. Or the phone ring. Or the doorbell. Or SOMETHING!

In an earlier document , I described the process of enabling remember and repeat important announcements on command. I won’t detail that process here, but rather refer the reader to the earlier document. Adding a flag, rule and a few more actions, HAL can easily repeat the reading on command.

 

 

 

 

 

 

 

 

 

Sidebar

Where do I learn more about perl?

The Comprehensive Perl Archive Network is a centralized archive for perl scripts and modules.

Anything a perl programmer might need is likely to be found at www.cpan.org

Other useful perl resources are www.perlmonks.org and of course O'Reilly's www.perl.com

Navigation

Introduction

Page 1

Page 2

Page 3

Page 4

Main Menu