raphaelbiojout commited on
Commit ·
8c6a1ad
1
Parent(s): 14c99c5
update
Browse files- handler.py +28 -23
handler.py
CHANGED
|
@@ -212,14 +212,18 @@ class EndpointHandler():
|
|
| 212 |
parameters = data.pop("parameters", None)
|
| 213 |
options = data.pop("options", None)
|
| 214 |
|
| 215 |
-
# OPTIONS
|
| 216 |
info = False
|
| 217 |
-
if options and "info" in options.keys() and info:
|
| 218 |
info = True
|
| 219 |
|
| 220 |
alignment = False
|
| 221 |
-
if options and "alignment" in options.keys() and alignment:
|
| 222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
language = "fr"
|
| 225 |
if parameters and "language" in parameters.keys():
|
|
@@ -288,26 +292,27 @@ class EndpointHandler():
|
|
| 288 |
print(f"TIME for alignment : {elapsed_time:.2f} seconds")
|
| 289 |
|
| 290 |
# 4. Assign speaker labels
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
| 298 |
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
|
| 312 |
# results_json = json.dumps(results)
|
| 313 |
# return {"results": results_json}
|
|
|
|
| 212 |
parameters = data.pop("parameters", None)
|
| 213 |
options = data.pop("options", None)
|
| 214 |
|
| 215 |
+
# OPTIONS are given as parameters
|
| 216 |
info = False
|
| 217 |
+
if options and "info" in options.keys() and options['info']:
|
| 218 |
info = True
|
| 219 |
|
| 220 |
alignment = False
|
| 221 |
+
if options and "alignment" in options.keys() and options['alignment']:
|
| 222 |
+
alignment = True
|
| 223 |
+
|
| 224 |
+
diarization = True
|
| 225 |
+
if options and "diarization" in options.keys() and not options['diarization']:
|
| 226 |
+
diarization = False
|
| 227 |
|
| 228 |
language = "fr"
|
| 229 |
if parameters and "language" in parameters.keys():
|
|
|
|
| 292 |
print(f"TIME for alignment : {elapsed_time:.2f} seconds")
|
| 293 |
|
| 294 |
# 4. Assign speaker labels
|
| 295 |
+
if diarization:
|
| 296 |
+
logger.info("--------------- STARTING DIARIZATION ------------------------")
|
| 297 |
+
# add min/max number of speakers if known
|
| 298 |
+
diarize_segments = self.diarize_model(audio_nparray)
|
| 299 |
+
if info:
|
| 300 |
+
print(diarize_segments)
|
| 301 |
+
logger.info(diarize_segments)
|
| 302 |
+
# diarize_model(audio, min_speakers=min_speakers, max_speakers=max_speakers)
|
| 303 |
|
| 304 |
+
transcription = whisperx.assign_word_speakers(diarize_segments, transcription)
|
| 305 |
+
if info:
|
| 306 |
+
print(transcription["segments"][0:10000])
|
| 307 |
+
logger.info(transcription["segments"][0:10000]) # segments are now assigned speaker IDs
|
| 308 |
+
|
| 309 |
+
# get the execution time
|
| 310 |
+
et = time.time()
|
| 311 |
+
elapsed_time = et - st
|
| 312 |
+
st = time.time()
|
| 313 |
+
logger.info(f"TIME for audio diarization : {elapsed_time:.2f} seconds")
|
| 314 |
+
if info:
|
| 315 |
+
print(f"TIME for audio diarization : {elapsed_time:.2f} seconds")
|
| 316 |
|
| 317 |
# results_json = json.dumps(results)
|
| 318 |
# return {"results": results_json}
|