changeset 311:ccad269ee0a0

Pass detection timestamp in audio region metadata in TokenizerWorker
author Amine Sehili <amine.sehili@gmail.com>
date Sun, 13 Oct 2019 17:18:40 +0200
parents 323a662227ee
children bf374186f80f
files auditok/workers.py
diffstat 1 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/auditok/workers.py	Sat Oct 12 18:47:12 2019 +0100
+++ b/auditok/workers.py	Sun Oct 13 17:18:40 2019 +0200
@@ -42,7 +42,6 @@
     def __init__(self, timeout=0.5, logger=None):
         self._timeout = timeout
         self._logger = logger
-        self._start_processing_timestamp = None
         self._inbox = Queue()
         Thread.__init__(self)
 
@@ -109,16 +108,14 @@
         for observer in self._observers:
             observer.send(message)
 
-    def _init_start_processing_timestamp(self):
-        timestamp = datetime.now()
-        self._start_processing_timestamp = timestamp
-        for observer in self._observers:
-            observer._start_processing_timestamp = timestamp
-
     def run(self):
         self._reader.open()
-        self._init_start_processing_timestamp()
+        start_processing_timestamp = datetime.now()
         for _id, audio_region in enumerate(self._audio_region_gen, start=1):
+            timestamp = start_processing_timestamp + timedelta(
+                seconds=audio_region.meta.start
+            )
+            audio_region.meta.timestamp = timestamp
             detection = _Detection(
                 _id,
                 audio_region.meta.start,
@@ -419,9 +416,7 @@
 
     def _process_message(self, message):
         _id, audio_region = message
-        timestamp = self._start_processing_timestamp + timedelta(
-            seconds=audio_region.meta.start
-        )
+        timestamp = audio_region.meta.timestamp
         timestamp = timestamp.strftime(self._timestamp_format)
         text = self._print_format.format(
             id=_id,