@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
Set up the Raspberry Pi
Install Espeak
Create the slackbot on slack.com (get the access token)
Install slask bot
Create speakbot plugin in plugins/
Make it start and restart automatically with monit
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"