Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl Reading Plain Text Documents

by LostS (Friar)
on Feb 27, 2003 at 21:16 UTC ( [id://239259]=CUFP: print w/replies, xml ) Need Help??

Again I was bored and modified some old code. Here you go... It will read any text doc you tell it to read.
#!/usr/bin/perl -w # Plain Text File Reader # Speaking version use strict; use Win32::OLE; my $voice; $voice = Win32::OLE->new("Speech.VoiceText") or die("TTS failed"); $voice->Register("", "$0"); $voice->{Enabled} = 1; $voice->{Speed}=150; my $myfile = shift; main(); sub nl { print $/; } sub main{ open (FILE, "$myfile"); my @thefile = <FILE>; close (FILE); foreach my $line (@thefile) { talk("$line"); nl(); } } sub talk{ my $line = shift; print $line,$/; $voice->Speak($line, 1); while ($voice->IsSpeaking()) { sleep 1; } }


-----------------------
Billy S.
Slinar Hardtail - Hand of Dane
Datal Ephialtes - Guildless
RallosZek.Net Admin/WebMaster

perl -le '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat +!\n"; } else { print "Thats a dog\n"; }'

Replies are listed 'Best First'.
Re: Perl Reading Plain Text Documents
by jsprat (Curate) on Feb 28, 2003 at 02:59 UTC
    How about having it read everything you copy to the clipboard! Just start this, then minimize the window. Any text you copy will be read out loud.

    #!/usr/bin/perl use warnings; use strict; use Win32::Clipboard; use Win32::OLE; my $cb = Win32::Clipboard; my $voice = Win32::OLE->new("Speech.VoiceText") or die("TTS failed"); $voice->Register("", "$0"); $voice->{Enabled} = 1; $voice->{Speed}=180; $cb->Empty(); sub say { my $text = shift; $voice->speak($text, 1); sleep 1 while $voice->IsSpeaking; } say <<SPEAK; Copy some text, and I will read it to you. Hit Control C to stop. SPEAK while (1) { my $text = $cb->GetText(); next unless length $text; say $text; $cb->WaitForChange; }

    I left this running when I copied the code to paste here - MS TTS doesn't read perl the way I do ;-)

    Oh, and once it starts speaking, it won't stop until it is done.

Re: Perl Reading Plain Text Documents
by zentara (Archbishop) on Feb 28, 2003 at 11:57 UTC
    For you linux users out there, check out "flite", flite.

    It is a pure c version of the festival speech engine, and is very fast. To read a file: "flite somefile", and it will read faster than you can. It also has a beautifully done "audible time engine" which is highly optimized to give very a realistic voice to speak the time.

      There is also a port of FLite for winCE available from the same guy that brought us PerlCE. See, it's Perl related :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found