import os, re rep = [ ('\n', ' \n'), ('\'', ''), ('_', ''), (':', ''), (';', ''), (',', ''), ('-', ''), ('D@', 'teh'), ('I2', 'eh'), ('@5', 'o'), ('I', 'i'), ('U', 'u'), ('L', 'l'), ('@', 'ah'), ('E', 'eh'), ('S', 'sh'), ('i', 'ei'), ('j', 'y'), ('N', 'n'), ('V', 'u'), ('a5', 'o'), ('Z', 'y'), ('D ', 'th '), ('D', 'd'), ('A', 'a'), ('T', 'th'), ('3', 'eh'), ('2', ''), #Fixup and contractions ('hh', 'h'), ('dy', 'j'), ('tsh', 'ch'), ('aei', 'ai'), ('eeit(?!h)', '8'), ('kee', 'kay'), ('ku', 'coo'), ('kt', 'k'), ('eah', 'eh'), ('ehk', 'ek'), ('pyu', 'pu'), ('(?<=[aeiouy])rh', 'h'), ('ah ', 'a '), ('(?<=[aeiouy])h(?=[cdfghjklmnpqrstvwxz])', ''), ('ei', 'i'), ('aa', 'ar'), ('ou', 'o'), ('yi', 'y'), ('aia', 'ia'), ('ng', 'n'), ('nm', 'hm'), ('tu', '2'), ('\n ', '\n'), ] def lolify(inputs): child_stdin, child_stdout, child_stderr = os.popen3('espeak -q -x') child_stdin.write(inputs) child_stdin.close() output = child_stderr.read() child_stderr.close() child_stdout.close() for a,b in rep: output = re.sub(a,b,output) return output.strip() if __name__ == '__main__': while True: try: line = raw_input('LOL> ') except EOFError: break print print lolify(line.rstrip()) print