Skip to content

Commit 6f8d161

Browse files
authored
fix(cli): valid SRT timestamps + clear json duration fields (#2982)
- SRT: when the model returns no per-sentence timestamps, the fallback used a bogus 99:59:59,999 end time. Now span the real audio duration so the SRT is valid. - json: duration_s was actually the processing time (a 60s file showed duration_s: 2.3). Split into audio_duration_s (real audio length) and processing_s (elapsed). Safe rename - the new CLI is unreleased. Found by smoke-testing the funasr CLI as a new user. Co-authored-by: LauraGPT <LauraGPT@users.noreply.github.com>
1 parent c39ff39 commit 6f8d161

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

funasr/cli.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,24 @@ def _format_output(text, segments, timestamps, fmt, audio_path, model_name, lang
4848
obj["segments"] = segments
4949
if timestamps:
5050
obj["timestamps"] = timestamps
51-
obj.update({"file": os.path.basename(audio_path), "model": model_name, "language": language or "auto", "duration_s": round(elapsed, 3)})
51+
try:
52+
import soundfile as sf
53+
audio_dur = round(sf.info(audio_path).duration, 3)
54+
except Exception:
55+
audio_dur = None
56+
obj.update({"file": os.path.basename(audio_path), "model": model_name, "language": language or "auto", "audio_duration_s": audio_dur, "processing_s": round(elapsed, 3)})
5257
return json.dumps(obj, ensure_ascii=False, indent=2)
5358
elif fmt == "srt":
54-
return format_srt(segments) if segments else f"1\n00:00:00,000 --> 99:59:59,999\n{text}\n"
59+
if segments:
60+
return format_srt(segments)
61+
# No per-sentence timestamps: emit one valid cue spanning the whole audio
62+
# (instead of a bogus 99:59:59 end time).
63+
try:
64+
import soundfile as sf
65+
dur_ms = int(sf.info(audio_path).duration * 1000)
66+
except Exception:
67+
dur_ms = 0
68+
return f"1\n00:00:00,000 --> {_srt_time(dur_ms)}\n{text}\n"
5569
elif fmt == "tsv":
5670
return format_tsv(segments) if segments else f"start\tend\ttext\n0.000\t0.000\t{text}"
5771

0 commit comments

Comments
 (0)