Skip to content

Commit e047afa

Browse files
authored
Clear the line on the final transcription too (GoogleCloudPlatform#745)
1 parent 352bd05 commit e047afa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

speech/grpc/transcribe_streaming.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,19 @@ def listen_print_loop(recognize_stream):
182182

183183
# Display interim results, but with a carriage return at the end of the
184184
# line, so subsequent lines will overwrite them.
185-
if not result.is_final:
186-
# If the previous result was longer than this one, we need to print
187-
# some extra spaces to overwrite the previous result
188-
overwrite_chars = ' ' * max(0, num_chars_printed - len(transcript))
185+
#
186+
# If the previous result was longer than this one, we need to print
187+
# some extra spaces to overwrite the previous result
188+
overwrite_chars = ' ' * max(0, num_chars_printed - len(transcript))
189189

190+
if not result.is_final:
190191
sys.stdout.write(transcript + overwrite_chars + '\r')
191192
sys.stdout.flush()
192193

193194
num_chars_printed = len(transcript)
194195

195196
else:
196-
print(transcript)
197+
print(transcript + overwrite_chars)
197198

198199
# Exit recognition if any of the transcribed phrases could be
199200
# one of our keywords.

0 commit comments

Comments
 (0)