MCPcopy Index your code
hub / github.com/modelscope/FunASR / _format_output

Function _format_output

funasr/cli.py:42–70  ·  view source on GitHub ↗
(text, segments, timestamps, fmt, audio_path, model_name, language, elapsed)

Source from the content-addressed store, hash-verified

40
41
42def _format_output(text, segments, timestamps, fmt, audio_path, model_name, language, elapsed):
43 if fmt == "text":
44 return text
45 elif fmt == "json":
46 obj = {"text": text}
47 if segments:
48 obj["segments"] = segments
49 if timestamps:
50 obj["timestamps"] = timestamps
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)})
57 return json.dumps(obj, ensure_ascii=False, indent=2)
58 elif fmt == "srt":
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"
69 elif fmt == "tsv":
70 return format_tsv(segments) if segments else f"start\tend\ttext\n0.000\t0.000\t{text}"
71
72
73def _get_version():

Callers 1

mainFunction · 0.85

Calls 4

format_srtFunction · 0.85
_srt_timeFunction · 0.85
format_tsvFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…