[Buffalo-pm] Slashtalk - Perl Script That Will Read Slashdot For You - Window Only...

Daniel Magnuszewski dmagnuszewski at yahoo.com
Tue Apr 26 15:47:33 PDT 2005


All,

I was inspired at last weeks meeting when Kevin was saying that it would be
cool to listen to slashdot on the way to work. So I wrote a little script that
will (somewhat) do that. It's a bit of a hack job, but it basically just parses
the articles from slashdot and passes it to the Microsoft text-to-speech
utility through the Win32 module. 

Prereq: cURL - http://curl.planetmirror.com/download.html
Here's the script:

package Speech;
use Win32::OLE;

sub TIEHANDLE {
    my $voice = Win32::OLE->new('Speech.VoiceText');
    $voice->Register('', 'Perl');
    bless \$voice => shift;
}

sub PRINT {
    my $voice = shift;
    my $text = join('', @_);
    print STDOUT $text, "\n";
    $$voice->Speak($text, 0);
}

sub DESTROY {
    my $voice = shift;
    sleep(1) while $$voice->IsSpeaking;
}

package main;

$| = 1;
$/="<B>Posted by";
tie *SPEECH, 'Speech'; END {untie *SPEECH}

# Assumes that the curl.exe file is located in the current directory
system("curl.exe -s http\:\/\/slashdot.org >slashtalk.temp");
open SLASH, "slashtalk.temp" or die "can't open file\n";
@slashdot = <SLASH>;

print SPEECH "Here are the $#slashdot most current stories from slashdot.";

foreach (@slashdot) 
{
	if (/Posted by/i) 
	{
		s/<(?:[^>\'\"]*|([\'\"]).*?\1)*>//gs;
		@art = split /\n/;
		$i = 0;
		for($i=2; $i < 5; $i++) 
		{
			print SPEECH "$art[$i]\n" unless /^$/;
		}
	}
}

Everything works great on my machine, but when I tried the script on Mike's
laptop, I get the following error:

"cant call method 'Register' on undefined value at line 18"

Line 18 is:

$voice->Register('', 'Perl');

Does anyone know why this works on my machine and not on Mike's? The only
difference I can possibly see is that I'm running Win XP Pro and he's on XP
Home. Is this something that can be solved by using perl2exe? If so, can I
include the cURL files within that exe?

Thoughts?

-Dan

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Buffalo-pm mailing list