http://qs321.pair.com?node_id=181481

Massyn has asked for the wisdom of the Perl Monks concerning the following question:

I'd like to use Microsoft TTS in Perl. Can someone provide me some sample code on how to use it?

Replies are listed 'Best First'.
Re: Text-to-speech in Perl
by Beatnik (Parson) on Jul 13, 2002 at 14:47 UTC
    Note: This example is HEAVILY based on the AgentChat script available somewhere in this monastery.
    #!/usr/local/bin/perl -w use Win32::OLE; use Win32::OLE::Variant; $sound="Yup"; use vars qw($Agent); use vars qw(%Languages $VERSION); %Languages = ( English => 0x0409, French => 0x040C, German => 0x0407, Italian => 0x0410, Portuguese => 0x0816, Spanish => 0x0C0A, Dutch => 0x0413, ); Win32::OLE->Initialize(Win32::OLE::COINIT_MULTITHREADED); $Agent = Win32::OLE->new('Agent.Control.2') or die Win32::OLE->LastErr +or(); $Agent->{Connected} = Variant(VT_BOOL, 1); $Agent->Characters->Load('Merlin','merlin.acs') or die Win32::OLE-> +LastError(); $Characters{agent} = $Agent->Characters('Merlin'); $Characters{agent}->{LanguageID}=$Languages{English}; $Characters{agent}->Show; $Characters{agent}->Play("Greet"); $Characters{agent}->Speak("Hallo"); $Characters{agent}->Speak("The quick brown fox jumps over the lazy dog +."); $Characters{agent}->Speak("She sells sea shells on the sea shore."); $Characters{agent}->Speak("There's more than one way to do it."); $Characters{agent}->Hide;
    No credits for me. t0mas++

    Greetz
    Beatnik
    ...Perl is like sex: if you're doing it wrong, there's no fun to it.
Re: Text-to-speech in Perl
by cjf (Parson) on Jul 13, 2002 at 17:33 UTC
Re: Text-to-speech in Perl
by shotgunefx (Parson) on Jul 14, 2002 at 09:33 UTC
    Not sure how you get a list of voices programmatically but here is an old script I dug up.
    #/usr/bin/perl -w use strict; use Win32::OLE; my ($voice); &Init_Voice(); &Talk("STARTING"); print "\nType something!\n"; while (my $aa = <STDIN>){ print "\nType something!\n"; chomp $aa; &Talk($aa); } sub Init_Voice{ $voice = Win32::OLE->new("Speech.VoiceText") or die("TTS failed"); $voice->Register("", "$0"); $voice->{Enabled} = 1; # optional $voice->{Speed}=150; return $voice; } sub Talk{ my $info = shift; return unless $info; $voice->Speak($info, 1); while ($voice->IsSpeaking()) { sleep 1; } return; } END{ sleep(3); }

    Update
    You might want to check out Talking Winamp RF remote control, or Voice_Text.pm that comes with Mister House and the documentation for the newest version of MS TTS. which can be obtained here

    -Lee

    "To be civilized is to deny one's nature."