def listen_print_loop(recognize_stream):
 num_chars_printed = 0
 for resp in recognize_stream:
  if (resp.error.code != code_pb2.OK):
   raise RuntimeError(('Server error: ' + resp.error.message))
  if (not resp.results):
   continue
  result = resp.results[0]
  transcript = result.alternatives[0].transcript
  overwrite_chars = (' ' * max(0, (num_chars_printed - len(transcript))))
  if (not result.is_final):
   sys.stdout.write(((transcript + overwrite_chars) + '\r'))
   sys.stdout.flush()
   num_chars_printed = len(transcript)
  else:
   print (transcript + overwrite_chars)
   if re.search('\\b(exit|quit)\\b', transcript, re.I):
    print 'Exiting..'
    break
   num_chars_printed = 0

def listen_print_loop ( recognize_stream ) : num_chars_printed = 0 for resp in recognize_stream : if ( resp . error . code != code_pb2 . OK ) : raise RuntimeError ( ( 'Server error: ' + resp . error . message ) ) if ( not resp . results ) : continue result = resp . results [ 0 ] transcript = result . alternatives [ 0 ] . transcript overwrite_chars = ( ' ' * max ( 0 , ( num_chars_printed - len ( transcript ) ) ) ) if ( not result . is_final ) : sys . stdout . write ( ( ( transcript + overwrite_chars ) + '\r' ) ) sys . stdout . flush ( ) num_chars_printed = len ( transcript ) else : print ( transcript + overwrite_chars ) if re . search ( '\\b(exit|quit)\\b' , transcript , re . I ) : print 'Exiting..' break num_chars_printed = 0
iterates through server responses and prints them .