Skip to content

Commit 167bc76

Browse files
authored
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
1 parent ab21131 commit 167bc76

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

python-api-examples/generate-subtitles.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,17 @@ def main():
386386

387387
print("Started!")
388388

389+
is_silence=False
389390
# TODO(fangjun): Support multithreads
390391
while True:
391392
# *2 because int16_t has two bytes
392393
data = process.stdout.read(frames_per_read * 2)
393394
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)
395400

396401
samples = np.frombuffer(data, dtype=np.int16)
397402
samples = samples.astype(np.float32) / 32768

0 commit comments

Comments
 (0)