Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions funasr/utils/timestamp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,10 @@ def timestamp_sentence(
return res

if punc_id_list is None or len(punc_id_list) == 0:
res.append(
{
"text": text_postprocessed.split(),
"start": timestamp_postprocessed[0][0],
"end": timestamp_postprocessed[-1][1],
"timestamp": timestamp_postprocessed,
}
)
return res
if len(punc_id_list) != len(timestamp_postprocessed):
# No punctuation: the loop below yields a single sentence whose text is a
# string, like every other result.
punc_id_list = []
elif len(punc_id_list) != len(timestamp_postprocessed):
logging.warning("length mismatch between punc and timestamp")
sentence_text = ""
sentence_text_seg = ""
Expand Down Expand Up @@ -257,16 +251,10 @@ def timestamp_sentence_en(
return res

if punc_id_list is None or len(punc_id_list) == 0:
res.append(
{
"text": text_postprocessed.split(),
"start": timestamp_postprocessed[0][0],
"end": timestamp_postprocessed[-1][1],
"timestamp": timestamp_postprocessed,
}
)
return res
if len(punc_id_list) != len(timestamp_postprocessed):
# No punctuation: the loop below yields a single sentence whose text is a
# string, like every other result.
punc_id_list = []
elif len(punc_id_list) != len(timestamp_postprocessed):
logging.warning("length mismatch between punc and timestamp")
sentence_text = ""
sentence_text_seg = ""
Expand Down
15 changes: 15 additions & 0 deletions tests/test_timestamp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ def test_timestamp_sentence_does_not_emit_tail_without_its_timestamp(splitter):

assert len(result) == 1
assert result[0]["end"] == 200


@pytest.mark.parametrize("punc_id_list", [None, []])
def test_timestamp_sentence_without_punctuation_returns_string_text(punc_id_list):
timestamps = [[0, 100], [100, 200]]

zh = timestamp_sentence(punc_id_list, timestamps, "你 好", return_raw_text=True)
en = timestamp_sentence_en(punc_id_list, timestamps, "hello world", return_raw_text=True)

assert zh == [
{"text": "你好", "start": 0, "end": 200, "timestamp": timestamps, "raw_text": "你 好"}
]
assert en == [
{"text": "hello world", "start": 0, "end": 200, "timestamp": timestamps, "raw_text": "hello world"}
]