Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.96 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 2,
  6. "metadata": {
  7. "collapsed": false
  8. },
  9. "outputs": [
  10. {
  11. "name": "stdout",
  12. "output_type": "stream",
  13. "text": [
  14. "True\n",
  15. "type: pubmsg, source: randallatamazon!randallatamazon@randallatamazon.tmi.twitch.tv, target: #aws, arguments: [u'hello this is an example message'], tags: []\n"
  16. ]
  17. },
  18. {
  19. "ename": "KeyboardInterrupt",
  20. "evalue": "",
  21. "output_type": "error",
  22. "traceback": [
  23. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  24. "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
  25. "\u001b[0;32m<ipython-input-2-02d00fe97ae9>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'#aws'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_connected\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 28\u001b[0;31m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_forever\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  26. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_forever\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"process_forever(timeout=%s)\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0mone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunctools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_once\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 271\u001b[0;31m \u001b[0mconsume\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfinite_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 272\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdisconnect_all\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  27. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/more_itertools/recipes.pyc\u001b[0m in \u001b[0;36mconsume\u001b[0;34m(iterator, n)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[0;31m# feed the entire iterator into a zero-length deque\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0mdeque\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;31m# advance to the empty slice starting at position n\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  28. "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jaraco/itertools.pyc\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m((_,))\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \t\"\"\"\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  29. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_once\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0msockets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msockets\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 251\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 252\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  30. "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
  31. ]
  32. }
  33. ],
  34. "source": [
  35. "import os\n",
  36. "import boto3\n",
  37. "import pyaudio\n",
  38. "import irc.client\n",
  39. "import irc.events\n",
  40. "polly = boto3.client('polly')\n",
  41. "p = pyaudio.PyAudio()\n",
  42. "\n",
  43. "def chat_handler(connection, event):\n",
  44. " print event\n",
  45. " if 'randallatamazon' in event.source:\n",
  46. " voice = 'Brian'\n",
  47. " else:\n",
  48. " voice = 'Justin'\n",
  49. " text = event.arguments[0]\n",
  50. " resp = polly.synthesize_speech(Text=text, TextType=\"text\", OutputFormat=\"pcm\", VoiceId=voice)\n",
  51. " stream = p.open(format=p.get_format_from_width(width=2), channels=1, rate=16000, output=True)\n",
  52. " stream.write(resp['AudioStream'].read())\n",
  53. " stream.stop_stream()\n",
  54. " stream.close()\n",
  55. "\n",
  56. "client = irc.client.Reactor()\n",
  57. "client.add_global_handler('pubmsg', chat_handler)\n",
  58. "server = client.server()\n",
  59. "server.connect(\"irc.chat.twitch.tv\", 6667, \"justinfan123\")\n",
  60. "server.join('#aws')\n",
  61. "print server.is_connected()\n",
  62. "client.process_forever()"
  63. ]
  64. },
  65. {
  66. "cell_type": "code",
  67. "execution_count": null,
  68. "metadata": {
  69. "collapsed": false
  70. },
  71. "outputs": [],
  72. "source": [
  73. "import os\n",
  74. "os.getenv('twitch_pass')"
  75. ]
  76. },
  77. {
  78. "cell_type": "code",
  79. "execution_count": null,
  80. "metadata": {
  81. "collapsed": false
  82. },
  83. "outputs": [],
  84. "source": [
  85. "help(irc.events.all)"
  86. ]
  87. },
  88. {
  89. "cell_type": "code",
  90. "execution_count": null,
  91. "metadata": {
  92. "collapsed": true
  93. },
  94. "outputs": [],
  95. "source": [
  96. " buf = StringIO.StringIO()\n"
  97. ]
  98. },
  99. {
  100. "cell_type": "code",
  101. "execution_count": 7,
  102. "metadata": {
  103. "collapsed": false
  104. },
  105. "outputs": [
  106. {
  107. "name": "stdout",
  108. "output_type": "stream",
  109. "text": [
  110. "True\n",
  111. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color blue for user randallatamazon', u'slots': {u'color': u'blue'}, u'sessionAttributes': {}}\n",
  112. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color kappa for user mjewl', u'slots': {u'color': u'kappa'}, u'sessionAttributes': {}}\n",
  113. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"randallatamazon's favorite color is blue\", u'slots': {}, u'sessionAttributes': {}}\n",
  114. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"yyyolk doesn't have a favorite color yet\", u'slots': {}, u'sessionAttributes': {}}\n",
  115. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"mjewl's favorite color is kappa\", u'slots': {}, u'sessionAttributes': {}}\n",
  116. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color green for user restlessnarwhal', u'slots': {u'color': u'green'}, u'sessionAttributes': {}}\n",
  117. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color yellow for user triangle_soup', u'slots': {u'color': u'yellow'}, u'sessionAttributes': {}}\n",
  118. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"restlessnarwhal's favorite color is green\", u'slots': {}, u'sessionAttributes': {}}\n",
  119. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color yellow for user yyyolk', u'slots': {u'color': u'yellow'}, u'sessionAttributes': {}}\n",
  120. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotGetColor', u'responseCard': None, u'message': u\"triangle_soup's favorite color is yellow\", u'slots': {}, u'sessionAttributes': {}}\n",
  121. "{u'slotToElicit': None, u'dialogState': u'Fulfilled', u'intentName': u'TwitchBotStoreColor', u'responseCard': None, u'message': u'I stored color now green for user yyyolk', u'slots': {u'color': u'now green'}, u'sessionAttributes': {}}\n"
  122. ]
  123. },
  124. {
  125. "ename": "KeyboardInterrupt",
  126. "evalue": "",
  127. "output_type": "error",
  128. "traceback": [
  129. "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
  130. "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
  131. "\u001b[0;32m<ipython-input-7-b16ba2068e96>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_connected\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 35\u001b[0m \u001b[0mserver\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprivmsg\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'#aws'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"HELLO, WORLD!\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 36\u001b[0;31m \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_forever\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  132. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_forever\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[0mlog\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"process_forever(timeout=%s)\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 270\u001b[0m \u001b[0mone\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunctools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpartial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_once\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 271\u001b[0;31m \u001b[0mconsume\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minfinite_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 272\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 273\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdisconnect_all\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmessage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  133. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/more_itertools/recipes.pyc\u001b[0m in \u001b[0;36mconsume\u001b[0;34m(iterator, n)\u001b[0m\n\u001b[1;32m 132\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 133\u001b[0m \u001b[0;31m# feed the entire iterator into a zero-length deque\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 134\u001b[0;31m \u001b[0mdeque\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmaxlen\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 135\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0;31m# advance to the empty slice starting at position n\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  134. "\u001b[0;32m/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jaraco/itertools.pyc\u001b[0m in \u001b[0;36m<genexpr>\u001b[0;34m((_,))\u001b[0m\n\u001b[1;32m 384\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 385\u001b[0m \t\"\"\"\n\u001b[0;32m--> 386\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0m_\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mitertools\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrepeat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 387\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 388\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  135. "\u001b[0;32m/usr/local/lib/python2.7/site-packages/irc/client.pyc\u001b[0m in \u001b[0;36mprocess_once\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0msockets\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0msockets\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 251\u001b[0;31m \u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mo\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mselect\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mselect\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msockets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 252\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprocess_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 253\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  136. "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
  137. ]
  138. }
  139. ],
  140. "source": [
  141. "import os\n",
  142. "import boto3\n",
  143. "import pyaudio\n",
  144. "import irc.client\n",
  145. "import irc.events\n",
  146. "from babylex import LexSession\n",
  147. "polly = boto3.client('polly')\n",
  148. "p = pyaudio.PyAudio()\n",
  149. "\n",
  150. "sessions = dict()\n",
  151. "\n",
  152. "def chat_handler(connection, event):\n",
  153. " message = event.arguments[0].split(\":\", 1)\n",
  154. " if len(message) > 1 and message[0].lower() == connection.get_nickname().lower():\n",
  155. " user = event.source.split('!')[0]\n",
  156. " if user not in sessions:\n",
  157. " sessions[user] = LexSession(\"TwitchChatBot\", \"$LATEST\", user)\n",
  158. " session = sessions[user]\n",
  159. " resp = session.text(message[1])\n",
  160. " print resp\n",
  161. " connection.privmsg(event.target, resp['message'])\n",
  162. "\n",
  163. "client = irc.client.Reactor()\n",
  164. "client.add_global_handler('pubmsg', chat_handler)\n",
  165. "server = client.server()\n",
  166. "server.connect(\"irc.chat.twitch.tv\", 6667, \"awslexbot\", password=os.getenv('twitch_pass'))\n",
  167. "server.join('#aws')\n",
  168. "print server.is_connected()\n",
  169. "server.privmsg('#aws', \"HELLO, WORLD!\")\n",
  170. "client.process_forever()"
  171. ]
  172. },
  173. {
  174. "cell_type": "code",
  175. "execution_count": null,
  176. "metadata": {
  177. "collapsed": false
  178. },
  179. "outputs": [
  180. {
  181. "name": "stdout",
  182. "output_type": "stream",
  183. "text": [
  184. "True\n",
  185. "<Response [200]>\n",
  186. "<Response [200]>\n",
  187. "<Response [200]>\n",
  188. "<Response [200]>\n",
  189. "<Response [200]>\n",
  190. "<Response [200]>\n",
  191. "<Response [200]>\n",
  192. "<Response [200]>\n",
  193. "<Response [200]>\n"
  194. ]
  195. }
  196. ],
  197. "source": [
  198. "import os\n",
  199. "import boto3\n",
  200. "import pyaudio\n",
  201. "import irc.client\n",
  202. "import irc.events\n",
  203. "from babylex import LexSession\n",
  204. "polly = boto3.client('polly')\n",
  205. "p = pyaudio.PyAudio()\n",
  206. "\n",
  207. "sessions = dict()\n",
  208. "\n",
  209. "def chat_handler(connection, event):\n",
  210. " message = event.arguments[0].split(\":\", 1)\n",
  211. " if len(message) > 1 and message[0].lower() == connection.get_nickname().lower():\n",
  212. " user = event.source.split('!')[0]\n",
  213. " if user not in sessions:\n",
  214. " sessions[user] = LexSession(\"TwitchChatBot\", \"$LATEST\", user)\n",
  215. " session = sessions[user]\n",
  216. " resp = session.content(message[1], \"text/plain; charset=utf-8\", \"audio/pcm\")\n",
  217. " stream = p.open(format=p.get_format_from_width(width=2), channels=1, rate=16000, output=True)\n",
  218. " stream.write(resp.content)\n",
  219. " stream.stop_stream()\n",
  220. " stream.close()\n",
  221. " connection.privmsg(event.target, resp.headers['x-amz-lex-message'])\n",
  222. "\n",
  223. "client = irc.client.Reactor()\n",
  224. "client.add_global_handler('pubmsg', chat_handler)\n",
  225. "server = client.server()\n",
  226. "server.connect(\"irc.chat.twitch.tv\", 6667, \"awslexbot\", password=os.getenv('twitch_pass'))\n",
  227. "server.join('#aws')\n",
  228. "print server.is_connected()\n",
  229. "server.privmsg('#aws', \"HELLO, WORLD!\")\n",
  230. "client.process_forever()"
  231. ]
  232. },
  233. {
  234. "cell_type": "code",
  235. "execution_count": null,
  236. "metadata": {
  237. "collapsed": true
  238. },
  239. "outputs": [],
  240. "source": []
  241. }
  242. ],
  243. "metadata": {
  244. "kernelspec": {
  245. "display_name": "Python 2",
  246. "language": "python",
  247. "name": "python2"
  248. },
  249. "language_info": {
  250. "codemirror_mode": {
  251. "name": "ipython",
  252. "version": 2
  253. },
  254. "file_extension": ".py",
  255. "mimetype": "text/x-python",
  256. "name": "python",
  257. "nbconvert_exporter": "python",
  258. "pygments_lexer": "ipython2",
  259. "version": "2.7.13"
  260. }
  261. },
  262. "nbformat": 4,
  263. "nbformat_minor": 2
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement