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

Function postprocess

funasr/utils/speaker_utils.py:128–175  ·  view source on GitHub ↗

Postprocess. Args: segments: TODO. vad_segments: TODO. labels: TODO. embeddings: TODO.

(
    segments: list, vad_segments: list, labels: np.ndarray, embeddings: np.ndarray
)

Source from the content-addressed store, hash-verified

126
127
128def postprocess(
129 segments: list, vad_segments: list, labels: np.ndarray, embeddings: np.ndarray
130) -> list:
131 """Postprocess.
132
133 Args:
134 segments: TODO.
135 vad_segments: TODO.
136 labels: TODO.
137 embeddings: TODO.
138 """
139 assert len(segments) == len(labels)
140 labels = correct_labels(labels)
141 distribute_res = []
142 for i in range(len(segments)):
143 distribute_res.append([segments[i][0], segments[i][1], labels[i]])
144 # merge the same speakers chronologically
145 distribute_res = merge_seque(distribute_res)
146
147 # accquire speaker center
148 spk_embs = []
149 for i in range(labels.max() + 1):
150 spk_emb = embeddings[labels == i].mean(0)
151 spk_embs.append(spk_emb)
152 spk_embs = np.stack(spk_embs)
153
154 def is_overlapped(t1, t2):
155 """Is overlapped.
156
157 Args:
158 t1: TODO.
159 t2: TODO.
160 """
161 if t1 > t2 + 1e-4:
162 return True
163 return False
164
165 # distribute the overlap region
166 for i in range(1, len(distribute_res)):
167 if is_overlapped(distribute_res[i - 1][1], distribute_res[i][0]):
168 p = (distribute_res[i][0] + distribute_res[i - 1][1]) / 2
169 distribute_res[i][0] = p
170 distribute_res[i - 1][1] = p
171
172 # smooth the result
173 distribute_res = smooth(distribute_res)
174
175 return distribute_res
176
177
178def correct_labels(labels):

Callers 3

inference_with_vadMethod · 0.90
process_audioFunction · 0.90
websocket_endpointFunction · 0.90

Calls 4

correct_labelsFunction · 0.70
merge_sequeFunction · 0.70
is_overlappedFunction · 0.70
smoothFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…