From 167bc76db0f7980dec4387302613ce53ffb0cece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=84=9A=E8=80=85=E8=87=AA=E6=84=9A?= <33177184+xiaokuang95@users.noreply.github.com> Date: Tue, 18 Jun 2024 18:29:39 +0800 Subject: [PATCH] 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 --- python-api-examples/generate-subtitles.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python-api-examples/generate-subtitles.py b/python-api-examples/generate-subtitles.py index 1f03d0d0..96061425 100755 --- a/python-api-examples/generate-subtitles.py +++ b/python-api-examples/generate-subtitles.py @@ -386,12 +386,17 @@ def main(): print("Started!") + is_silence=False # TODO(fangjun): Support multithreads while True: # *2 because int16_t has two bytes data = process.stdout.read(frames_per_read * 2) if not data: - break + if is_silence: + break + is_silence=True + # 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 + data = np.zeros(1*args.sample_rate,dtype=np.int16) samples = np.frombuffer(data, dtype=np.int16) samples = samples.astype(np.float32) / 32768