Spaces:
Runtime error
Runtime error
Update scraibe/diarisation.py
Browse files- scraibe/diarisation.py +68 -42
scraibe/diarisation.py
CHANGED
|
@@ -87,68 +87,94 @@ class Diariser:
|
|
| 87 |
|
| 88 |
return out
|
| 89 |
|
| 90 |
-
@staticmethod
|
| 91 |
-
def format_diarization_output(dia: Annotation) -> dict:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
|
| 122 |
-
|
| 123 |
-
current_speaker = speaker
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
current_speaker])
|
| 132 |
|
| 133 |
-
|
| 134 |
-
current_speaker = speaker
|
| 135 |
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
diarization_output["segments"].append([start, end])
|
| 149 |
-
diarization_output["speakers"].append(
|
|
|
|
| 150 |
return diarization_output
|
| 151 |
|
|
|
|
| 152 |
@staticmethod
|
| 153 |
def _get_token():
|
| 154 |
"""
|
|
|
|
| 87 |
|
| 88 |
return out
|
| 89 |
|
| 90 |
+
# @staticmethod
|
| 91 |
+
# def format_diarization_output(dia: Annotation) -> dict:
|
| 92 |
+
# """
|
| 93 |
+
# Formats the raw diarization output into a more usable structure for this project.
|
| 94 |
|
| 95 |
+
# Args:
|
| 96 |
+
# dia: Raw diarization output.
|
| 97 |
|
| 98 |
+
# Returns:
|
| 99 |
+
# dict: A structured representation of the diarization, with speaker names
|
| 100 |
+
# as keys and a list of tuples representing segments as values.
|
| 101 |
+
# """
|
| 102 |
|
| 103 |
+
# dia_list = list(dia.itertracks(yield_label=True))
|
| 104 |
+
# diarization_output = {"speakers": [], "segments": []}
|
| 105 |
|
| 106 |
+
# normalized_output = []
|
| 107 |
+
# index_start_speaker = 0
|
| 108 |
+
# index_end_speaker = 0
|
| 109 |
+
# current_speaker = str()
|
| 110 |
|
| 111 |
+
# ###
|
| 112 |
+
# # Sometimes two consecutive speakers are the same
|
| 113 |
+
# # This loop removes these duplicates
|
| 114 |
+
# ###
|
| 115 |
|
| 116 |
+
# if len(dia_list) == 1:
|
| 117 |
+
# normalized_output.append([0, 0, dia_list[0][2]])
|
| 118 |
+
# else:
|
| 119 |
+
|
| 120 |
+
# for i, (_, _, speaker) in enumerate(dia_list):
|
| 121 |
|
| 122 |
+
# if i == 0:
|
| 123 |
+
# current_speaker = speaker
|
| 124 |
|
| 125 |
+
# if speaker != current_speaker:
|
|
|
|
| 126 |
|
| 127 |
+
# index_end_speaker = i - 1
|
| 128 |
|
| 129 |
+
# normalized_output.append([index_start_speaker,
|
| 130 |
+
# index_end_speaker,
|
| 131 |
+
# current_speaker])
|
| 132 |
|
| 133 |
+
# index_start_speaker = i
|
| 134 |
+
# current_speaker = speaker
|
|
|
|
| 135 |
|
| 136 |
+
# if i == len(dia_list) - 1:
|
|
|
|
| 137 |
|
| 138 |
+
# index_end_speaker = i
|
| 139 |
|
| 140 |
+
# normalized_output.append([index_start_speaker,
|
| 141 |
+
# index_end_speaker,
|
| 142 |
+
# current_speaker])
|
| 143 |
|
| 144 |
+
# for outp in normalized_output:
|
| 145 |
+
# start = dia_list[outp[0]][0].start
|
| 146 |
+
# end = dia_list[outp[1]][0].end
|
| 147 |
|
| 148 |
+
# diarization_output["segments"].append([start, end])
|
| 149 |
+
# diarization_output["speakers"].append(outp[2])
|
| 150 |
+
# return diarization_output
|
| 151 |
+
|
| 152 |
+
@staticmethod
|
| 153 |
+
def format_diarization_output(dia: Annotation) -> dict:
|
| 154 |
+
"""
|
| 155 |
+
Formats the raw diarization output into a more usable structure for this project,
|
| 156 |
+
without combining consecutive segments of the same speaker.
|
| 157 |
+
|
| 158 |
+
Args:
|
| 159 |
+
dia: Raw diarization output.
|
| 160 |
+
|
| 161 |
+
Returns:
|
| 162 |
+
dict: A structured representation of the diarization, with speaker names
|
| 163 |
+
as keys and a list of tuples representing segments as values.
|
| 164 |
+
"""
|
| 165 |
+
dia_list = list(dia.itertracks(yield_label=True))
|
| 166 |
+
diarization_output = {"speakers": [], "segments": []}
|
| 167 |
+
|
| 168 |
+
for segment, _, speaker in dia_list:
|
| 169 |
+
start = segment.start
|
| 170 |
+
end = segment.end
|
| 171 |
|
| 172 |
diarization_output["segments"].append([start, end])
|
| 173 |
+
diarization_output["speakers"].append(speaker)
|
| 174 |
+
|
| 175 |
return diarization_output
|
| 176 |
|
| 177 |
+
|
| 178 |
@staticmethod
|
| 179 |
def _get_token():
|
| 180 |
"""
|