Beispiel #1
0
    def conversation2(self, deadline=DEFAULT_GRPC_DEADLINE):
        """
        Starts a conversation with the Google Assistant.

        The device begins listening for your query or command and will wait indefinitely.
        Once it completes a query/command, it returns to listening for another.

        Args:
            deadline: The amount of time (in milliseconds) to wait for each gRPC request to
                complete before terminating.
        """
        keep_talking = True
        while keep_talking:
            playing = False
            with Recorder() as recorder, BytesPlayer() as player:
                play = player.play(AUDIO_FORMAT)

                def wrapped_play(data):
                    nonlocal playing
                    if not playing:
                        self._playing_started()
                        playing = True
                    play(data)

                try:
                    logger.info("FINALLY")
                    keep_talking = self._assist_2(recorder, wrapped_play,
                                                  deadline)
                finally:
                    play(None)  # Signal end of sound stream.
                    recorder.done()  # Signal stop recording.

            if playing:
                self._playing_stopped()
Beispiel #2
0
    def conversation(self, deadline=DEFAULT_GRPC_DEADLINE):
        listen_flag = False
        keep_talking = True
        while keep_talking:
            playing = False
            with Recorder() as recorder, BytesPlayer() as player:
                play = player.play(AUDIO_FORMAT)

                def wrapped_play(data):
                    nonlocal playing
                    if not playing:
                        self._playing_started()
                        playing = True
                    play(data)

                try:
                    keep_talking, listen_flag = self._assist(
                        recorder, wrapped_play, deadline)
                finally:
                    play(None)  # Signal end of sound stream.
                    recorder.done()  # Signal stop recording.

            if listen_flag:
                return True

            if playing:
                self._playing_stopped()

        return False