愚者自愚
Committed by GitHub

fix generate-subtitles.py bug (#1029)

* fix generate-subtitles.py If the audio file is not muted for more than 1 second at the end, it will cause the last segment to be lost
@@ -386,12 +386,17 @@ def main(): @@ -386,12 +386,17 @@ def main():
386 386
387 print("Started!") 387 print("Started!")
388 388
  389 + is_silence=False
389 # TODO(fangjun): Support multithreads 390 # TODO(fangjun): Support multithreads
390 while True: 391 while True:
391 # *2 because int16_t has two bytes 392 # *2 because int16_t has two bytes
392 data = process.stdout.read(frames_per_read * 2) 393 data = process.stdout.read(frames_per_read * 2)
393 if not data: 394 if not data:
394 - break 395 + if is_silence:
  396 + break
  397 + is_silence=True
  398 + # The converted audio file does not have a mute data of 1 second or more at the end, which will result in the loss of the last segment data
  399 + data = np.zeros(1*args.sample_rate,dtype=np.int16)
395 400
396 samples = np.frombuffer(data, dtype=np.int16) 401 samples = np.frombuffer(data, dtype=np.int16)
397 samples = samples.astype(np.float32) / 32768 402 samples = samples.astype(np.float32) / 32768