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:
51 use lib "$FindBin::Bin/../lib";
57 our @EXPORT = qw(speak);
64 =head2 speak($msg, $log)
66 Convert $msg to speach.
68 Note this currently uses an external script to do the conversion. I intend to
69 re-write that into Perl here eventually.
73 =for html <blockquote>
79 Message to speak. If $msg is defined and scalar then that is the message
80 to speak. If it is a file handle then the text will be read from that file.
81 Otherwise the text in the clipboard will be used.
85 If provided, errors and messages will be logged to the logfile, otherwise stdout
89 =for html </blockquote>
93 =for html <blockquote>
101 =for html </blockquote>
105 if (-f "$FindBin::Bin/shh") {
107 $log->msg("Not speaking because we were asked to be quiet - $msg");
109 verbose "Not speaking because we were asked to be quiet - $msg";
115 # Handle the case where $msg is a filehandle
116 $msg = <$msg> if ref $msg eq 'GLOB';
118 # We can't have two speakers going at the same time so if we have an error
119 # backoff a little and try again.
124 my ($status, @output);
126 while ($attempts++ < $maxretries) {
127 ($status, @output) = Execute "/usr/local/bin/gt \"$msg\"";
130 my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output;
140 return; # We said our piece...
144 my $errmsg = 'Maximum retries exceeded - terminating';
147 $log->err($errmsg, $status);
149 error $errmsg, $status;
159 =head1 CONFIGURATION AND ENVIRONMENT
161 DEBUG: If set then $debug is set to this level.
163 VERBOSE: If set then $verbose is set to this level.
165 TRACE: If set then $trace is set to this level.
171 L<File::Spec|File::Spec>
173 L<Term::ANSIColor|Term::ANSIColor>
175 =head1 INCOMPATABILITIES
179 =head1 BUGS AND LIMITATIONS
181 There are no known bugs in this module.
183 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
185 =head1 LICENSE AND COPYRIGHT
187 This Perl Module is freely available; you can redistribute it and/or
188 modify it under the terms of the GNU General Public License as
189 published by the Free Software Foundation; either version 2 of the
190 License, or (at your option) any later version.
192 This Perl Module is distributed in the hope that it will be useful,
193 but WITHOUT ANY WARRANTY; without even the implied warranty of
194 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
195 General Public License (L<http://www.gnu.org/copyleft/gpl.html>) for more
198 You should have received a copy of the GNU General Public License
199 along with this Perl Module; if not, write to the Free Software Foundation,
200 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.