Fangjun Kuang
Committed by GitHub

Print the time about the first message in tts. (#655)

@@ -180,6 +180,8 @@ sample_rate = None @@ -180,6 +180,8 @@ sample_rate = None
180 180
181 event = threading.Event() 181 event = threading.Event()
182 182
  183 +first_message_time = None
  184 +
183 185
184 def generated_audio_callback(samples: np.ndarray): 186 def generated_audio_callback(samples: np.ndarray):
185 """This function is called whenever max_num_sentences sentences 187 """This function is called whenever max_num_sentences sentences
@@ -191,6 +193,10 @@ def generated_audio_callback(samples: np.ndarray): @@ -191,6 +193,10 @@ def generated_audio_callback(samples: np.ndarray):
191 samples: 193 samples:
192 A 1-D np.float32 array containing audio samples 194 A 1-D np.float32 array containing audio samples
193 """ 195 """
  196 + global first_message_time
  197 + if first_message_time is None:
  198 + first_message_time = time.time()
  199 +
194 buffer.put(samples) 200 buffer.put(samples)
195 global started 201 global started
196 202
@@ -297,14 +303,14 @@ def main(): @@ -297,14 +303,14 @@ def main():
297 play_back_thread.start() 303 play_back_thread.start()
298 304
299 logging.info("Start generating ...") 305 logging.info("Start generating ...")
300 - start = time.time() 306 + start_time = time.time()
301 audio = tts.generate( 307 audio = tts.generate(
302 args.text, 308 args.text,
303 sid=args.sid, 309 sid=args.sid,
304 speed=args.speed, 310 speed=args.speed,
305 callback=generated_audio_callback, 311 callback=generated_audio_callback,
306 ) 312 )
307 - end = time.time() 313 + end_time = time.time()
308 logging.info("Finished generating!") 314 logging.info("Finished generating!")
309 global stopped 315 global stopped
310 stopped = True 316 stopped = True
@@ -316,7 +322,7 @@ def main(): @@ -316,7 +322,7 @@ def main():
316 play_back_thread.join() 322 play_back_thread.join()
317 return 323 return
318 324
319 - elapsed_seconds = end - start 325 + elapsed_seconds = end_time - start_time
320 audio_duration = len(audio.samples) / audio.sample_rate 326 audio_duration = len(audio.samples) / audio.sample_rate
321 real_time_factor = elapsed_seconds / audio_duration 327 real_time_factor = elapsed_seconds / audio_duration
322 328
@@ -327,6 +333,10 @@ def main(): @@ -327,6 +333,10 @@ def main():
327 subtype="PCM_16", 333 subtype="PCM_16",
328 ) 334 )
329 logging.info(f"The text is '{args.text}'") 335 logging.info(f"The text is '{args.text}'")
  336 + logging.info(
  337 + "Time in seconds to receive the first "
  338 + f"message: {first_message_time-start_time:.3f}"
  339 + )
330 logging.info(f"Elapsed seconds: {elapsed_seconds:.3f}") 340 logging.info(f"Elapsed seconds: {elapsed_seconds:.3f}")
331 logging.info(f"Audio duration in seconds: {audio_duration:.3f}") 341 logging.info(f"Audio duration in seconds: {audio_duration:.3f}")
332 logging.info( 342 logging.info(