in reply to speak to me!
#!/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; }
|
|---|