Octavian Rasnita wrote:
> Hi,
>
> I have tried the following script under Windows 2000 (probably SAPI 4), but
> it doesn't speak anything.
>
> Can you give me the right code?
This works for me and you may need to D/L the speech SDK (see notes at end):
#!perl -w --
use strict;
use Win32;
use Win32::OLE;
our %A; # get commandline switches into %A
for (my $ii = 0; $ii < @ARGV; ) {
last if $ARGV[$ii] =~ /^--$/;
if ($ARGV[$ii] !~ /^-{1,2}(.*)$/) { $ii++; next; }
my $arg = $1; splice @ARGV, $ii, 1;
if ($arg =~ /^([\w]+)=(.*)$/) { $A{$1} = $2; } else { $A{$1}++; }
}
my $XP = 0;
$XP = 1 if $^O =~ /Win32/i and Win32::GetOSName() =~ /XP/;
my $class = $XP ? "SAPI.SpVoice" : "Speech.VoiceText";
my $debug = $A{d} || 0;
my $use_tie = $A{t} || 0;
my $text = "It is now " . scalar (localtime) . "\n";
$text = join ' ', @ARGV if @ARGV;
print "XP=$XP; text=$text\n" if $debug;
if ($use_tie) {
tie *SPEECH, 'Speech'; END { untie *SPEECH; }
print SPEECH $text;
} else {
my $voice = Win32::OLE->new($class) or die "new $class: $! ($^E)";
# $voice->Register('', 'Perl');
$voice->speak($text);
}
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
package Speech;
sub TIEHANDLE {
my $voice = Win32::OLE->new($class) or die "new $class: $! ($^E)";
# $voice->Register('', 'Perl');
print "Tieing class $class to $_[0]\n" if $debug;
bless \$voice => shift;
}
sub PRINT {
my $voice = shift;
print "Speaking $text\n" if $debug;
$$voice->Speak($text, 0);
}
sub DESTROY {
my $voice = shift;
print "In destroy\n" if $debug;
if ($XP) {
my $ret = $$voice->WaitUntilDone(10000);
# print "ret=", $ret ? 'finished' : 'killed', "\n";
} else {
sleep (1) while $$voice->IsSpeaking;
}
}
__END__
Notes:
Speech SDK:
http://www.microsoft.com/speech/download/sdk51/
http://download.microsoft.com/download/speechSDK/SDK/5.1/WXP/EN-US/speechsdk51.exe
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs