Added speak_all_private_messages and the script now uses spd-say, not espeak-ng to prevent speaking over itself!

This commit is contained in:
Jeremiah Ticket 2023-10-06 08:25:21 -06:00
parent 1b04e1e429
commit f59fb1ed48
2 changed files with 27 additions and 11 deletions

View File

@ -3,7 +3,7 @@
Adds speech to some events. Adds speech to some events.
This script requires you have espeak-ng installed and in your path. This script requires you have speech-dispatcher installed and spd-say in your path.
## Usage ## Usage
Place autospeak.pl in .irssi/scripts/ Place autospeak.pl in .irssi/scripts/
@ -23,22 +23,24 @@ This install script creates the folder ~/.irssi/scripts/autorun if it doesn't ex
## Configuration ## Configuration
This script has some settings. Use the /set command to set them. This script has some settings. Use the /set command to set them.
- speech_voice <voice> - espeak-ng voice to use (default is en-us) - speech_voice <voice> - espd-say voice to use (default is en-us)
- speech_rate <digits> - speech rate in words per minute (default is 175) - speech_rate <digits> - speech rate(-100 to 100) (default is 50)
- speak_public_messages <on/off> - Speak public messages; This does not speak all messages. This only speaks when you are directly spoken to. (Default is on) - speech_module <module> - Speech dispatcher output module to use (Default is espeak-ng)
- speak_public_messages <on/off> - Speak public messages; This does not speak all messages by default. [See the next setting.] This only speaks when you are directly spoken to. (Default is on)
- speak_all_public_message <on/off> - Speak every single message reguardless of if you are mensioned or not. (Default is off)
- speak_indirect_messages - Speaks indirect messages in public channels, reguardless of where your nick sits in the message; If this if off, public messages will only pseak if directly addressed to you. (Default is off) - speak_indirect_messages - Speaks indirect messages in public channels, reguardless of where your nick sits in the message; If this if off, public messages will only pseak if directly addressed to you. (Default is off)
- speak_private_messages <on/off> - Speaks incoming private messages. (Default is on) - speak_private_messages <on/off> - Speaks incoming private messages. (Default is on)
- speak_active_window <on/off> - Speaks the currently focused window (Default is off) - speak_active_window <on/off> - Speaks the currently focused window (Default is off)
- speak_dcc_messages <on/off> - Speaks DCC messages; Notifys if a file transfer or dcc chat request. - speak_dcc_messages <on/off> - Speaks DCC messages; Notifys if a file transfer or dcc chat request.
### Explanation of Public Message Speaking ### Explanation of Public Message Speaking
This script is designed not to be very spammy. Public messages only speak when you are directly addressed, unless you have the speak_indirect_message setting on, then it speaks no matter where in the message you are mensioned. This script is designed not to be very spammy. Public messages only speak when you are directly addressed, unless you have the speak_indirect_message setting on, then it speaks no matter where in the message you are mensioned. If you want all messages spoken, enable speak_all_public_messages
#### Examples #### Examples
When only speak_public_messages is on, When only speak_public_messages is on,
"<someone> jticket: Hi there!" Will be spoken. "<someone> jticket: Hi there!" Will be spoken.
"<someone> Hi there jticket!" will not automatically be spoken. "<someone> Hi there jticket!" will not automatically be spoken.
"<someone> This is a test" Will never be spoken automatically. "<someone> This is a test" Will never be spoken automatically unless speak_all_public_messages is on.
When speak_public_messages and speak_indirect_messages is on, both will be spoken, but the last will still not be spoken. When speak_public_messages and speak_indirect_messages is on, both will be spoken, but the last will still not be spoken unless you set speak_all_public_messages to on.

View File

@ -44,8 +44,9 @@ sub speak_message {
$body = decode(ENCODING, $body); $body = decode(ENCODING, $body);
my $SpeechRate = Irssi::settings_get_int("speech_rate"); my $SpeechRate = Irssi::settings_get_int("speech_rate");
my $SpeechVoice = Irssi::settings_get_str("speech_voice"); my $SpeechVoice = Irssi::settings_get_str("speech_voice");
my $SpeechModule = Irssi::settings_get_str("speech_module");
# Speak The Message # Speak The Message
system("espeak-ng -v $SpeechVoice -s $SpeechRate \"$summary $body\"&"); system("spd-say -P important -y $SpeechVoice -r $SpeechRate -o $SpeechModule \"$summary $body\"&");
} }
# Handle incoming public messages: # Handle incoming public messages:
@ -67,12 +68,23 @@ sub message_public {
# Get the user's nick name: # Get the user's nick name:
my $user = $server->{nick}; my $user = $server->{nick};
#check to notify about all messages:
if ((Irssi::settings_get_bool('speak_all_public_messages')) == 1) {
# Get the server's tag:
my $tag = $server->{tag};
# Prepare the message body:
(my $body = $message) =~ s/^$user[\s:,]\s*//;
# Notify the user about the incoming public message:
speak_message("Message from $nick/$tag on $target:", $body);
}
# Check whether to notify the user about indirect messages: # Check whether to notify the user about indirect messages:
unless (Irssi::settings_get_bool('speak_indirect_messages')) { elsif ((Irssi::settings_get_bool('speak_indirect_messages')) == 0) {
# Ignore messages that are not explicitly addressed to the user: # Ignore messages that are not explicitly addressed to the user:
return if ($message !~ /^$user[\s:,]/); return if ($message !~ /^$user[\s:,]/);
} }
else { else {
# Ignore messages that do not mention the user: # Ignore messages that do not mention the user:
return if ($message !~ /\b$user\b/); return if ($message !~ /\b$user\b/);
} }
@ -177,10 +189,12 @@ sub dcc_chat_message {
} }
# Register configuration options: # Register configuration options:
Irssi::settings_add_int("autospeak", "speech_rate", 175); Irssi::settings_add_int("autospeak", "speech_rate", 50);
Irssi::settings_add_str("autospeak", "speech_voice", "en-us"); Irssi::settings_add_str("autospeak", "speech_voice", "en-us");
Irssi::settings_add_str("autospeak", "speech_module", "espeak-ng");
Irssi::settings_add_bool('autospeak', 'speak_private_messages', 1); Irssi::settings_add_bool('autospeak', 'speak_private_messages', 1);
Irssi::settings_add_bool('autospeak', 'speak_public_messages', 1); Irssi::settings_add_bool('autospeak', 'speak_public_messages', 1);
Irssi::settings_add_bool('autospeak', 'speak_all_public_messages', 0);
Irssi::settings_add_bool('autospeak', 'speak_indirect_messages',0); Irssi::settings_add_bool('autospeak', 'speak_indirect_messages',0);
Irssi::settings_add_bool('autospeak', 'speak_active_window', 0); Irssi::settings_add_bool('autospeak', 'speak_active_window', 0);
Irssi::settings_add_bool('autospeak', 'speak_dcc_messages', 1); Irssi::settings_add_bool('autospeak', 'speak_dcc_messages', 1);