def listen_print_loop(recognize_stream):
    for resp in recognize_stream:
        if resp.error.code != code_pb2.OK:
            raise RuntimeError('Server error: ' + resp.error.message)

        # Display the transcriptions & their alternatives
        for result in resp.results:
            print(result.alternatives)

        # Exit recognition if any of the transcribed phrases could be
        # one of our keywords.
        if any(alt.confidence > .5 and
               (alt.transcript.strip() in ('exit', 'quit'))
               for result in resp.results
               for alt in result.alternatives):
            print('Exiting..')
            return
dataset/ETHPy150Open GoogleCloudPlatform/python-docs-samples/speech/api/speech_streaming.py/listen_print_loop/original