SwearPi - Using Amazon Polly to read swearing git commits

Recently I stumbled upon a twitter account called Developers Swearing @gitlost, created by by @uiri00. The bio of the account sums up what it does better than I ever could “Unfiltered commit messages containing profanity from GitHub's API”. With every tweet I read I could feel compassion towards the developer making that commit. For some odd reason I thought I’d enable mobile notifications for the account. There is something about getting a notification, looking down at my watch and seeing “fixed a whole lot of shit” and just feeling some connection with that random developer.

But do you know what would be better is if rather than text, this was audiobably played in my home office. And that is where the idea for the SwearPi came from. Project seems pretty simple and I’ve broke its tasks down into a few steps.

  1. Get some twitter API to read @gitlost
  2. Use Amazon Polly to convert that tweet to text
  3. Feel shame, for all the great things I could contribute to the world… I made this instead.

I know I want to use php for this rather than banging my head on the table working with bash scripts or python. It's simple enough and it’ll get the job done quickly. First things first though, install php and some additional packages I will need.

sudo apt-get install php7.0-cli php7.0-curl php7.0-simplexml

We'll need to install composer (https://getcomposer.org/download/) because it will be required to install Amazon SDK for php.

While we’re installing things we may as well also install mpg321 as we’ll need it to play mp3 files.

sudo apt-get install mpg321

Twitter API

Simple enough to do. Go to apps.twitter.com, create new app, create access token via the dashboard. Grab a simple library to speed up the process. I found twitter-api-php which appears to do exactly what I want. So to install it with composer

php composer.phar require j7mbo/twitter-api-php

And and from their examples this came together in about 15 seconds flat. Copying oauth_access_token, oauth_access_token_secret, consumer_key and consumer_secret from our twitter app page that we created before, finding the right API endpoint to read a users timeline, then throwing all those together gives this php script.


Now to test it in the terminal and if everything has gone to plan it'll output the 2 most recent tweets. I won't be going through the extra twitter code I am going to add but it will all be attached at the bottom and minimally commented. It's just a few extra tweaks, caching tweets, marking them as spoken, etc.

Amazon Polly

Having a raspberry Pi swear at me may get repetitive, so I'm going to use the DescribeVoices voices method to query a list of voices. Then when its time to read out a tweet, use a random voice. I'll cache this like I did with tweets and then reload it once a week. As I want more than just the Australian voices (there is only two...) I will also be listing all of the Great Britain and United States voices.

I'm not going to go into too much detail about what I am doing with Polly as its pretty simple and full source code is provided at the bottom of this post. In short, its using synthesizeSpeech to take some text to convert to an mp3 stream, which we write to a temp file with file_put_contents and then read out loud with mpg321.

All the code up until now is functional, all there is left to do is add it to a cronjob and now I have a fully functional developer powered swearing raspberry pi.

Full source code:


Leave a Reply

Your email address will not be published. Required fields are marked *

one × 3 =