, , , , , , , , , ,

Arkwood has a deep scar. He won’t talk about it openly, but it has something to do with the British Broadcasting Corporation. Indeed, the horror has become so bad that last month he was found strolling about our town with a megaphone strapped to his person, shouting, ‘The BBC are lying to us! Down with the BBC!’ Irrational, I know, but I though it best to put his mind to rest with a little piece of Python and the Raspberry Pi.

To start with, I put a microphone against the TV speaker and used Google’s speech to text service to turn the words spoken by the BBC News channel’s anchorman into strings. The results were surprisingly good:

2014-03-10 20:51:06: break up line on the ground cover
2014-03-10 20:51:21: investigation in the army monkeys
2014-03-10 20:51:33: 2525
2014-03-10 20:51:45: what rhymes with Scott Summers
2014-03-10 20:52:02: lungs is a schedule I need to change
2014-03-10 20:52:13: regional transplant center
2014-03-10 20:52:24: transplant
2014-03-10 20:52:38: 3001 thing coming
2014-03-10 20:53:02: Manson family members
2014-03-10 20:53:15: the nearest transplant center
2014-03-10 20:53:27: people with you missed a Wilson
2014-03-10 20:53:39: getting braces
2014-03-10 20:53:59: after another summary of Suffolk
2014-03-10 20:54:19: adore you
2014-03-10 20:54:38: Kootra photos Mascoutah
2014-03-10 20:54:58: compounding by the waves and rain
2014-03-10 20:55:17: is not going to be
2014-03-10 20:55:37: how it works where is the one stop
2014-03-10 20:55:53: I don't know about me
2014-03-10 20:56:04: 1900 to do something
2014-03-10 20:56:15: 12 the same spot 20 years
2014-03-10 20:56:29: Macy's BBC News app
2014-03-10 20:56:50: Social Security Administration
2014-03-10 20:57:01: time for the cat the weather we going to need a man
2014-03-10 20:57:13: high pressure Pentagon building in the cross
2014-03-10 20:57:25: I'm kind of a compound for the weekend
2014-03-10 20:57:37: Frost Bank Clinton CT
2014-03-10 20:57:49: movin on up tomorrow to talk to school with
2014-03-10 20:58:01: in Scotland 2012
2014-03-10 20:58:13: why does the back into the family
2014-03-10 20:58:25: Will Smith
2014-03-10 20:58:37: wake up sunshine lady slipper
2014-03-10 20:58:49: the Sun is the next couple be on Wednesday
2014-03-10 20:59:03: FB stock first day hike
2014-03-10 20:59:15: high pressure is the weather is going in the front
2014-03-10 20:59:27: coupon for the forecast talk about the end of days
2014-03-10 20:59:38: the weather across the USA

Interesting to see that Google is handling profanity:

2014-03-10 20:39:24: what is c***
2014-03-10 21:25:36: girl c** straight can you go
2014-03-10 21:25:48: Costco take a s*** on ever ever about

But this is okay:

2014-03-10 21:09:40: masturbation

Natural after all.

Plus some stuff that even made my morose Belgian friend laugh:

2014-03-10 20:46:09: nude twerking should see their wages Grove
2014-03-10 20:48:30: recycle bin Laden I will be picking up
2014-03-10 21:13:15: yesterday sounds of people crossing cream

Anyway, I digress slightly. For the purpose of the exercise was to prove to Arkwood that the BBC are good eggs.

Okay. So we have converted the news from the TV speakers into text. Next, we can check for lies. We do this by fetching the latest RSS feed from the distinguished Reuters agency. Looping through each article in the feed, we can determine if the titles match the latest words being broadcast by Auntie Beeb. If they do, then we announce the BBC’s innocence through a set of headphones in the Pi’s audio jack, using Google’s text to speech service. If not, Arkwood can take them to court.

Here’s the main code block:

from speech import Speech
import datetime
import feedparser
from time import sleep

# loop until armageddon
while True:

    # get bbc chat
    bbc_chat = Speech().speech_to_text('/home/pi/PiAUISuite/VoiceCommand/speech-recog.sh')
    # store chat 

    # is chat in reuters feed

    # pause before next sample

And here’s the supporting functions:

def write_to_file(text):

    # get current time
    datestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # add text to file
    with open("news.txt", "a") as news_file:
        news_file.write(datestamp + ': ' + text + '\n')

def chat_in_feed(bbc_chat):
    # get reuters feed
    reuters_feed = feedparser.parse('http://mf.feeds.reuters.com/reuters/UKTopNews')
    # loop through feed
    for i in range(0,len(reuters_feed['entries'])):
        # loop through chat
        for word in bbc_chat.split():

            # if word in chat is found in article then announce BBC innocent
            if word.lower() in reuters_feed['entries'][i].title.lower():
                announcement = word + " found in article " + reuters_feed['entries'][i].title

    # if chat is not found in feed then announce BBC liars
    announcement = bbc_chat + " not found in feed. The BBC are lying to us again"

I won’t go through the underlying implementation for Google’s services – it’s all in my previous posts.

As Bucks Fizz once said, the text file never lies. Look what it’s captured:

2014-03-13 00:16:08: completely in East Neck Road
2014-03-13 00:17:35: in found in article EU moves toward sanctions on Russians, Obama meets Ukraine PM
2014-03-13 00:17:46: about weather next week budget
2014-03-13 00:19:19: budget found in article UK government seizes on worsening Scottish budget figures
2014-03-13 00:19:31: immediate Optima mother
2014-03-13 00:21:01: immediate Optima mother not found in feed. The BBC are lying to us again
2014-03-13 00:21:13: 76 is the time is taken to put on
2014-03-13 00:22:43: is found in article Israel bombs Gaza militants after intensive rocket fire
2014-03-13 00:22:55: security long time
2014-03-13 00:24:22: security long time not found in feed. The BBC are lying to us again

Granted, we could do with binning off comparisons between small words e.g. ‘in’, ‘is’. And not match on words within words. But you get the gist.

Setting this experiment up involved running the code on the Pi, then quickly switching the HDMI channels on the TV to BBC News and listening though the headphones to what was being picked up by the microphone gaffer taped to the TV speaker. Sounds simple, right? Yes, I am as surprised as you are that this actually flew. But fly it did!


So – let’s cut to the chase – are the BBC spouting gibberish, or are they consistent with Reuters? I’ll let you know as soon as Arkwood puts his megaphone down.