Published © CC BY-NC-SA

The Swear Bear

Do you also swear too much? Don't worry, this artificial intelligence powered, internet of things enabled swear jar is here to help!

IntermediateFull instructions providedOver 1 day4,247
The Swear Bear

Things used in this project

Hardware components

Raspberry Pi 3b+ Starter Kit
Google AIY Kit
Teddy Bear

Software apps and online services

Google Cloud Platform
ThingSpeak API
ThingSpeak API


Read more


import os
import requests
import time
import json

from aiy.cloudspeech import CloudSpeechClient
from profanity_check import predict, predict_prob
import aiy.voice.tts 

def say(test):
    aiy.voice.tts.say(test, lang='en-GB', volume=50, pitch=10, speed=100, device='default')

def sendData(profane, spokenText):

    url = ' KEY HERE&field1={0}&field2={1}'.format(profane, spokenText)
    response = requests.request("GET", url)

def getStats():

    say("Fine, calculating")
    # Get the data from ThingSpeaks
    url = "Your ThingSpeak URL here"
    response = requests.request("GET", url)
    jsonData = json.loads(response.text)
    records = jsonData['feeds']

    # Stats
    totalGood = 0
    totalBad = 0
    total = len(records)
    lastBad = ''

    # Loop over them, add to stats
    for record in records:

        if record['field1'] == 'True':
            totalBad += 1
            lastBad = record['field2']

            totalGood += 1

    # Give summary of stats
    say('A total of ' + str(total) + ' records to analyse.')
    say('A whopping ' + str(int((totalBad/total) * 100)) + ' percent contain a swear.'))
    say("The last one beeing 'bears suck'. By you. Just now.")

# Instantiates a Google Cloud client
cloudClient = CloudSpeechClient()
say("The bear has awoken!")

while True:

    # Listen en recognize
    spokenText = cloudClient.recognize()

    # Check if anything was said
    if spokenText is not None:
        # Let assume the best
        profanity = False
        # Secret data voice module console validator!
        if spokenText.lower() == 'bears suck':
            profanity = True

        # It happend, profanity!
        if predict([str(spokenText)]):
            say('O dear!')
            profanity = True

        # Now the cloud must know! 
        sendData(profanity, spokenText)