Skip to content

Instantly share code, notes, and snippets.

@zopieux
Created July 25, 2015 14:33
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 zopieux/02a17a43ac1a273514d9 to your computer and use it in GitHub Desktop.
Save zopieux/02a17a43ac1a273514d9 to your computer and use it in GitHub Desktop.
IRC to Voxygen TTS
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