8bitsandabyte
Published © CC BY-NC

Monty Python's Argument Bot

In need of a good argument? Try the argument bot! A robot based on Monty Python's Flying Circus argument sketch.

IntermediateFull instructions providedOver 1 day500

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Google AIY Kit
×1
Tower Pro MG995
×1

Software apps and online services

Google Dialogflow
Photo Editing Software

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Scissors, Free Fall
Scissors, Free Fall
Multitool, Screwdriver
Multitool, Screwdriver
Screw
Glue
Printer

Story

Read more

Custom parts and enclosures

Linear Actuator

Schematics

Dataflow

Code

arguCode.py

Python
# Servo setup
from gpiozero import Servo
mouthServo = Servo(26)
global talk

# Generic imports
import time
import os
import threading
from random import randint

# Dialogflow setup
import aiy.voice.tts 
import dialogflow_v2 as dialogflow
from aiy.board import Board
from aiy.cloudspeech import CloudSpeechClient

session_client = dialogflow.SessionsClient()
session = session_client.session_path('xxxxxxx', 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

def talk():

    global talk
    while True:
        while talk:
            sleepTime = (randint(1, 3))/10
            mouthServo.max()
            time.sleep(sleepTime)
            mouthServo.mid()
            time.sleep(sleepTime)
        
        mouthServo.detach()

moveLidThread = threading.Thread(target=talk)
moveLidThread.start()

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

while True:

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

    if spokenText is None:
        print('You said nothing.')
    else:
        response = getDialogResponse(spokenText)
        responseText = response.query_result.fulfillment_text

        talk = True
        say(responseText)
        talk = False

    time.sleep(0.5)

Credits

8bitsandabyte

8bitsandabyte

47 projects • 39 followers
We’re Dane & Nicole, two makers that create tremendously terrible tech, which we happily share with you on our channel!

Comments