Created
December 8, 2016 15:06
-
-
Save skorotkiewicz/630ff6c35bd67d5d04221e4510c31ad7 to your computer and use it in GitHub Desktop.
IRC to Speech
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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