Skip to content

Instantly share code, notes, and snippets.

@eqhmcow
Last active October 13, 2015 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eqhmcow/4243193 to your computer and use it in GitHub Desktop.
Save eqhmcow/4243193 to your computer and use it in GitHub Desktop.
irc espeak replacer for fox
$ cat test.txt
18:36 <@Dop> also fox_1: the scottish accent isn't too bad but you need to slow it down quite a bit to get the full effect
18:37 <@fox_1> still need to tweak a little
18:37 <@fox_1> right now you're a female scot for example I think
18:37 <@Dop> och aye? rofl
18:38 <@fox_1> ;)
18:55 <@ytz> lol
18:56 <@fox_1> that was the facebook fight
18:56 <@ytz> time to assemble coffee before the main card
18:56 <@fox_1> yeah I got rockstar
18:56 -!- gurudwara [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has joined #fop
19:35 <@HighBit> yay I finally got an upvote for my apache access log parser regex
19:35 <@HighBit> http://stackoverflow.com/questions/2221636/regex-for-apache-logs-in-php/7012726#7012726 too
19:55 <@HighBit> afk
19:57 -!- gru [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has quit [Ping timeout: 311 seconds]
20:02 -!- gurudwara [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has quit [Ping timeout: 272 seconds]
20:04 <@fox_1> lj made yummy cookies
20:05 <@HighBit>:) hello
$ cat test.txt | perl replacer.pl --debug 2>/dev/null
espeak -v en+m4 -s 130 -b 1 dop
espeak -m -v en-sc -s 120 -p 50 -b 1 also fox_1: the scottish accent isn't too bad but you need to slow it down quite a bit to get the full effect
espeak -v en+m4 -s 130 -b 1 dop
espeak -m -v en-sc -s 120 -p 50 -b 1 och aye? roll on floor laughing
espeak -v en+m4 -s 130 -b 1 yitz
espeak -m -v mb-us2 -s 125 -p 50 -b 1 laugh out loud
espeak -v en+m4 -s 130 -b 1 yitz
espeak -m -v mb-us2 -s 125 -p 50 -b 1 time to assemble coffee before the main card
espeak -v en+m4 -s 130 -b 1 highbit
espeak -m -v mb-de4-en -s 122 -p 40 -b 1 yay I finally got an upvote for my apache access log parser regex
espeak -v en+m4 -s 130 -b 1 highbit
espeak -m -v mb-de4-en -s 122 -p 40 -b 1 too
espeak -v en+m4 -s 130 -b 1 highbit
espeak -m -v mb-de4-en -s 122 -p 40 -b 1 away from keyboard
espeak -v en+m4 -s 130 -b 1 highbit
espeak -m -v mb-de4-en -s 122 -p 40 -b 1 smiles hello
jstizzle,, mb-fr4-en, 110, 75
!HighBit,, mb-de4-en, 122, 40
ytz, yitz, mb-us2 , 125
Dop,,en-sc ,120
Thwibble,, mb-af1-en,
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
# hot pipes
$|++;
my $debug = ''; # option variable with default value (false)
GetOptions ('debug' => \$debug);
# load nicks to be replaced
open (my $nicks, '<', 'nicks.txt');
my (%n, %nr, %ns, %np, %ni);
# Nick, replacement, voice, speed,pitch (see espeak man)
# e.g.
# jstizzle,, en+f4,,75
# OR
# HighBit,, en+m5, 120,50
# OR
# ytz, yitz, en+m3, 115,40
while (<$nicks>) {
chomp;
my ($n, $r, $v, $s, $p) = split(m/\s*,\s*/);
$n = lc($n);
if ($n =~ m/^!/) {
$n =~ s/^!//;
$ni{$n}++;
next;
}
$nr{$n} = $r || $n;
$n{$n} = $v;
$ns{$n} = $s;
$np{$n} = $p;
}
# load special characters and words list for replacement
open (my $thesaurus, '<', 'thesaurus.txt');
my %t;
# search for word, replacement term
# e.g.
# :) , smiles
# rofl, roll on floor laughing
while (<$thesaurus>) {
chomp;
my ($t1, $t2) = split(m/\s*,\s*/);
$t{lc($t1)} = $t2;
}
# read each line and add the voice
# e.g.
# 21:16 -!- mode/#fop [+o fox_1] by HighBit
# 22:17 <@fox_1> oh, did you see my filters
my $last_nick = '';
my $last_time = 0;
while (<>) {
chomp;
# ignore non-chat lines
next unless m/^\d/;
# chop off initial timestamp
s/^.{8}//;
# ignore server message lines starting with -!-
next if m/^-/;
# grab the nick
my ($n) = (m/^([^>]+)>/);
# remove trailing underscores
$n =~ s/_+$//;
$n = lc($n);
# skip ignored nicks
next if $ni{$n};
# Loading up the voice file,speed,pitch from their hashes
my $v = $n{$n};
my $s = $ns{$n};
my $p = $np{$n};
# swapping the nick for the replacement nick now that we are done
# using it as a key
$n = $nr{$n} || $n;
# default voice if we don't have a match
$v ||= "en-us";
# default speed
$s ||= "130";
# default pitch
$p ||= "50";
# build the line
s/^[^>]+>\s*//;
#attempt to prevent dash as first character espeak reads
s/^-/&#45;/x;
#attempt to filter urls
s!https?://\S+!!;
# find replace with custom thesaurus file
my $l = $_;
my @words = split(/\s+/, $l);
foreach my $word (@words) {
my $r = $t{lc($word)};
next unless $r;
$word = $r;
}
# reassemble string
$l = join(" ",@words);
# setup line to be spoken
$l = qq!$l!;
# don't repeat nick if it was just said
if ($last_nick ne $n or time() - $last_time > 120) {
system("espeak", "-v", "en+m4", "-s", "130","-b", "1", "$n");
}
$last_nick = $n;
$last_time = time();
system("espeak", "-m" ,"-v","$v", "-s","$s","-p", "$p","-b","1", "$l");
if ($debug == 1) {
print("espeak ", "-v ","en+m4 ", "-s ", "130 ","-b ", "1 ", "$n\n");
print("espeak ", "-m " ,"-v ","$v ", "-s ","$s ","-p ", "$p ","-b ","1 ", "$l\n");
}
}
18:36 <@Dop> also fox_1: the scottish accent isn't too bad but you need to slow it down quite a bit to get the full effect
18:37 <@fox_1> still need to tweak a little
18:37 <@fox_1> right now you're a female scot for example I think
18:37 <@Dop> och aye? rofl
18:38 <@fox_1> ;)
18:55 <@ytz> lol
18:56 <@fox_1> that was the facebook fight
18:56 <@ytz> time to assemble coffee before the main card
18:56 <@fox_1> yeah I got rockstar
18:56 -!- gurudwara [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has joined #fop
19:35 <@HighBit> yay I finally got an upvote for my apache access log parser regex
19:35 <@HighBit> http://stackoverflow.com/questions/2221636/regex-for-apache-logs-in-php/7012726#7012726 too
19:55 <@HighBit> afk
19:57 -!- gru [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has quit [Ping timeout: 311 seconds]
20:02 -!- gurudwara [~gurudwara@c-71-239-178-9.hsd1.in.comcast.net] has quit [Ping timeout: 272 seconds]
20:04 <@fox_1> lj made yummy cookies
20:05 <@HighBit>:) hello
lol , laugh out loud
rofl , roll on floor laughing
afk , away from keyboard
bbiab , be back in a bit
bbiaw , be back in a while
:) , smiles
;) , winks
:( , frowns
:p , sticks tongue out
;p , sticks out tongue
:P , stick my tongue out
;P , crazy face
ffs , for futzs sake
pos , piece of scrap
brb , be right back
yea , yeah
:< , very sad
:> , very happy
rgr , roger
wtf , what the frell
... , dot dot dot
;( , frowns
:D , big smile
8) , google lee eyes
w/ , with
omg , oh my gee
l8r , later
r , are
teh , the
btw , by the way
cya , see ya
@triangletodd
Copy link

lol

@triangletodd
Copy link

It's been 3 months since I've seen this and I had forgotten it. I lol'd again. Crazy and bored as a bear.

@eqhmcow
Copy link
Author

eqhmcow commented Mar 21, 2013

@toddedw I wrote this cuz fox asked me to, I like making things for people and stuff :)

note that fox also contributed to it greatly as well

@triangletodd
Copy link

I know. I was at your house while you were working on it, but it's still humorous to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment