From 44c8e829dbc847c9e1a6e1be87e0bfea37048fbc Mon Sep 17 00:00:00 2001 From: Ritchie Cunningham Date: Sat, 7 Jun 2025 15:59:29 +0100 Subject: [PATCH] Daemonized tts process to prevent text blocking. --- fnotify.pl | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/fnotify.pl b/fnotify.pl index 798c107..ca96cbb 100644 --- a/fnotify.pl +++ b/fnotify.pl @@ -2,7 +2,7 @@ use strict; use Irssi; use vars qw($VERSION %IRSSI); -$VERSION = "3.0-themeproof"; +$VERSION = "3.1-daemonise"; %IRSSI = ( authors => 'Ritchie Cunningham', contact => 'ritchie@ritchiecunningham.co.uk', @@ -24,9 +24,25 @@ sub notify { system("notify-send", "-i", "irssi", $title, $message); if (Irssi::settings_get_bool('festival_enabled')) { - my $text = "$title. $message"; - $text =~ s/[^A-Za-z0-9\s,.]//g; # Sanitize for festival. - system("echo '$text' | festival --tts --language english --pipe &"); + my $text_to_speak = "$title, $message"; + + # Fork the process to prevent Irssi from freezing while festival speaks. + # :oop: Actually, we're going to have to double-fork to prevent + # festival from changing the parent into some raw mode. + # + # FINE!! Go screw yourself! as neither forking, nor double-forking worked out + # we'll use systemd-run for a guaranteed detachment. + # This will offload the entire backgrounding task to the systemd service + # manager. + + # We need to escape any single quotes in the text.. + # Sorry @dacav, tried to use your open() suggestion, but as we can't + # daemonise using the fork solution, we have to manually prevent shell injection. + $text_to_speak =~ s/'/'\\''/g; + + my $command = "echo '$text_to_speak' | festival --tts --language english --pipe"; + + system("systemd-run", "--user", "--quiet", "--no-ask-password", "/bin/sh", "-c", $command) } }