3 =head1 NAME $RCSfile: Speak.pm,v $
5 Convert text to speach using Google's engine and play it on speakers
13 Andrew DeFaria <Andrew@DeFaria.com>
21 Wed 24 Feb 2021 11:05:36 AM PST
30 This module offers subroutines to convert text into speach and speak them.
34 This module exports subroutines to process text to speach and speak them.
38 The following routines are exported:
52 use lib "$FindBin::Bin/../lib";
58 our @EXPORT = qw(speak);
65 =head2 speak($msg, $log)
67 Convert $msg to speach.
69 Note this currently uses an external script to do the conversion. I intend to
70 re-write that into Perl here eventually.
74 =for html <blockquote>
80 Message to speak. If $msg is defined and scalar then that is the message
81 to speak. If it is a file handle then the text will be read from that file.
82 Otherwise the text in the clipboard will be used.
86 If provided, errors and messages will be logged to the logfile, otherwise stdout
90 =for html </blockquote>
94 =for html <blockquote>
102 =for html </blockquote>
106 if (-f "$FindBin::Bin/shh") {
117 # Handle the case where $msg is not passed in. Then use the clipboard;
118 $msg = Clipboard->paste unless $msg;
120 # Handle the case where $msg is a filehandle
121 $msg = <$msg> if ref $msg eq 'GLOB';
123 # We can't have two speakers going at the same time so if we have an error
124 # backoff a little and try again.
129 my ($status, @output);
131 while ($attempts++ < $maxretries) {
132 ($status, @output) = Execute "/usr/local/bin/gt \"$msg\"";
135 my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output;
145 return; # We said our piece...
149 my $errmsg = 'Maximum retries exceeded - terminating';
152 $log->err($errmsg, $status);
154 error $errmsg, $status;
164 =head1 CONFIGURATION AND ENVIRONMENT
166 DEBUG: If set then $debug is set to this level.
168 VERBOSE: If set then $verbose is set to this level.
170 TRACE: If set then $trace is set to this level.
176 L<File::Spec|File::Spec>
178 L<Term::ANSIColor|Term::ANSIColor>
180 =head1 INCOMPATABILITIES
184 =head1 BUGS AND LIMITATIONS
186 There are no known bugs in this module.
188 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
190 =head1 LICENSE AND COPYRIGHT
192 This Perl Module is freely available; you can redistribute it and/or
193 modify it under the terms of the GNU General Public License as
194 published by the Free Software Foundation; either version 2 of the
195 License, or (at your option) any later version.
197 This Perl Module is distributed in the hope that it will be useful,
198 but WITHOUT ANY WARRANTY; without even the implied warranty of
199 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
200 General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
203 You should have received a copy of the GNU General Public License
204 along with this Perl Module; if not, write to the Free Software Foundation,
205 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.