### speak.pl (c) 2006 Petr Baudis <pasky@ucw.cz>
#
## Let irssi speak aloud (using speechd) chat messages.
#
# You need to install speechd. Your distribution should have it. Setup it
# (or the desired backend, likely Festival) to use the desired language.
#
#
## Options:
#
# speech_channels -> space-separated list of channels for which the acustic output is enabled.
#                    ~ means private messages
#
## See http://pasky.or.cz/~pasky/dev/irssi/ for the latest version.
#
## $Id: operit.pl,v 1.10 2002/11/29 16:51:46 pasky Exp pasky $
#
# $Log: operit.pl,v $
#

use strict;

use vars qw($VERSION %IRSSI $rcsid $changed);
$rcsid = '$Id: operit.pl,v 1.10 2002/11/29 16:51:46 pasky Exp pasky $';
($VERSION, $changed) = $rcsid =~ / (\d+\.\d+) (\d+\/\d+\/\d+) /;
%IRSSI = (
    name        => 'speak',
    authors     => 'Petr Baudis',
    contact     => 'pasky@ucw.cz',
    description => 'Allows you to let irssi speak aloud (using speechd) chat messages.',
    license     => 'BSD',
    url         => 'http://pasky.or.cz/~pasky/dev/irssi',
    changed     => $changed,
);

use Irssi;
use Irssi::Irc;

sub event_privmsg {
  my ($server, $data, $nick, $address) = @_;
  my ($msgtarget, $text) = split(/ :/, $data, 2);
  my (@channels) = split(/\s+/, Irssi::settings_get_str('speech_channels'));

  return unless (grep {s/^~$/$server->{nick}/x; $_ eq $msgtarget} @channels);

  # You want to change this..?
  $text =~ s/:.?\)/haha/g;
  $text =~ s/:.?\(/fòuk/g;
  # TODO: more transformations? User transformations!

  local $| = 1;

  print SPEECH "$nick! $text\n";
}

Irssi::signal_add("event privmsg", "event_privmsg");

Irssi::settings_add_str($IRSSI{'name'}, 'speech_channels', '');

Irssi::print("Speak $VERSION loaded: see the source header for help.");

open SPEECH, ">/dev/speech" or die "Cannot open /dev/speech: $!";
