Page 1131 - 3-2
P. 1131

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)


                    yield b''.join(data)




            def _fill_buffer(buff, in_data, frame_count, time_info, status_flags):
                """Continuously collect data from the audio stream, into the buffer."""
                buff.put(in_data)
                return None, pyaudio.paContinue




            # [START audio_stream]
            @contextlib.contextmanager


                                                        - 1131 -
   1126   1127   1128   1129   1130   1131   1132   1133   1134   1135   1136