1717import hmac
1818import subprocess
1919import multiprocessing
20+ import traceback
2021import platform
2122from xml .dom import minidom
2223import acrcloud_stream_decode
@@ -103,6 +104,8 @@ def __init__(self, worker_queue, stream_info, config):
103104 self ._is_stop = True
104105 self ._retry_n = 0
105106 self ._logger = logging .getLogger ('acrcloud_stream' )
107+ self ._current_time = round (time .time ())
108+ self ._time_update_point = 0
106109
107110 def run (self ):
108111 self ._is_stop = False
@@ -147,13 +150,20 @@ def _decode_callback(self, res_data):
147150 return 1
148151
149152 if res_data .get ('audio_data' ) != None :
150- task = (1 , res_data .get ('audio_data' ))
153+ data_secs = round (float (len (res_data .get ('audio_data' )))/ 16000 , 2 )
154+ self ._current_time = self ._current_time + data_secs
155+ self ._time_update_point = self ._time_update_point + data_secs
156+ if self ._time_update_point > 10 :
157+ self ._current_time = round (time .time ())
158+ self ._time_update_point = 0
159+ task = (1 , res_data .get ('audio_data' ), self ._current_time )
151160 self ._logger .info ("audio len:" + str (len (res_data .get ('audio_data' ))))
152161 self ._worker_queue .put (task )
153162 else :
154163 self ._logger .info (str (res_data ))
155164 return 0
156165 except Exception as e :
166+ traceback .print_exc ()
157167 self ._logger .error (str (e ))
158168
159169 def _check_url (self ):
@@ -262,7 +272,7 @@ def run(self):
262272 try :
263273 live_upload = True
264274 task = self ._worker_queue .get ()
265- task_type , now_buf = task
275+ task_type , now_buf , ts = task
266276 if task_type == 2 :
267277 self ._stream_info = now_buf
268278 cur_buf = last_buf + now_buf
@@ -281,7 +291,7 @@ def run(self):
281291 record_last_buf = record_last_buf + now_buf
282292 if len (record_last_buf ) > self ._record_upload_interval * 16000 :
283293 record_fp = acrcloud_stream_decode .create_fingerprint (record_last_buf , False , 50 )
284- if record_fp and self ._upload_record (record_fp ):
294+ if record_fp and self ._upload_record (record_fp , ts ):
285295 record_last_buf = ''
286296 else :
287297 if len (record_last_buf ) > self ._record_fp_max_time * 16000 :
@@ -312,11 +322,11 @@ def _upload(self, fp):
312322 self ._logger .error (acr_id + ":" + str (len (fp )) + ":" + str (e ))
313323
314324 return result
315- def _upload_record (self , fp ):
325+ def _upload_record (self , fp , ts ):
316326 result = True
317327 acr_id = self ._stream_info ['acr_id' ]
318328 stream_id = self ._stream_info ['id' ]
319- timestamp = int (time . time () )
329+ timestamp = int (ts )
320330 detail = str (stream_id )+ ":" + str (timestamp )
321331 try :
322332 host = self ._stream_info ['timeshift_host' ]
0 commit comments