Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am planning to buy a raspberry pi 4 and this is the first project I want to do https://www.hackster.io/8_Bits_and_a_Byte/monty-python-s-argument-bot-d616b8#code so I was wondering if the code could be modified to work without a servo and instead of the AIY voice kit, it could work with a bluetooth speaker?

here is the code:

# 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)


as you can tell I am not very good at python as if I were, I would be able to modify this myself but I would like some help and some explanation as well.

What I have tried:

I don't currently have a raspberry pi but I want to get one and this is the first project that caught my eye so I was wondering if someone could help me?
Posted
Comments
[no name] 29-Jan-21 22:05pm    
I think you'll get a better understanding by simply Googling: "Add mic to Raspberry"; "Add speaker to Raspberry"; "add mic and speakers ...", etc.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900