Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Created December 8, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorotkiewicz/630ff6c35bd67d5d04221e4510c31ad7 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/630ff6c35bd67d5d04221e4510c31ad7 to your computer and use it in GitHub Desktop.
IRC to Speech
import socket, string, os, re, time
#some user data, change as per your taste
SERVER = 'irc.freenode.net'
PORT = 6667
NICKNAME = 'MsgToSpeech'
CHANNEL = '#itunix-eu'
#open a socket to handle the connection
IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#open a connection with the server
def irc_conn():
IRC.connect((SERVER, PORT))
#simple function to send data through the socket
def send_data(command):
IRC.send(command + '\n')
#join the channel
def join(channel):
send_data("JOIN %s" % channel)
#send login data (customizable)
def login(nickname, username='user', password = None, realname='Pythonist', hostname='Helena', servername='Server'):
send_data("USER %s %s %s %s" % (username, hostname, servername, realname))
send_data("NICK " + nickname)
irc_conn()
login(NICKNAME)
join(CHANNEL)
while (1):
buffer = IRC.recv(1024)
msg = string.split(buffer)
if msg [1] == 'PRIVMSG':
message = ' '.join(msg[3:])
print message
os.system('espeak -v en "{0}" --stdout | aplay 2>/dev/null >/dev/null'.format(message)) #speech this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment