MCPcopy Create free account
hub / github.com/modelscope/FunASR / timestamp_sentence

Function timestamp_sentence

funasr/utils/timestamp_tools.py:125–220  ·  view source on GitHub ↗

Split recognized text into sentences using punctuation, with timestamps. Args: punc_id_list (Tensor/list): Punctuation IDs from CT-Transformer. Values: 1=none, 2=comma, 3=period, 4=question. timestamp_postprocessed (list): Per-character timestamps [[start_ms, end_ms]

(
    punc_id_list, timestamp_postprocessed, text_postprocessed, return_raw_text=False
)

Source from the content-addressed store, hash-verified

123
124
125def timestamp_sentence(
126 punc_id_list, timestamp_postprocessed, text_postprocessed, return_raw_text=False
127):
128
129 """Split recognized text into sentences using punctuation, with timestamps.
130
131 Args:
132 punc_id_list (Tensor/list): Punctuation IDs from CT-Transformer.
133 Values: 1=none, 2=comma, 3=period, 4=question.
134 timestamp_postprocessed (list): Per-character timestamps [[start_ms, end_ms], ...].
135 text_postprocessed (str): Space-separated recognized text.
136 return_raw_text (bool): Include raw_text in output.
137
138 Returns:
139 list[dict]: Sentences with keys: text, start, end, timestamp, [raw_text].
140 """
141 punc_list = [",", "。", "?", "、"]
142 res = []
143 if text_postprocessed is None:
144 return res
145 if timestamp_postprocessed is None:
146 return res
147 if len(timestamp_postprocessed) == 0:
148 return res
149 if len(text_postprocessed) == 0:
150 return res
151
152 if punc_id_list is None or len(punc_id_list) == 0:
153 res.append(
154 {
155 "text": text_postprocessed.split(),
156 "start": timestamp_postprocessed[0][0],
157 "end": timestamp_postprocessed[-1][1],
158 "timestamp": timestamp_postprocessed,
159 }
160 )
161 return res
162 if len(punc_id_list) != len(timestamp_postprocessed):
163 logging.warning("length mismatch between punc and timestamp")
164 sentence_text = ""
165 sentence_text_seg = ""
166 ts_list = []
167 sentence_start = timestamp_postprocessed[0][0]
168 sentence_end = timestamp_postprocessed[0][1]
169 texts = text_postprocessed.split()
170 punc_stamp_text_list = list(
171 zip_longest(punc_id_list, timestamp_postprocessed, texts, fillvalue=None)
172 )
173 for punc_stamp_text in punc_stamp_text_list:
174 punc_id, timestamp, text = punc_stamp_text
175 if sentence_start is None and timestamp is not None:
176 sentence_start = timestamp[0]
177 # sentence_text += text if text is not None else ''
178 if text is not None:
179 if "a" <= text[0] <= "z" or "A" <= text[0] <= "Z":
180 sentence_text += " " + text
181 elif len(sentence_text) and (
182 "a" <= sentence_text[-1] <= "z" or "A" <= sentence_text[-1] <= "Z"

Callers 1

inference_with_vadMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…