Page 499 - 3-2
P. 499

# Grab application default credentials from the environment
                credentials, _ = google.auth.default(scopes=[SPEECH_SCOPE])



                # Create a secure channel using the credentials.

                http_request = google.auth.transport.requests.Request()
                target = '{}:{}'.format(host, port)



                return google.auth.transport.grpc.secure_authorized_channel(

                    credentials, http_request, target)





            def _audio_data_generator(buff):

                """A generator that yields all available data in the given buffer.
                Args:

                    buff - a Queue object, where each element is a chunk of data.
                Yields:

                    A chunk of data that is the aggregate of all chunks of data in `buff`.
                    The function will block until at least one data chunk is available.

                """
                stop = False

                while not stop:
                    # Use a blocking get() to ensure there's at least one chunk of data.

                    data = [buff.get()]



                    # Now consume whatever other data's still buffered.
                    while True:

                        try:
                            data.append(buff.get(block=False))

                        except queue.Empty:
                            break



                    # `None` in the buffer signals that the audio stream is closed. Yield

                    # the final bit of the buffer and exit the loop.
                    if None in data:

                        stop = True
                        data.remove(None)



                                                         - 499 -
   494   495   496   497   498   499   500   501   502   503   504