Changes to speak and check4update
authorAndrew DeFaria <Andrew@DeFaria.com>
Fri, 4 Feb 2022 20:11:32 +0000 (12:11 -0800)
committerAndrew DeFaria <Andrew@DeFaria.com>
Fri, 4 Feb 2022 20:11:32 +0000 (12:11 -0800)
. Changed Speak.pm to log things and to not try to avoid two speakers
speaking at once.
. Change shh to find and kill any processes currently speaking
.Changed speak to sanitist input beforespeaking.

bin/check4update
bin/jpg [deleted file]
bin/shh
bin/speak
lib/Speak.pm

index 387f034..dc96396 100755 (executable)
@@ -9,6 +9,7 @@ systems="\
 function notify {
   #zenity --notification --text "$1" 2> /dev/null
   notify-send --expire-time=$expireTime "$1"
+  echo $1
 }
 
 function yesno {
diff --git a/bin/jpg b/bin/jpg
deleted file mode 100755 (executable)
index 69ac18e..0000000
--- a/bin/jpg
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-#
-# Simple script to save an image in the clipboard to a file
-save_file=/tmp/image.jpg
-
-xclip -selection clipboard -t image/jpeg -o > $save_file
diff --git a/bin/shh b/bin/shh
index c020f98..7e82eba 100755 (executable)
--- a/bin/shh
+++ b/bin/shh
@@ -6,11 +6,15 @@ touchfile=/opt/clearscm/data/shh
 if [ -f $touchfile ]; then
   rm $touchfile
   cp ~/.icons/ShhOff.png ~/.icons/Shh.png
-  notify-send -t $timeout "Announcements turned on"
 else
+  # Stop currently playing audio
+  killall play
+  # Stop any Google TTS
+  kill -9 $(cat /tmp/simple_google_tts.pid)
+  # Clean up tmp
+  rm -rf /tmp/simple_google_tts.*
+  # Touch shh file
   touch $touchfile
+  # Change the icon
   cp ~/.icons/ShhOn.png ~/.icons/Shh.png
-  # Note that a -t 0 will keep the notification up. This way we can
-  # be visually reminded that we are not receiving audio announcements
-  notify-send -t 0 "Announcements turned off"
 fi
index 97aceb1..7b54945 100755 (executable)
--- a/bin/speak
+++ b/bin/speak
@@ -100,4 +100,4 @@ if ($opts{clipboard}) {
   } # if
 } # if
 
-speak $msg;
+speak quotemeta $msg;
index 7003f20..c98feca 100644 (file)
@@ -83,7 +83,7 @@ Otherwise the text in the clipboard will be used.
 
 =item $log
 
-If provided, errors and messages will be logged to the logfile, otherwise stdout
+If provided, errors and messages will be logged to the logfile, otherwise to speak.log
 
 =back
 
@@ -103,13 +103,16 @@ Returns:
 
 =cut
 
+  $log = Logger->new(
+    path        => '/var/local/log',
+    name        => 'speak',
+    timestamped => 'yes',
+    append      => 1,
+  ) unless $log;
+
   if (-f "$FindBin::Bin/../data/shh") {
     $msg .= ' [silent shh]';
-    if ($log) {
-      $log->msg($msg);
-    } else {
-      verbose $msg;
-    } # if
+    $log->msg($msg);
 
     return;
   } # if
@@ -120,40 +123,15 @@ Returns:
   # Handle the case where $msg is a filehandle
   $msg = <$msg> if ref $msg eq 'GLOB';
 
-  # We can't have two speakers going at the same time so if we have an error
-  # backoff a little and try again.
-  my $attempts   = 0;
-  my $maxretries = 3;
-
-  my ($status, @output);
-
   # Log message to log file if $log was passed in.
-  $log->msg($msg) if $log;
-
-  while ($attempts++ < $maxretries) {
-    ($status, @output) = Execute "/usr/local/bin/gt \"$msg\"";
-
-    if ($status) {
-      my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output;
-
-      if ($log) {
-        $log->err($errmsg);
-      } else {
-        error $errmsg;
-      } # if
+  $log->msg($msg);
 
-      sleep int rand 10;
-    } else {
-      return;
-    } # if
-  } # while
+  my ($status, @output) = Execute "/usr/local/bin/gt \"$msg\"";
 
-  my $errmsg = 'Maximum retries exceeded - terminating';
+  if ($status) {
+    my $errmsg = "Unable to speak (Status: $status) - " . join "\n", @output;
 
-  if ($log) {
-    $log->err($errmsg, $status);
-  } else {
-    error $errmsg, $status;
+    $log->err($errmsg);
   } # if
 
   return;