|
@@ -31,8 +31,9 @@ log.basicConfig(format='[%(asctime)s] %(message)s', level=log.INFO)
|
|
|
AUDIOS_PATH = '/tmp'
|
|
|
AHEAD_TIME_AUDIO_TOLERANCE = 2 # second
|
|
|
MAX_SEGMENT_THREADS = 4
|
|
|
-THRESHOLD = 8
|
|
|
-TOLERANCE = 0.7
|
|
|
+THRESHOLD = 10
|
|
|
+SEGMENTS_TOLERANCE_RATE = 0.6
|
|
|
+FALL_TOLERANCE_SEGMENTS = 1
|
|
|
|
|
|
# Modos de procesamiento de queue
|
|
|
# - QUEQUE_SINGLE: procesa solo un segmento a la vez
|
|
@@ -167,7 +168,9 @@ def process_segment(item, audios=None):
|
|
|
try:
|
|
|
audio = mutagen.mp3.MP3(filename)
|
|
|
segments_needed = int(round(float(audio.info.length) / float(5)))
|
|
|
- segments_needed = int(round(segments_needed * TOLERANCE))
|
|
|
+ segments_needed = int(round(
|
|
|
+ segments_needed * SEGMENTS_TOLERANCE_RATE
|
|
|
+ ))
|
|
|
except Exception as ex:
|
|
|
log.error('file {} is not an mp3'.format(audio))
|
|
|
log.error(str(ex))
|
|
@@ -203,8 +206,13 @@ def process_segment(item, audios=None):
|
|
|
'offset': match['offset']
|
|
|
})
|
|
|
values.append(str(match['confidence']))
|
|
|
+
|
|
|
except KeyError as ex:
|
|
|
- log.error(str(ex))
|
|
|
+ the_key = str(ex)
|
|
|
+ if the_key == 'confidence':
|
|
|
+ log.warning('Invalid confidence')
|
|
|
+ else:
|
|
|
+ log.warning(the_key)
|
|
|
|
|
|
ts += match['length'] / 1000
|
|
|
|
|
@@ -235,8 +243,9 @@ def process_segment(item, audios=None):
|
|
|
def find_repetitions(results, segments_needed=2):
|
|
|
found_counter = 0
|
|
|
found_index = None
|
|
|
- seconds_needed = 9
|
|
|
expect_space = False
|
|
|
+ expect_recover = False
|
|
|
+ last_value_in_threshold_index = -1
|
|
|
found = []
|
|
|
|
|
|
if segments_needed < 1:
|
|
@@ -246,11 +255,34 @@ def find_repetitions(results, segments_needed=2):
|
|
|
if not expect_space:
|
|
|
if result['confidence'] >= THRESHOLD:
|
|
|
found_counter += 1
|
|
|
+ last_value_in_threshold_index = index
|
|
|
if found_index is None:
|
|
|
found_index = index
|
|
|
+ if expect_recover:
|
|
|
+ expect_recover = False
|
|
|
+
|
|
|
+ elif FALL_TOLERANCE_SEGMENTS:
|
|
|
+ if not expect_recover:
|
|
|
+ if last_value_in_threshold_index != -1:
|
|
|
+ """ Solo cuando ya haya entrado por lo menos
|
|
|
+ un valor en el rango del threshold, es cuando
|
|
|
+ se podrá esperar un valor bajo """
|
|
|
+ expect_recover = True
|
|
|
+ found_counter += 1
|
|
|
+ else:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ """ Si después de haber pasado tolerado 1 elemento
|
|
|
+ vuelve a salir otro fuera del threshold continuo,
|
|
|
+ entonces ya se da por perdido """
|
|
|
+ found_counter = 0
|
|
|
+ found_index = None
|
|
|
+ expect_recover = False
|
|
|
+
|
|
|
else:
|
|
|
found_counter = 0
|
|
|
found_index = None
|
|
|
+ expect_recover = False
|
|
|
else:
|
|
|
if result['confidence'] <= THRESHOLD:
|
|
|
expect_space = False
|