The Typing Of The Horseshit

Tags

, , , , , , , , , , ,

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 sing 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
audio_play.guitar('song/horseshit_guitar.wav')

while True:

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

    # sing the word
    audio_play.text_to_speech(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):
        pygame.mixer.init()

    def guitar(self, guitar_file):

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

    def text_to_speech(self, text):
        
        # debug
        print text + "\n"

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

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

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:

TheTypingOfTheHorseshit_Output

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, check out the file TheTypingOfTheHorseshit.wav in my repository.

Rock on!

P.S.

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.

Follow

Get every new post delivered to your Inbox.

Join 72 other followers