def run(self): last_buf = '' record_last_buf = '' doc_pre_time = self._fp_time - self._fp_interval acr_id = self._stream_info['acr_id'] self._logger.info(acr_id + " ProcessFingerprintWorker running!") self._is_stop = False timeshift = self._stream_info.get('timeshift', 0) while not self._is_stop: try: live_upload = True task = self._worker_queue.get() task_type, now_buf, ts = task if task_type == 2: self._stream_info = now_buf cur_buf = last_buf + now_buf last_buf = cur_buf fp = acrcloud_stream_decode.create_fingerprint( cur_buf, False, 50) if fp and not self._upload(fp): live_upload = False if len(last_buf) > self._fp_max_time * 16000: last_buf = last_buf[len(last_buf) - self._fp_max_time * 16000:] if live_upload and len(last_buf) > doc_pre_time * 16000: last_buf = last_buf[-1 * doc_pre_time * 16000:] if timeshift: record_last_buf = record_last_buf + now_buf if len(record_last_buf ) > self._record_upload_interval * 16000: record_fp = acrcloud_stream_decode.create_fingerprint( record_last_buf, False, 50) if record_fp and self._upload_record( record_fp, ts): record_last_buf = '' else: if len(record_last_buf ) > self._record_fp_max_time * 16000: record_last_buf = record_last_buf[ len(last_buf) - self._record_fp_max_time * 16000:] except Exception as e: self._logger.error(str(e)) self._logger.info(acr_id + " ProcessFingerprintWorker stopped!")
def run(self): last_buf = b"" while not self.stopped.is_set(): live_upload = True buf = self.queue.get() cur_buf = last_buf + buf last_buf = cur_buf fingerprint = acrcloud_stream_decode.create_fingerprint( cur_buf, False) if fingerprint: try: self.upload_fingerprint(fingerprint) except Exception as e: logger.exception(e) live_upload = False if len(last_buf ) > self.fingerprint_max_time * self.sample_const: start = (len(last_buf) - self.fingerprint_max_time * self.sample_const) last_buf = last_buf[start:] if live_upload and len( last_buf) > self.doc_pre_time * self.sample_const: idx = -1 * self.doc_pre_time * self.sample_const last_buf = last_buf[idx:]
def run(self): last_buf = '' doc_pre_time = self._fp_time - self._fp_interval acr_id = self._stream_info['acr_id'] self._logger.info(acr_id + " ProcessFingerprintWorker running!") self._is_stop = False while not self._is_stop: try: now_buf = self._worker_queue.get() cur_buf = last_buf + now_buf last_buf = cur_buf fp = acrcloud_stream_decode.create_fingerprint( cur_buf, False) if fp and not self._upload(fp): if len(last_buf) > self._fp_max_time * 16000: last_buf = last_buf[len(last_buf) - self._fp_max_time * 16000:] continue if len(last_buf) > doc_pre_time * 16000: last_buf = last_buf[-1 * doc_pre_time * 16000:] except Exception as e: self._logger.error(str(e)) self._logger.info(acr_id + " ProcessFingerprintWorker stopped!")
def create_fingerprint(self, buf): audio_fingerprint_opt = { 'filter_energy_min': int(self._config['config']['rec']['filter_energy_min']), 'silence_energy_threshold': int(self._config['config']['rec']['silence_energy_threshold']), 'silence_rate_threshold': float(self._config['config']['rec']['silence_rate_threshold']) } return acrcloud_stream_decode.create_fingerprint( buf, False, audio_fingerprint_opt)
def gen_fp(self, buf, rate=0): return acrcloud_stream_decode.create_fingerprint(buf, False, 50)
def gen_fp(self, buf, rate=0): return acrcloud_stream_decode.create_fingerprint(buf, False)