Created
July 25, 2015 14:33
-
-
Save zopieux/02a17a43ac1a273514d9 to your computer and use it in GitHub Desktop.
IRC to Voxygen TTS
This file contains hidden or 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 asyncio | |
import binascii | |
import irc3 | |
import re | |
import requests | |
import subprocess | |
import time | |
VOICES = ["Helene", "Emma", "Electra", "DarkVadoor", "Damien", "Agnes", "Bicool", "Chut", "Melodine", "Ludovic", "Fabienne", "Eva", "Loic", "JeanJean", "John", "Matteo", "Michel", "Papi", "Philippe", "Ramboo", "Robot", "Sidoo", "Sorciere", "Yeti", "Zozo"] | |
URI_RE = re.compile(r'[a-z]{3,6}://[^\s]*') | |
@irc3.plugin | |
class TTSPlugin: | |
requires = [ | |
'irc3.plugins.core', | |
] | |
def __init__(self, bot): | |
self.bot = bot | |
@irc3.event(irc3.rfc.PRIVMSG) | |
def on_privmsg(self, mask=None, data=None, **kw): | |
data = URI_RE.sub('un URL', data) | |
text = "{}. {}".format(mask.nick, data) | |
voice = VOICES[binascii.crc32(mask.nick.encode('utf8')) % len(VOICES)] | |
r = requests.get('https://www.voxygen.fr/sites/all/modules/voxygen_voices/assets/proxy/index.php', params={ | |
'text': text, | |
'voice': voice, | |
'ts': int(time.time()), | |
'method': 'redirect', | |
}) | |
p = subprocess.Popen(['mpg123', '-'], stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) | |
p.communicate(r.content) | |
def main(): | |
import sys | |
nick = sys.argv[1] | |
chan = sys.argv[2] | |
loop = asyncio.get_event_loop() | |
config = { | |
'autojoins': [chan], | |
'host': 'irc.freenode.net', 'port': 7000, 'ssl': True, | |
'includes': [ | |
'irc3.plugins.core', | |
__name__, | |
], | |
'loop': loop | |
} | |
irc3.IrcBot(nick=nick, **config).run(forever=False) | |
loop.run_forever() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment