, , , , , , , , , , ,

I am in a rock band. I write the songs and play guitar. Arkwood, my debauched Belgian buddy, is the drummer. Monita – oh, my lovely Hispanic maid Monita – well, she sings backing vocals in the tone of a screeching alley cat. And then there’s Peters…

Peters is my Dutch lodger. A huge fat slob of a beast with Kentucky Fried Chicken cartons under his flabby arms and urine stains on his chinos. Nevertheless, he has a great rock voice and so is the singer of our band.

‘1-2-3-4’ I screamed, and launched into the next song on the setlist, a little ditty entitled Horseshit. Peters threw up a hand.

‘What’s the matter?’ I asked.

Arkwood replied, ‘Peters has lost his voice. He can’t sing.’

Damn. Band practice would have to be postponed. But just then, Monita had a brainwave.

‘Darling. I play The Typing Of The Dead on the laptop. Why you not do the same for Peters?’ she asked me in her thick Hispanic accent.

Created with Nokia Smart Cam

Created with Nokia Smart Cam

Of course! The Typing Of The Dead is based on the best arcade game ever – The House Of The Dead 2 – but instead of using a gun to kill the zombies, you use a keyboard. Each word you successfully type, a zombie explodes. So why not let Peters do the same thing – type words into a computer so that he can sing along with our jamming.

So here’s the Python code that will do the trick:

from audioplay import AudioPlay

audio_play = AudioPlay()

# play guitar track

while True:

    # get word from keyboard
    word = raw_input('Type a word: ')

    # sing the word

Dead simple. The code starts to play the guitar track to my song Horseshit, before dropping into a while loop. A command prompt then asks Peters to type the word he wants to sing. Then, using Text To Speech, the typed word is converted to audio and played out through the computer speakers. Peters is then asked to type another word, and so on.

Here’s the AudioPlay class, which uses Pygame to play the guitar track and provide Text To Speech:

import pygame

class AudioPlay(object):

    T2S_DICTIONARY = {"dungarees": "dungarees.wav", 
                      "horseshit": "horseshit.wav", 
                      "of": "of.wav", 
                      "over": "over.wav", 
                      "smeared": "smeared.wav", 
                      "stinking": "stinking.wav",
                      "your": "your.wav"}

    def __init__(self):

    def guitar(self, guitar_file):

        # play guitar
        guitar = pygame.mixer.Sound(guitar_file)

    def text_to_speech(self, text):

        # get sound file
        sound_file = self.T2S_DICTIONARY.get(text)

        if sound_file:
            # play sound
            sound = pygame.mixer.Sound("song/words/{}".format(sound_file))

Check out my Text To Speech using Python post for a bit of background on the text_to_speech method. My Audio with Python post has detail of playing guitar tracks.

Fantastic! Here’s Peters practicing typing along to my song Horseshit:


Whoops! He’s typed the word Smelling, which doesn’t feature in the Text To Speech dictionary. But apart from that he’s done a sterling job.

If you want to hear Peters typing along to the song, press play…

Rock on!


I used a Fender Stratocaster electric guitar. I used a Rode NT-USB microphone to capture the words and guitar.

Magix Music Maker 14 helped me record the words for my Text To Speech dictionary, as well as the guitar track. Python Tools for Visual Studio ran the code on my Windows 7 PC.

And if you want to hear an acoustic recording of my pseudo-political masterpiece Horseshit, I’ve dumped it on Myspace.