示例#1
0
def main():
    logging.basicConfig(level=logging.INFO)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            process_event(board.led, event)
示例#2
0
    def __init__(self, language_code='en-US', volume_percentage=100):
        self._volume_percentage = volume_percentage  # Mutable state.
        self._conversation_state = None              # Mutable state.
        self._language_code = language_code

        ##
        credentials = auth_helpers.get_assistant_credentials()
        device_model_id, device_id = device_helpers.get_ids_for_service(credentials)

        logger.info('device_model_id: %s', device_model_id)
        logger.info('device_id: %s', device_id)

        http_request = google.auth.transport.requests.Request()
        try:
            credentials.refresh(http_request)
        except Exception as e:
            raise RuntimeError('Error loading credentials: %s', e)

        api_endpoint = ASSISTANT_API_ENDPOINT
        grpc_channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, http_request, api_endpoint)
        logger.info('Connecting to %s', api_endpoint)
        ##

        self._assistant = embedded_assistant_pb2_grpc.EmbeddedAssistantStub(grpc_channel)
        self._device_config = embedded_assistant_pb2.DeviceConfig(
            device_model_id=device_model_id,
            device_id=device_id)
示例#3
0
def main():
    global node_list
    logging.basicConfig(level=logging.INFO)
    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        schedule.every().day.at("00:59").do(schedule_wifiOff)
        schedule.every().day.at("01:00").do(schedule_waterMainOn)
        schedule.every().day.at("01:01").do(schedule_waterSideOn)
        schedule.every().day.at("01:15").do(schedule_waterSideOff)
        schedule.every().day.at("01:16").do(schedule_waterEastOn)
        schedule.every().day.at("01:30").do(schedule_waterEastOff)
        schedule.every().day.at("01:31").do(schedule_waterWestOn)
        schedule.every().day.at("01:45").do(schedule_waterWestOff)
        schedule.every().day.at("01:46").do(schedule_waterSouthOn)
        schedule.every().day.at("02:00").do(schedule_waterSouthOff)
        schedule.every().day.at("02:01").do(schedule_waterMainOff)
        #schedule.every().day.at("07:30").do(sayWeather, assistant)
        #schedule.every().day.at("07:45").do(sayWorkPath, assistant)
        schedule.every(15).minutes.do(checkSystem, assistant)
        schedule_thread_worker = threading.Thread(target=schedule_thread,
                                                  args=(schedule, ))
        schedule_thread_worker.start()
        http_thread_worker = threading.Thread(target=http_thread, args=())
        http_thread_worker.start()
        for key, value in node_list.items():
            value.start()
        checkSystem(assistant)
        for event in assistant.start():
            process_event(assistant, board.led, event)
def main():
    logging.basicConfig(level=logging.INFO)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            process_event(board.led, event)
示例#5
0
文件: grpc.py 项目: eosurman/physicsc
    def __init__(self, language_code='en-US', volume_percentage=100):
        self._volume_percentage = volume_percentage  # Mutable state.
        self._conversation_state = None              # Mutable state.
        self._language_code = language_code

        ##
        credentials = auth_helpers.get_assistant_credentials()
        device_model_id, device_id = device_helpers.get_ids_for_service(credentials)

        logger.info('device_model_id: %s', device_model_id)
        logger.info('device_id: %s', device_id)

        http_request = google.auth.transport.requests.Request()
        try:
            credentials.refresh(http_request)
        except Exception as e:
            raise RuntimeError('Error loading credentials: %s', e)

        api_endpoint = ASSISTANT_API_ENDPOINT
        grpc_channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, http_request, api_endpoint)
        logger.info('Connecting to %s', api_endpoint)
        ##

        self._assistant = embedded_assistant_pb2_grpc.EmbeddedAssistantStub(grpc_channel)
        self._device_config = embedded_assistant_pb2.DeviceConfig(
            device_model_id=device_model_id,
            device_id=device_id)
