def main(): global ASSISTANT parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) ASSISTANT = Assistant(credentials) GPIO.add_event_detect(PIN_BTN, GPIO.FALLING, callback=callback_start_conversation, bouncetime=300) for event in ASSISTANT.start(): process_event(event) while True: pass
def run(self, mainQueue, utils): p = multiprocessing.current_process() self.logger = utils._logger self.logger.info('Google Assistant PID: ' + str(p.pid)) with open( os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) self.logger.info('Google Assistant: Starting') _assistant = Assistant(credentials, 'homepi-177214-shineon-1s9b88') self._assistant = _assistant self.register_device('homepi-177214', credentials, 'homepi-177214-shineon-1s9b88', self._assistant.device_id) count = 0 for event in _assistant.start(): #print(event) _events = GoogleEvents(_assistant, utils) if (count == 0): self.logger.info('Google Assistant: Started') messages = _events.getEvent(event) self.sendMessages(mainQueue, messages) count += 1
def callback(channel): global CREDENTIALS if not CREDENTIALS: return print("callback") assistant = Assistant(CREDENTIALS) ret = assistant.start_conversation() print(ret)
def main(): global assistant pixels.wakeup() # GPIO.setmode(GPIO.BCM) # GPIO.setup(PIN_LAMP, GPIO.OUT) # for p in PIN_BUTTON: # GPIO.setup(p, GPIO.IN, GPIO.PUD_UP) # if p == 13: # toggle button # GPIO.add_event_detect(p, GPIO.BOTH, callback=procButton, \ # bouncetime=BOUNCE_MSEC) # else: # GPIO.add_event_detect(p, GPIO.FALLING, callback=procButton, \ # bouncetime=BOUNCE_MSEC) parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument( '--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) for event in events: process_event(event, assistant.device_id)
def __init__(self, device_model_id, creds_path=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json')): with open(creds_path, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) self.assistant = Assistant(credentials, device_model_id)
def main(): while (1): if (os.system("ping -c 1 " + "google.com")) == 0: break parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument( '--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') GPIO.setmode(GPIO.BCM) GPIO.setup(redP, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(blueP, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(greenP, GPIO.OUT, initial=GPIO.LOW) if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) GPIO.output(redP, 1) time.sleep(2) GPIO.output(redP, 0) for event in events: process_event(event, assistant.device_id)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument( '--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument( '-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) parser.add_argument( '-p', '--port', required=True, help='The USB port to connect to the sign over') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) print('Starting flipdot') global flipapps flipapps = FlipApps(args.port) flipapps.add_sign('dev', 1, 84, 7) with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) for event in events: process_event(event, assistant.device_id)
def __init__(self, credentials, device_model_id, project_id=None): # Create a google assistant client self.assistant = Assistant(credentials, device_model_id) # Register device if necessary if project_id: self.register_device( project_id, credentials, device_model_id, self.assistant.device_id) # Create a flipapps client self.client = FlipAppClient()
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument(constants.CREDENTIALS_ARG, type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument(constants.DEVICE_MODEL_ARG, type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument( constants.PROJECT_ARG, type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: # Play intro audio playWavFile(dir_path + configData[constants.STARTUP_AUDIO_FILE_KEY]) say(configData[constants.STARTUP_MESSAGE_KEY], configData[constants.SAY_FILE_KEY]) events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) #indicate that we are ready now... playWavFile(dir_path + configData[constants.HOTWORD_WAITING_AUDIO_FILE_KEY]) for event in events: process_event(event, assistant.device_id)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument( '--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') # setup the PWM for the LED GPIO.setmode(GPIO.BOARD) GPIO.setup(12, GPIO.OUT) global pwm, duty_cycle pwm = GPIO.PWM(12, 50) pwm.start(duty_cycle) if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) for event in events: process_event(event, assistant.device_id)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('/home/pi/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials) as assistant: for event in assistant.start(): process_event(event) if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED: if actions.process(event.args["text"].lower(), assistant): assistant.stop_conversation() pass
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google.') parser.add_argument('--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device ' + 'instances.') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id) for event in events: process_event(event, assistant.device_id)
def main(): doa = None # DoA # src = Source(rate=16000, frames_size=320, channels=4, device_index=0) src = Source(rate=16000, frames_size=320, channels=4) doa = DOA(rate=16000, chunks=20) src.link(doa) src.recursive_start() # GPIO GPIO.output(led_gnd_pin, False) GPIO.output(led1_pin, True) GPIO.output(led2_pin, True) # Google Assistant parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('/home/pi/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials, "RPi3_Assistant") as assistant: for event in assistant.start(): process_event(event, doa)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('/home/pi/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials) as assistant: subprocess.Popen(["aplay", "/home/pi/GassistPi/sample-audio-files/Startup.wav"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) for event in assistant.start(): process_event(event) usrcmd=event.args if 'trigger'.lower() in str(usrcmd).lower(): assistant.stop_conversation() Action(str(usrcmd).lower()) if 'play'.lower() in str(usrcmd).lower(): assistant.stop_conversation() YouTube(str(usrcmd).lower()) if 'stop'.lower() in str(usrcmd).lower(): stop()
def start_listening(self) : self.botThread.start() #Code from google's hotword.py parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) # with Assistant(credentials) as assistant : for event in assistant.start() : if event.type == EventType.ON_START_FINISHED: print(event) if event.type == EventType.ON_CONVERSATION_TURN_STARTED : print("say") if event.type == EventType.ON_END_OF_UTTERANCE : print("okay") if event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED : if isACustomCommand(event.args['text']) assistant.stop_conversation() processCommand(event.args['text'])
def run(self): with Assistant(self.credentials, self.deviceModelId) as assistant: self.assistant = assistant for event in assistant.start(): self.process_event(event) if self.debug == True: print(event)
def main(device_model): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('/home/pi/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') args = parser.parse_args() print(args) with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) try: with Assistant(credentials, device_model) as assistant: for event in assistant.start(): process_event(event) except Exception as e: # Keyboard interrupt or other stuff that causes termination - # clean up any running child process. radio_process.terminate() GPIO.cleanup() python = sys.executable os.execl(python, python, *sys.argv)
def main(): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: for event in assistant.start(): byte = str(randint(0, 4)).encode("utf-8") ser.write(byte) process_event(assistant, event)
def run(self): import google.oauth2.credentials from google.assistant.library import Assistant super().run() with open(self.credentials_file, 'r') as f: self.credentials = google.oauth2.credentials.Credentials( token=None, **json.load(f)) while not self.should_stop(): self._has_error = False with Assistant(self.credentials, self.device_model_id) as assistant: self.assistant = assistant for event in assistant.start(): if not self.is_detecting(): self.logger.info( 'Assistant event received but detection is currently paused' ) continue self._process_event(event) if self._has_error: self.logger.info( 'Restarting the assistant after an unrecoverable error' ) time.sleep(5) break
def main(): radio = False credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: aiy.voicehat.get_button().on_press(_on_button_pressed) for event in assistant.start(): process_event(assistant, event)
def main(): global mqttc mqttc.on_message = on_message mqttc.connect("raspberrypi.local",1883,60) mqttc.subscribe('topic/test') print("starting application") print("say: Ok, Google. To start") print("Commands: lights on, lights off, lights down, lights up") # mqttc.loop_forever() parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join( os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json' ), help='Path to store and read OAuth2 credentials') args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) with Assistant(credentials) as assistant: for event in assistant.start(): process_event(event)
def run(self): super().run() with Assistant(self.credentials, self.device_model_id) as assistant: self.assistant = assistant for event in assistant.start(): self._process_event(event)
def _run_task(self): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() model_id, device_id = aiy.assistant.device_helpers.get_ids(credentials) with Assistant(credentials, model_id) as assistant: self._assistant = assistant for event in assistant.start(): self._process_event(event)
def main(): init_output([LED_PIN]) light(LED_PIN, 'on') credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: for event in assistant.start(): process_event(assistant, event)
def _run_task(self): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: self._assistant = assistant self._custom_action_helper = CustomActionHelper(assistant) for event in assistant.start(): self._process_event(event)
def main(): # Mittels des Parameters --crendentials kann eine eigene Credentials-Datei angegeben werden. # Wurde keine angegeben, greift das Programm auf die Datei ~/.config/google-oauthlib-tool/credentials.json zurück. parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') args = parser.parse_args() # Die für die Anmeldung an Googles API notwendigen Credentials werden geladen. with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) # Die Instanz des Google Assistant in assistant beginnt Ereignisse auszulösen, diese werden mittels process_event # verarbeitet. with Assistant(credentials) as assistant: # Started den Thread, der auf den Mute-Button reagiert button_thread = threading.Thread(target=listen, args=(assistant, )) button_thread.start() print("Warte auf Hotword") eventlist = assistant.start() mute(assistant) for event in eventlist: process_event(event, assistant)
def main(): device_setup() credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: for event in assistant.start(): process_event(assistant, event)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument( '--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument( '--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google.') parser.add_argument( '--project_id', type=str, metavar='PROJECT_ID', required=False, help='The project ID used to register device instances.') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials( token=None, **json.load(f)) with Assistant(credentials, args.device_model_id) as assistant: subprocess.Popen([ "aplay", "/home/pi/Omega-AI/sample-audio-files/Startup.wav" ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) events = assistant.start() print('device_model_id:', args.device_model_id + '\n' + 'device_id:', assistant.device_id + '\n') if args.project_id: register_device(args.project_id, credentials, args.device_model_id, assistant.device_id)
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('--credentials', type=existing_file, metavar='OAUTH2_CREDENTIALS_FILE', default=os.path.join(os.path.expanduser('~/.config'), 'google-oauthlib-tool', 'credentials.json'), help='Path to store and read OAuth2 credentials') parser.add_argument('--device_model_id', type=str, metavar='DEVICE_MODEL_ID', required=True, help='The device model ID registered with Google') parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + Assistant.__version_str__()) args = parser.parse_args() with open(args.credentials, 'r') as f: credentials = google.oauth2.credentials.Credentials(token=None, **json.load(f)) # Set up the sound thread sound_queue = Queue() sound_thread = Process(target=sound_playback_thread, args=(sound_queue, )) sound_thread.start() # Set up the process that will play sounds for other processes. This # is needed until we get a shared PulseAudio system up and running # s.t. all elements can play their own sounds sound_element = Process(target=sound_element_thread, args=(sound_queue, )) sound_element.start() with Assistant(credentials, args.device_model_id) as assistant: # Create our element element = Element("voice") # Start the assistant events = assistant.start() for event in events: process_event(event, assistant, element, sound_queue)
def __init__(self): self.bot = Bot() self.gather_commands() credentials = aiy.assistant.auth_helpers.get_assistant_credentials() with Assistant(credentials) as assistant: for event in assistant.start(): self.process_event(assistant, event)