Use Windows' text to speech API from your Perl script

Jonathan Stowe commented on Facebook:

I hate say in any computer language that doesn’t actually make audible speaking sounds.

Well, you can use Windows’ text to speech API from Perl:

#!/usr/bin/env perl

use 5.020; # Why not?!
use strict;
use warnings;

use Win32::OLE;
$Win32::OLE::Warn = 3;

my $speaker = Win32::OLE->new('SAPI.spvoice');

while (my $line = <DATA>) {
    next unless $line =~ /\S/;
    $speaker->Speak( $line );

Flexible & Powerful

That's why we love Perl 5


Now, if you want to replace the builtin say, I am afraid you are stuck. But, even with the use 5.020; line, you could add a no feature 'say';, and define your own say function.

Additionally, the speech API understands some XML directives.