Skip to content

Commit

Permalink
revert the change of end_time (#63)
Browse files Browse the repository at this point in the history
* revert the change of end_time

* Add option to add extra duration on left/right
  • Loading branch information
pkufool authored Feb 6, 2024
1 parent b745e5c commit bc2bed3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(textsearch)

set(TS_VERSION "0.11")
set(TS_VERSION "0.12")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
Expand Down
4 changes: 4 additions & 0 deletions examples/libriheavy/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def get_params() -> AttributeDict:
# you can find the docs in textsearch/match.py#split_aligned_queries
"preceding_context_length": 1000,
"timestamp_position": "current",
"duration_add_on_left": 0.0,
"duration_add_on_right": 0.5,
"silence_length_to_break": 0.45,
"overlap_ratio": 0.25,
"min_duration": 2,
Expand Down Expand Up @@ -322,6 +324,8 @@ def split(
process_pool=process_pool,
preceding_context_length=params.preceding_context_length,
timestamp_position=params.timestamp_position,
duration_add_on_left=params.duration_add_on_left,
duration_add_on_right=params.duration_add_on_right,
silence_length_to_break=params.silence_length_to_break,
overlap_ratio=params.overlap_ratio,
min_duration=params.min_duration,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fasttextsearch"
version = "0.11"
version = "0.12"
authors = [
{ name="Next-gen Kaldi development team", email="[email protected]" },
]
Expand Down
18 changes: 17 additions & 1 deletion textsearch/python/textsearch/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,8 @@ def _split_into_segments(
alignment: Tuple[Tuple[int, int], List[Dict[str, Any]]],
preceding_context_length: int = 1000,
timestamp_position: str = "middle", # previous, middle, current
duration_add_on_left: float = 0.0, # in second
duration_add_on_right: float = 0.5, # in second
silence_length_to_break: float = 0.6, # in second
overlap_ratio: float = 0.35, # percentage
min_duration: float = 2, # in second
Expand Down Expand Up @@ -1005,6 +1007,12 @@ def _split_into_segments(
`previous` the `start_time` is the timestamp of token in `begin_pos - 1`
if it equals to `middle`, the `start_time` is the averaged timestamp of
tokens in `begin_pos` and `begin_pos - 1`.
duration_add_on_left:
The extra duration added on the left (in second), to compensate the inaccuracy
of timestamps of the ASR model.
duration_add_on_right:
The extra duration added on the right (in second), to compensate the inaccuracy
of timestamps of the ASR model.
silence_length_to_break:
A threshold for deciding the possible breaking points, if a position has
preceding or succeeding silence length greater than this value, we will
Expand Down Expand Up @@ -1138,7 +1146,7 @@ def _split_into_segments(
"current",
)
start_time = aligns[seg[0]]["hyp_time"]
end_time = aligns[seg[1]]["hyp_time"]
end_time = aligns[succeeding_index]["hyp_time"]

hyp_begin_pos = aligns[seg[0]]["hyp_pos"]
while chr(query_source.binary_text[hyp_begin_pos]) == " ":
Expand Down Expand Up @@ -1221,6 +1229,8 @@ def _split_helper(
alignment: Tuple[Tuple[int, int], List[Dict[str, Any]]],
preceding_context_length: int,
timestamp_position: str,
duration_add_on_left: float,
duration_add_on_right: float,
silence_length_to_break: float,
overlap_ratio: float,
min_duration: float,
Expand All @@ -1238,6 +1248,8 @@ def _split_helper(
alignment,
preceding_context_length=preceding_context_length,
timestamp_position=timestamp_position,
duration_add_on_left=duration_add_on_left,
duration_add_on_right=duration_add_on_right,
silence_length_to_break=silence_length_to_break,
overlap_ratio=overlap_ratio,
min_duration=min_duration,
Expand All @@ -1256,6 +1268,8 @@ def split_aligned_queries(
process_pool: Optional[Pool] = None,
preceding_context_length: int = 1000,
timestamp_position: str = "current", # previous, middle, current
duration_add_on_left: float = 0.0, # in second
duration_add_on_right: float = 0.5, # in second
silence_length_to_break: float = 0.6, # in second
overlap_ratio: float = 0.35,
min_duration: float = 2, # in second
Expand Down Expand Up @@ -1353,6 +1367,8 @@ def split_aligned_queries(
alignments[i],
preceding_context_length,
timestamp_position,
duration_add_on_left,
duration_add_on_right,
silence_length_to_break,
overlap_ratio,
min_duration,
Expand Down

0 comments on commit bc2bed3

Please sign in to comment.