Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Sunday November 17, 2002
03:44 AM

Perl Speak and Spell

[ #8990 ]

I made a Perl program that spoke text, then Chris Nandor improved it with his Mac::Speech module that comes with the new Mac::Carbon. You need the Developer Tools for better documentation though. It's just a Perl version of the Carbon stuff.

I have been looking for an excuse to use Robby Walker's Tie::FileHandle::MultiPlex module, which he wrote about in The Perl Review v0 i5. Now I want any output to show up on the screen as well as the speakers. (Note: IO::Tee can do the same thing).

I create a Tie::IO::Speak that speaks anything I print to its handle, SPEAK. Once I have that I multiplex output to STDOUT and SPEAK. There is an initial delay for the first spoken text, so I take care of that when I tie the handle by speaking the empty string.

If I want to have use.perl spoken to me, I simply add this stuff to my journal reader program. :)

package main;
use Tie::FileHandle::Multiplex;
tie *SPEAK, 'Tie::IO::Speak';
tie *MULTI, 'Tie::FileHandle::MultiPlex', *STDOUT, *SPEAK;
print MULTI "$_\n" for ("Starting countdown, Dr. Evil",
    reverse ( 'Blastoff', 1 .. 10 ) );
    package Tie::IO::Speak;
    use Mac::Speech;
    my $voice   = $Mac::Speech::Voice{Victoria};
    my $channel = NewSpeechChannel($voice);
    SpeakText( $channel, '' );
        my $class = shift; bless {}, $class;
    sub PRINT
        my $self = shift;
        SpeakText( $channel, $_[0] );
        sleep 1 while SpeechBusy();
    sub PRINTF
        my $self = shift;
        $self->PRINT( sprintf @_ );
    sub DESTROY { DisposeSpeechChannel($channel) }