Published © CC BY-NC-SA

AI Powered Bull**** Detector

The one device we all need, an AI Powered Bull**** Detector!

AdvancedFull instructions providedOver 1 day1,353
AI Powered Bull**** Detector

Things used in this project

Story

Read more

Custom parts and enclosures

BoxBaseplate

BoxCorner

Poop

BoxHolewall

BoxTop

BoxWall

Error uploading file to Sketchfab.

Schematics

Dataflow

Code

TestCodeNeoVoice.py

Python
from aiy.cloudspeech import CloudSpeechClient
import neopixel
import time
import board

pixels = neopixel.NeoPixel(board.D12,30)

print('setup...')
client = CloudSpeechClient('/home/pi/cloud_speech.json')

while True:

    print('Listening...')
    spokenText = client.recognize() 

    if spokenText is None:
        print('You said nothing.')
    else:
        if spokenText == 'green':s
            pixels.fill((0, 255, 0))
            time.sleep(0.5)
            pixels.fill((0, 0, 0))
        elif spokenText == 'red':
            pixels.fill((255, 0, 0))
            time.sleep(0.5)
            pixels.fill((0, 0, 0))

TestCodeDialogflow.py

Python
from aiy.cloudspeech import CloudSpeechClient
import dialogflow_v2 as dialogflow
import neopixel
import time
import board

pixels = neopixel.NeoPixel(board.D12,30)

print('setup...')
client = CloudSpeechClient('/home/pi/cloud_speech.json')

session_client = dialogflow.SessionsClient()
session = session_client.session_path('XXXXX', 12345)

def getDialogResponse(text):

    text_input = dialogflow.types.TextInput(text=text, language_code='EN')

    query_input = dialogflow.types.QueryInput(text=text_input)

    response = session_client.detect_intent(session=session, query_input=query_input)

    text = response.query_result.fulfillment_text

    return response

while True:

    print('Listening...')
    spokenText = client.recognize() 

    if spokenText is None:
        print('You said nothing.')
    else:

        print(spokenText)
        response = getDialogResponse(spokenText)
        responseText = response.query_result.fulfillment_text
        responseIntent = response.query_result.intent.display_name

        if responseIntent == 'Default Fallback Intent':
            pixels.fill((0, 255, 0))
            time.sleep(0.5)
            pixels.fill((0, 0, 0))
        else:
            pixels.fill((255, 0, 0))
            time.sleep(0.5)
            pixels.fill((0, 0, 0))

chat_custom.py

Python
import re
import os

from aiy.cloudspeech import CloudSpeechClient
import dialogflow_v2 as dialogflow
import neopixel
import time
import board
import robot_util

pixels = neopixel.NeoPixel(board.D12,30)

print('setup...')
client = CloudSpeechClient('/home/pi/cloud_speech.json')

session_client = dialogflow.SessionsClient()
session = session_client.session_path('XXXX', 12345)

def getDialogResponse(text):

    text_input = dialogflow.types.TextInput(text=text, language_code='EN')

    query_input = dialogflow.types.QueryInput(text=text_input)

    response = session_client.detect_intent(session=session, query_input=query_input)

    text = response.query_result.fulfillment_text

    return response

# example for adding a custom chat handler
main_chat_handler = None


# Reboot function, to be added to the extended chat commands.
def reboot(*args):
    os.system('sudo shutdown -r now')
    exit()  

def setup(robot_config, chat_handler):
    global main_chat_handler
    
    # Any chat related setup code goes here


    
    # Add a reboot command to the extended chat commands
    if robot_config.getboolean('tts', 'ext_chat'):
        import extended_command
        extended_command.add_command('.reboot', reboot)    
    
    main_chat_handler = chat_handler
    
    
def handle_chat(args):
    # Your custom chat handling code goes here
    print(args['message'])
    spokenText = args['message']
    response = getDialogResponse(spokenText)
    responseText = response.query_result.fulfillment_text
    responseIntent = response.query_result.intent.display_name

    if responseIntent == 'Default Fallback Intent':
        robot_util.sendChatMessage("No Bull****!")
        pixels.fill((0, 255, 0))
        time.sleep(1)
        pixels.fill((0, 0, 0))
    else:
        robot_util.sendChatMessage("Bull****!")
        pixels.fill((255, 0, 0))
        time.sleep(1)
        pixels.fill((0, 0, 0))
     
    # Call the main chat handler
    main_chat_handler(args)

Credits

Comments