From f9d36ebb6ed299a64a518378b031ba6f16d843fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcin=20W=C4=85troba?= <markowanga@gmail.com>
Date: Tue, 5 Oct 2021 14:43:47 +0200
Subject: [PATCH] Add words_time_alignment to asr

---
 sziszapangma/.DS_Store                        | Bin 6148 -> 6148 bytes
 .../service_core/asr/asr_base_processor.py    |  12 +++++++++---
 .../service_core/asr/asr_result.py            |   9 ++++++++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/sziszapangma/.DS_Store b/sziszapangma/.DS_Store
index 2fff18096fcf72463ee45cf922f8040ac30b2e8a..b4c1ad28389434242f75e13e11d1692bf083ec69 100644
GIT binary patch
literal 6148
zcmeHKJx{|h5IxfjRVzeB28R5FZXMGqFe7zh>bKHL%?G6*vE{$9BN$lV&+yJ?+C*(Y
zEC|6}<$JDuXFosHc1=X4e>>|C`9#!2Vf0#X2aNl<?AeiPIR+X##+1f1r3KAtxEHMr
zs(>o++Z5ov+s1AkQcm~SySx26T*aNiG)r=!eD+iynPgEkS!EMMG{@bSo`3Ps`z(6)
zjp%$)W)Wgo^1w5rHO(swP2;58SLT$CuAX1#meV#j$#yIb^;hO?@U+yzxt7obeumGI
zQi|#3Zm>>QSsJ4sXCSoX_6=fUFdU<{1lP36bn{jpS>}EDc>Te<X58{BzK*V}$pZ(q
z|EvK2USZ9)pn6q66;K7X3h?<5pfH9G3qgByz}Y7NaC@1c&Tk3M2^@wF3qkb2jHCi3
z)wm~yk#w{NE-rLf2ueB`_xLbwX5(Hc#?FrM0~<~z6jZMYr~*|5<X<iMeE*-<zyGUA
z`b`y31^$!*#)}3~A4_s~>)zt{t_@H|C~O>82-*}lcOBabU&W^=*3cJl1sFOk1knQ1
OKLS<;b*jLRD)0_NQGRm(

delta 91
zcmZoMXfc=|#>CJzu~2NHo}wrt0|NsP3otOG0AVIW9z!}q@x(%PM#jk|tm>OZID}a?
oHaIeGX6NAN0P5N-$nl+dGQWr}CrIM~AZD0s!y~;pMq~*y0Cv+8JOBUy

diff --git a/sziszapangma/integration/service_core/asr/asr_base_processor.py b/sziszapangma/integration/service_core/asr/asr_base_processor.py
index ee15a08..a447dc2 100644
--- a/sziszapangma/integration/service_core/asr/asr_base_processor.py
+++ b/sziszapangma/integration/service_core/asr/asr_base_processor.py
@@ -36,13 +36,19 @@ class AsrBaseProcessor(ABC):
             try:
                 transcription = self.process_asr(file_path)
                 os.remove(file_path)
-                result_object = jsonify(
-                    {"transcription": transcription.words, "full_text": transcription.full_text}
-                )
+                response_dict = {
+                    "transcription": transcription.words,
+                    "full_text": transcription.full_text,
+                    "words_time_alignment": transcription.words_time_alignment
+                }
+                result_object = jsonify(response_dict)
             except Exception as exception:
                 print(exception)
                 traceback.print_exc()
                 result_object = jsonify({"error": "Error on asr processing"})
+            finally:
+                if os.path.isfile(file_path):
+                    os.remove(file_path)
         else:
             result_object = jsonify({"error": "Error on asr processing"})
         return result_object
diff --git a/sziszapangma/integration/service_core/asr/asr_result.py b/sziszapangma/integration/service_core/asr/asr_result.py
index cdf7c20..dd65f55 100644
--- a/sziszapangma/integration/service_core/asr/asr_result.py
+++ b/sziszapangma/integration/service_core/asr/asr_result.py
@@ -1,8 +1,15 @@
 from dataclasses import dataclass
-from typing import List
+from typing import List, Optional
+
+
+@dataclass(frozen=True)
+class WordTimeAlignment:
+    start_ms: float
+    end_ms: float
 
 
 @dataclass(frozen=True)
 class AsrResult:
     words: List[str]
     full_text: str
+    words_time_alignment: Optional[List[WordTimeAlignment]]
-- 
GitLab