示例#6
0
def main():
    if not os.path.exists('/run/user/0'):
        os.makedirs('/run/user/0')

    logging.basicConfig(level=logging.INFO)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            process_event(assistant, board.led, event)
示例#7
0
def main():

    logging.basicConfig(level=logging.INFO)

    #    button = aiy.voicehat.get_button()
    #    button.on_press(on_button_press)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            process_event(assistant, board.led, event)
def main():

    global EV3  # THis is the pointer to the LEGO EV3.  This is a declared
    # as global so that during multiple calls to process_event,
    # the pointer in EV3 will have a persistant value

    EV3 = None

    logging.basicConfig(level=logging.INFO)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            exit_conv = process_event(assistant, board.led, event)
            if exit_conv:
                break  # Stop this look if user requested it
示例#9
0
def main():
    global config
    config = class_config()
    if fileexists(config.config_filename):
        print("will try to read Config File : ", config.config_filename)
        config.read_file()  # overwrites from file
    else:  # no file so file needs to be writen
        config.write_file()
        print(
            "New Config File Made with default values, you probably need to edit it"
        )

    logging.basicConfig(level=logging.INFO)

    credentials = auth_helpers.get_assistant_credentials()
    with Board() as board, Assistant(credentials) as assistant:
        for event in assistant.start():
            process_event(assistant, board.led, event)
示例#10
0
文件: main.py 项目: dunstad/voice-kit
 def _run_task(self):
     credentials = auth_helpers.get_assistant_credentials()
     with Assistant(credentials) as assistant:
         self._assistant = assistant
         for event in assistant.start():
             self._process_event(event)
 def _run_task(self):
     credentials = auth_helpers.get_assistant_credentials()
     with Assistant(credentials) as assistant:
         self._assistant = assistant
         for event in assistant.start():
             self._process_event(event)
示例#12
0
def main():
    logging.basicConfig(level=logging.INFO)
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser(description='Assistant service example.')
    parser.add_argument('--language', default=locale_language())
    args = parser.parse_args()
    while (1):
        try:
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=SHOW&module=module_0_clock'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_2_calendar'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_5_MMM-google-route'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_3_currentweather'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_4_weatherforecast'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_6_MMM-Remote-Control'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_7_newsfeed'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=SHOW&module=module_1_compliments'
            )
            r = requests.get(
                'http://127.0.0.1:8080/remote?action=HIDE&module=module_9_MMM-ToDoList'
            )
            client = CloudSpeechClient()
            print(client)
            credentials = auth_helpers.get_assistant_credentials()
            print(credentials)
            with Board() as board, Assistant(credentials) as assistant:
                print('s')
                assistant.set_mic_mute(True)
                print('ss')
                assistant.start()
                print('sss')
                print('start')
                while (1):
                    # status_ui=aiy.Assistant.get_status_ui()

                    print('coming')
                    board.led.state = Led.ON
                    print('here')
                    text = client.recognize(language_code=args.language)

                    # text="friday"
                    print('hgjhr')
                    if text is None:

                        continue
                    elif text.lower().find('friday') != -1:
                        board.led.state = Led.ON
                        index = text.lower().find('friday')
                        aiy.voice.audio.play_wav(
                            '/home/pi/Smart_Mirror/googlestart.wav')
                        text = text[index + 7:]
                        if (len(text) > 5):
                            logging.info('Processing..')
                            process_event(text, assistant, board, client)
                        else:
                            while (1):
                                logging.info('Smart Mirror Listening..')
                                text1 = client.recognize(
                                    language_code=args.language)

                                if text1 is None:
                                    continue
                                else:
                                    process_event(text1, assistant, board,
                                                  client)
                                    break
                    elif text.lower().find('minimize') != -1 or text.lower(
                    ).find('minimise') != -1 or text.lower().find(
                            'close') != -1:
                        process_event('minimise', assistant, board, client)
                    else:
                        continue
        except Exception as e:
            print(str(e))
            print('exception caught')
            time.sleep(0.5)