Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Published © CC BY-NC

The All-Knowing Artifact

The aim of this project is to build an ancient relic that looks the part, but is delightfully useless. We're thinking of an all knowing stat

IntermediateFull instructions provided20 hours501
The All-Knowing Artifact

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
×1
Google AIY Kit
×1
Bamboo
×1
Glue
×1
Primer
×1
Spray Paint
×1
Sandpaper
×1

Software apps and online services

Google Dialogflow
Google Cloud Platform

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Statue Model

Schematics

Data flow

Code

truthTeller.py

Python
# Generic imports
import time
import os
import vlc

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

session_client = dialogflow.SessionsClient()
session = session_client.session_path('YOUR PROJECT ID', 12345)

# Instantiates a client
speechClient = texttospeech.TextToSpeechClient()
cloudClient = CloudSpeechClient()


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 say(test):

    synthesis_input = texttospeech.types.SynthesisInput(text=test)
    voice = texttospeech.types.VoiceSelectionParams(language_code='en-US', ssml_gender=texttospeech.enums.SsmlVoiceGender.MALE)
    audio_config = texttospeech.types.AudioConfig(audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16)
    response = speechClient.synthesize_speech(synthesis_input,voice,audio_config)

    with open('/home/pi/Desktop/truthteller/output.wav', 'wb') as out:
        out.write(response.audio_content)
        out.close()

    os.system('aplay ' + "/home/pi/Desktop/truthteller/output.wav")


while True:

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

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

    
    time.sleep(2)

Credits

Comments