Skip to content

Commit

Permalink
Clear the line on the final transcription too (GoogleCloudPlatform#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerjou authored Jan 5, 2017
1 parent 352bd05 commit e047afa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions speech/grpc/transcribe_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,19 @@ def listen_print_loop(recognize_stream):

# Display interim results, but with a carriage return at the end of the
# line, so subsequent lines will overwrite them.
if not result.is_final:
# If the previous result was longer than this one, we need to print
# some extra spaces to overwrite the previous result
overwrite_chars = ' ' * max(0, num_chars_printed - len(transcript))
#
# If the previous result was longer than this one, we need to print
# some extra spaces to overwrite the previous result
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)
print(transcript + overwrite_chars)

# Exit recognition if any of the transcribed phrases could be
# one of our keywords.
Expand Down

0 comments on commit e047afa

Please sign in to comment.