I’ve got a post about (chirp), but this is about the HackNY Spring 2015 Hackathon winner:
GLaPEP8 is best explained with a demo video:
GLaPEP8 checks a file’s Python syntax and sings the error to you in the style of GLaDOS singing Still Alive in the closing credits of Portal.1 I started building this because I wanted to play around with OS X2’s speech synthesis. I’d guess a fair proportion of Mac users know that you can use the command ‘say’ thus:
But the speech synthesis engine in OS X is actually really quite sophisticated and controllable. The interesting thing for our purposes is that you can include commands in the text which let you control various aspects of the synthesised voice, including prosody and tone. I’ve messed around with this before for livecoding purposes, but I didn’t really grok the TUNE format, which gives you the most control — and, as it turns out, I needed very fine-grained control for GLaPEP8.
Basically, you can provide ‘say’ with a list of syllables, and for each of them specify how long to say it for, and at which frequency. The format is called ‘TUNE’, and looks like this:
I only need a subset of the features for GLaPEP8, so the only things I’ll change are the syllables, the number after ‘D’ (the duration in ms), and the number after ‘P’ (the pitch at time 0 of the syllable).
Supplying individual syllables is not super convenient, so I started off trying to use the standard ‘TEXT’ input format. In that mode, you can also specify the pitch like so:
‘69’ is the MIDI number of the frequency you want, and ‘[[ pmod 0]]’ makes the pronunciation monotone. I couldn’t use this for GLaPEP8 because there’s no way of specifying how long it should take to say a word, so they sound rhythmically weird. You can specify the rate in words-per-minute, but to convert that a note duration in milliseconds to a rate you also need to know in advance how long it would take to say the word!
The problem with providing a syllable-level pronunciation guide is that OS X Speech Synthesis uses a phoneme list which is, as far as I can tell, a non-standard version of Arpabet. I’m converting words to the component phonemes of their pronunciations using CMUdict (the Carnegie Mellon Pronouncing Dictionary), which does use Arpabet, so GLaPEP8 ends up converting words to Arpabet phonemes, then to OS X-style phonemes, then to audio.
The vast majority of the work went into getting OS X to sing like Ellen McLain, but I also used flake8 to find the PEP8 violations in the code, python-midi to read in the melody and the python ncurses library to make an interface like Portal’s end credits. For a little bit more 2010-retro-futuristic chic, I demoed GLaPEP8 inside the vintage terminal emulator Cathode.
I started work on GLaPEP8 quite late, and I realised it might actually be worth finishing even later. There are consequently some very rough edges I’d like to fix, such as:
- It only really works for one-syllable words
- Each syllable within a word is pronounced for the same duration, because ‘say’ doesn’t, as far as I can tell, return the information it uses to determine the length of each syllable
- The lyrics it sings are pretty much fixed, so it only works properly on the demo file. I think I can make it more dynamic with some creativity, but the first two problems need to be fixed first
I think I’m going to spin off the text-to-song part of GLaPEP8 into its own project, because I can see myself re-using that (notably for livecoding). I also remain interested in error messages – to the extent that my PhD dissertation is going to spend quite some time on them, albeit in a slightly more academic context.