Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

speak to me!

by batkins (Chaplain)
on Jan 07, 2003 at 00:17 UTC ( [id://224799]=CUFP: print w/replies, xml ) Need Help??

If this isn't a cool use for perl, then by god, I don't know what is. This script uses Microsoft's Speech API http://www.microsoft.com/speech to say whatever you tell it to. I found this originally on Progressive Perl (don't have a link) and fooled around with it. It is by no means my own code. The speech, however, was created by myself and primus.

use Win32::OLE qw( EVENTS ); my $DirectSS = new Win32::OLE( "{EEE78591-FE22-11D0-8BEF-0060081841DE}" ); $DirectSS->Speak("Good evening, Mr. Anderson. How's your day been? G +oooood. Well, listen, I'm going to have to ask you to be assimilated + into the Borg because, yeah, resistance is futile. Oh, and about th +ose TPS reports. Yeah, didja get that memo? You see, we're putting +new cover sheets on all our TPS reports. By the way, I've taken the +liberty of searching, searching, searching out. your domain controlle +rs. It seems they're named charles and michael. or should i say, we +re? cuz now they're pete and repeat. yeah. how do you like that? +by the way, if pete and repeat are in a boat and pete jumps out, who's left? Ok, i'll say it again. if pete and repeat are in a boat +and pete jumps out, who's left? that was a little borg humor for you +. most people don't know about it, but we can be a regular barrel of + laughs when we want to. and remember: anything is possible, except +skiing through a revolving door. Because then where would we be? no +where, that's where. by the way, you're logged in as " . getlogin . +". We Borg know that kind of stuff. It's what we do, so we have to +be good at it. and we are. we're really good. really good. really +, really good. in fact, so good that we know that everything about yo +ur computer. everything. have a pleasant remainder of your day. ch +eers from the borg. "); while( $DirectSS->{Speaking} ) { Win32::OLE->SpinMessageLoop(); Win32::Sleep( 100 ); }
This code runs on Windows 2000. It doesn't seem to work on my XP Pro box, but the docs say it's supposed to work on ME, XP Home, XP Pro, and 2000. Then again, maybe I shouldn't trust Microsoft documentation....

Anyways, if you're running 2000, give this a shot. And if you're running some other flavor of windows and you get it to work anyway, comment here so the rest of us can figure it out. :)

Some parts of this really have to be heard to appreciate. Listening to Sam (the primary M$oft voice) say "searching, searching, searching out. your domain controllers" is a whole lot better to hear than to read.

Update: The trick to using this on XP is to download the SAPI 4.0 from Microsoft's Speech site.

Here's a Tk program that will say whatever you tell it:

use Win32::OLE qw( EVENTS ); use Tk; my $DirectSS = new Win32::OLE( "{EEE78591-FE22-11D0-8BEF-0060081841DE} +" ) or die "$!"; $mw = MainWindow->new(-title => "the BATKINS speaker"); my $text = $mw->Text->pack; $text->focus; $mw->Button(-text => 'say it', -command => sub { say($text->get("0.0", + "end")); })->pack; MainLoop; sub say { my $say = shift; $DirectSS->Speak($say); while( $DirectSS->{Speaking} ) { Win32::OLE->SpinMessageLoop(); Win32::Sleep( 100 ); } }

For added fun, tell this program to say "he. a-he. a-he-he-he."

Replies are listed 'Best First'.
Re: speak to me!
by shotgunefx (Parson) on Jan 07, 2003 at 09:51 UTC
    This works on 98
    #!/usr/bin/perl use warnings; use strict; use Win32::OLE::Variant; sub init_voice{ my $voice = Win32::OLE->new("Speech.VoiceText") or die("TTS failed"); $voice->Register("", "$0"); $voice->{Enabled} = 1; return $voice; } sub talk{ my ($voice,$text) = @_; return unless $text; return unless $voice->{Enabled}; $voice->Speak($text, 1); while ($voice->IsSpeaking()) { sleep .5; } } sub blab{ my ($voice, $status) = @_; if ($status){ $voice->{Enabled} = 1; talk($voice, "Start yapping."); }else{ talk($voice, "Shutting up."); $voice->{Enabled} = 0; } } my $voice = init_voice(); print "Enter quit to exit.\n"; { print "Enter text:\n"; my $text = <STDIN>; chomp($text); blab($voice,0) if $text eq 'shutup'; blab($voice,1) if $text eq 'talk'; last if $text eq 'quit'; talk($voice,$text); redo; }


    -Lee

    "To be civilized is to deny one's nature."
Re: speak to me!
by boo_radley (Parson) on Jan 07, 2003 at 08:30 UTC
    this seems to be the correct answer under Windows ME
Re: speak to me!
by Nitrox (Chaplain) on Feb 01, 2003 at 20:41 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://224799]
Approved by Aristotle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found