Daemonized tts process to prevent text blocking.
This commit is contained in:
parent
a25b527804
commit
44c8e829db
24
fnotify.pl
24
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user