@speakbot

Overview

The goal was to create a Slackbot (using slack.com) that could text-to-speech to the cleanspace on command.

Slack provides an API for automated agents (bots) and there are many ways to access the API as found here. I looked at several of the Python examples and settled on Slask as most appropriate for the job. It is very simple, well organized and easily extendible without changing any of the existing code.

Hardware

The hardware for the project is a stock Raspberry Pi model B with Raspbian. It has an ethernet and a simple headphone jack for audio output. The only other part required is an audio amplifier and speaker.

Building

  1. Set up the Raspberry Pi

  2. Install Espeak

  3. Create the slackbot on slack.com (get the access token)

  4. Install slask bot

  5. Create speakbot plugin in plugins/

  6. Make it start and restart automatically with monit

  7. Enjoy!

"""!speak <text> will speak the text"""

import re

import subprocess

def speak(m) :

print 'speak("%s")' % m

subprocess.call(['espeak', m])

return 'Spoken!'

def on_message(msg, server):

text = msg.get("text", "")

match = re.findall(r"(!speak)\s*(.+)*", text)

if not match: return

msg = match[0][1]

return speak(msg)

Launch Script:

#/bin/sh

cd /home/pi/slask-master

/usr/bin/python slask.py

/etc/monit/conf.d/speakbot.cfg

check process speakbot

matching "speakbot"

start program = "/usr/bin/nohup /bin/sh /home/pi/slask-master/speakbot.sh > /tmp/speakbot.out &"

stop program = "/usr/bin/killall slask"