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 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 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 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 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: 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 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(): 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 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(): 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 _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(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 _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 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 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 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(): 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 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 callback(channel): global CREDENTIALS if not CREDENTIALS: return print("callback") assistant = Assistant(CREDENTIALS) ret = assistant.start_conversation() print(ret)
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)
def activate(self): """ GOOGLE ASSISTANTを有効にして処理を行う部分 :return: """ with Assistant(self.credentials, "zairiki") as assistant: for event in assistant.start(): self._process_event(event)
def main(): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() aiy.audio.say('Ok google will be activated in approximately one minute') bot.start_bot() # my_actions.initialize() # this is used to initialized HAT relay board PINS with Assistant(credentials) as assistant: for event in assistant.start(): process_event(assistant, event)
def main(): credentials = aiy.assistant.auth_helpers.get_assistant_credentials() try: with Assistant(credentials) as assistant: for event in assistant.start(): process_event(event, assistant) finally: GPIO.cleanup()
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 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: subprocess.Popen(["aplay", "/home/pi/GassistPi/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) for event in events: process_event(event, assistant.device_id) usrcmd=event.args if 'trigger'.lower() in str(usrcmd).lower(): assistant.stop_conversation() Action(str(usrcmd).lower()) if 'stream'.lower() in str(usrcmd).lower(): assistant.stop_conversation() YouTube(str(usrcmd).lower()) if 'stop'.lower() in str(usrcmd).lower(): stop() if 'tune into'.lower() in str(usrcmd).lower(): assistant.stop_conversation() radio(str(usrcmd).lower()) if 'wireless'.lower() in str(usrcmd).lower(): assistant.stop_conversation() ESP(str(usrcmd).lower()) if 'parcel'.lower() in str(usrcmd).lower(): assistant.stop_conversation() track() if 'news'.lower() in str(usrcmd).lower() or 'feed'.lower() in str(usrcmd).lower() or 'quote'.lower() in str(usrcmd).lower(): assistant.stop_conversation() feed(str(usrcmd).lower()) if 'on kodi'.lower() in str(usrcmd).lower(): assistant.stop_conversation() kodiactions(str(usrcmd).lower())
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 do_assistant_library(args, recognizer, credentials, player, status_ui): """Run a recognizer using the Google Assistant Library. The Google Assistant Library has direct access to the audio API, so this Python code doesn't need to record audio. """ try: from google.assistant.library import Assistant from google.assistant.library.event import EventType except ImportError: print(''' ERROR: failed to import the Google Assistant Library. This is required for "OK Google" hotwording, but is only available for Raspberry Pi 2/3. It can be installed with: env/bin/pip install google-assistant-library==0.0.2''') sys.exit(1) say = tts.create_say(player) actor = action.make_actor(say) action.add_commands_just_for_cloud_speech_api(actor, say) recognizer.add_phrases(actor) def process_event(event): logging.info(event) if event.type == EventType.ON_START_FINISHED: status_ui.status('ready') if sys.stdout.isatty(): print( 'Say "OK, Google" then speak, or press Ctrl+C to quit...') elif event.type == EventType.ON_CONVERSATION_TURN_STARTED: status_ui.status('listening') elif event.type == EventType.ON_END_OF_UTTERANCE: status_ui.status('thinking') elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED and \ event.args and actor.can_handle(event.args['text']): if not args.assistant_always_responds: assistant.stop_conversation() actor.handle(event.args['text']) elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: status_ui.status('ready') elif event.type == EventType.ON_ASSISTANT_ERROR and \ event.args and event.args['is_fatal']: sys.exit(1) with Assistant(credentials) as assistant: for event in assistant.start(): process_event(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__()) 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)