Skip to content

Commit c095cd0

Browse files
committed
stream
1 parent 20f519c commit c095cd0

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

linux/x86-64/stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import hmac
1818
import subprocess
1919
import multiprocessing
20+
import traceback
2021
import platform
2122
from xml.dom import minidom
2223
import acrcloud_stream_decode
@@ -149,7 +150,7 @@ def _decode_callback(self, res_data):
149150
return 1
150151

151152
if res_data.get('audio_data') != None:
152-
data_secs = round(res_data.get('audio_data')/16000)
153+
data_secs = round(float(len(res_data.get('audio_data')))/16000, 2)
153154
self._current_time = self._current_time + data_secs
154155
self._time_update_point = self._time_update_point + data_secs
155156
if self._time_update_point > 10:
@@ -162,6 +163,7 @@ def _decode_callback(self, res_data):
162163
self._logger.info(str(res_data))
163164
return 0
164165
except Exception as e:
166+
traceback.print_exc()
165167
self._logger.error(str(e))
166168

167169
def _check_url(self):
@@ -324,7 +326,7 @@ def _upload_record(self, fp, ts):
324326
result = True
325327
acr_id = self._stream_info['acr_id']
326328
stream_id = self._stream_info['id']
327-
timestamp = ts
329+
timestamp = int(ts)
328330
detail = str(stream_id)+":"+str(timestamp)
329331
try:
330332
host = self._stream_info['timeshift_host']

raspberrypi/python2.7/stream.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import hmac
1818
import subprocess
1919
import multiprocessing
20+
import traceback
2021
import platform
2122
from xml.dom import minidom
2223
import 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']

windows/win32/stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import hmac
1818
import subprocess
1919
import multiprocessing
20+
import traceback
2021
import platform
2122
from xml.dom import minidom
2223
import acrcloud_stream_decode
@@ -149,7 +150,7 @@ def _decode_callback(self, res_data):
149150
return 1
150151

151152
if res_data.get('audio_data') != None:
152-
data_secs = round(res_data.get('audio_data')/16000)
153+
data_secs = round(float(len(res_data.get('audio_data')))/16000, 2)
153154
self._current_time = self._current_time + data_secs
154155
self._time_update_point = self._time_update_point + data_secs
155156
if self._time_update_point > 10:
@@ -162,6 +163,7 @@ def _decode_callback(self, res_data):
162163
self._logger.info(str(res_data))
163164
return 0
164165
except Exception as e:
166+
traceback.print_exc()
165167
self._logger.error(str(e))
166168

167169
def _check_url(self):
@@ -324,7 +326,7 @@ def _upload_record(self, fp, ts):
324326
result = True
325327
acr_id = self._stream_info['acr_id']
326328
stream_id = self._stream_info['id']
327-
timestamp = ts
329+
timestamp = int(ts)
328330
detail = str(stream_id)+":"+str(timestamp)
329331
try:
330332
host = self._stream_info['timeshift_host']

windows/win64/stream.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import hmac
1818
import subprocess
1919
import multiprocessing
20+
import traceback
2021
import platform
2122
from xml.dom import minidom
2223
import acrcloud_stream_decode
@@ -149,7 +150,7 @@ def _decode_callback(self, res_data):
149150
return 1
150151

151152
if res_data.get('audio_data') != None:
152-
data_secs = round(res_data.get('audio_data')/16000)
153+
data_secs = round(float(len(res_data.get('audio_data')))/16000, 2)
153154
self._current_time = self._current_time + data_secs
154155
self._time_update_point = self._time_update_point + data_secs
155156
if self._time_update_point > 10:
@@ -162,6 +163,7 @@ def _decode_callback(self, res_data):
162163
self._logger.info(str(res_data))
163164
return 0
164165
except Exception as e:
166+
traceback.print_exc()
165167
self._logger.error(str(e))
166168

167169
def _check_url(self):
@@ -324,7 +326,7 @@ def _upload_record(self, fp, ts):
324326
result = True
325327
acr_id = self._stream_info['acr_id']
326328
stream_id = self._stream_info['id']
327-
timestamp = ts
329+
timestamp = int(ts)
328330
detail = str(stream_id)+":"+str(timestamp)
329331
try:
330332
host = self._stream_info['timeshift_host']

0 commit comments

Comments
 (0)