, , , , , , , , , , , , ,

I am Scottish. Arkwood is Belgian. Yesterday, he said, ‘I can never understand a word you say. It all sounds Greek to me.’

I told him to go fuck himself. He understood that clearly enough. Crystal clear. We started to punch each other in the groinal region.

‘Okay, okay!’ I exclaimed, gasping for air, ‘I will get one of my robots to teach you Scottish.’

I will add a new feature to SaltwashAR – a Python Augmented Reality application – so as to translate phrases spoken by Arkwood into Scots tongue, which Sporty Robot can then speak back to him. My Belgian chum will soon rant forth like a Highlander.

Here’s the phrasetranslation.ini config file, which matches Arkwood’s spoken phrases to translated Scottish sound files:


As you can see, there are only two phrases to start with: “Can we eat” and “Time for bed”. We can easily add more phrases and associated sound files in due course.

And here’s the Python code for the new Phrase Translation feature:

from features.base import Feature
import ConfigParser
import pygame

class PhraseTranslation(Feature):

    FILE_PATH = 'scripts/features/phrasetranslation/'

    def __init__(self, speech_to_text):
        self.is_speaking = False
        self.speech_to_text = speech_to_text
        self.phrases = self._load_config()

    # load phrases from config
    def _load_config(self):
        config = ConfigParser.ConfigParser()

        return dict(config.items('Phrases'))
    def _thread(self, args):
        # user speaks a phrase
        phrase = self.speech_to_text.convert()
        if not phrase: return

        # check whether to stop thread
        if self.is_stop: return

        # translator replies
        phrase = phrase.replace(' ', '').lower()
        sound_file = self.phrases.get(phrase)
        if sound_file:

            sound = pygame.mixer.Sound('{}{}'.format(self.FILE_PATH, sound_file))
            channel = sound.play()

            self.is_speaking = True

            while channel.get_busy():

            self.is_speaking = False

We inherit from the Feature base class, which provides the Phrase Translation’s threading functionality (all features run in threads, so as not to block the main OpenGL process from rendering to screen).

Our __init__ method is passed a Speech To Text class, which will allow Arkwood to speak to the robot via the computer microphone. We load the phrases from config into a dictionary, and we initialize Pygame (which will be used to play the Scottish sound files).

The _thread method is where all the shit happens, as a bus conductor would say.

First, the Speech To Text class picks up the phrase Arkwood has uttered into the mic.

Once done, we check whether the thread should be stopped (which is the case if Sporty Robot is no longer in front of the webcam).

Now we get to translating Arkwood’s phrase into Scots tongue. If we find the phrase in the dictionary, we use Pygame to load the associated sound file and play it through the computer speakers. Whilst the Scottish words ring out, the is_speaking class variable is set to True so that Sporty Robot knows to move his mouth.

And that is it! The robot is able to teach Arkwood how to speak – and thus understand – the Scottish voice. If any unintelligible phrases fall from my lips, I can make a sound file for Arkwood so that he can learn my coarse acoustics.

‘Are you happy now?’ I asked my Belgian buddy.

He screwed up his brow. ‘What did you say?’

Nothing more. I simply rolled up my fist and pummelled his testicles.

Here’s the robot in action, translating the Queen’s English into Scottish rants:

Arkwood: “Can we eat”

Robot: “Away ben an git ese a fish supper”

Arkwood: “Time for bed”

Robot: “Git tae yer bed, yer makin a first class airse o yerself”

You can check out the SaltwashAR Wiki for details on how to install and help develop the Python Augmented Reality application.