From 50c4d8a096c7594858ff077b1dc845dcb8d3d736 Mon Sep 17 00:00:00 2001 From: HeNine <> Date: Sun, 7 Nov 2021 11:20:06 +0100 Subject: [PATCH] Final result sometimes has no content (if segments are missing after silence?) --- buscribe/buscribe/buscribe.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/buscribe/buscribe/buscribe.py b/buscribe/buscribe/buscribe.py index 7ece7c8..aa32519 100644 --- a/buscribe/buscribe/buscribe.py +++ b/buscribe/buscribe/buscribe.py @@ -94,9 +94,10 @@ def finish_off_recognizer(recognizer: BuscribeRecognizer, db_cursor): """Flush the recognizer, commit the final line to the database and reset it.""" final_result_json = json.loads(recognizer.final_result()) # Flush the tubes - line_start_time = recognizer.segments_start_time + timedelta(seconds=final_result_json["result"][0]["start"]) - line_end_time = recognizer.segments_start_time + timedelta(seconds=final_result_json["result"][-1]["end"]) + if "result" in final_result_json: + line_start_time = recognizer.segments_start_time + timedelta(seconds=final_result_json["result"][0]["start"]) + line_end_time = recognizer.segments_start_time + timedelta(seconds=final_result_json["result"][-1]["end"]) - write_line(final_result_json, line_start_time, line_end_time, db_cursor) + write_line(final_result_json, line_start_time, line_end_time, db_cursor) recognizer.reset()