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
This commit is contained in:
愚者自愚
2024-06-18 18:29:39 +08:00
committed by GitHub
parent ab21131f7f
commit 167bc76db0

View File

@@ -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