- no more scheduled runs in offline mode - only interactive calls

This commit is contained in:
Dmytro Bogovych 2023-09-21 05:18:07 +01:00
parent cd9c250c95
commit 598456b830
3 changed files with 38 additions and 31 deletions

View File

@ -69,23 +69,23 @@ def detect_degraded_signal(file_test: Path, file_reference: Path) -> SignalBound
# Seems some problem with recording, return zero boundaries # Seems some problem with recording, return zero boundaries
return SignalBoundaries() return SignalBoundaries()
r = SignalBoundaries()
if CONFIG.UseSpeechDetector: if CONFIG.UseSpeechDetector:
r = bt_signal.find_reference_signal_via_speechdetector(file_test) r = bt_signal.find_reference_signal_via_speechdetector(file_test)
else:
r = bt_signal.find_reference_signal(file_test)
if r.offset_start == 0.0 and is_caller: if r.offset_start == 0.0 and is_caller:
r.offset_start = 5.0 # Skip ringing tones r.offset_start = 5.0 # Skip ringing tones
return r return r
def detect_reference_signal(file_reference: Path) -> SignalBoundaries: def detect_reference_signal(file_reference: Path) -> SignalBoundaries:
# Run silence eraser on reference file as well # Run silence eraser on reference file as well
result = SignalBoundaries()
if CONFIG.UseSpeechDetector: if CONFIG.UseSpeechDetector:
result = bt_signal.find_reference_signal_via_speechdetector(file_reference) result = bt_signal.find_reference_signal_via_speechdetector(file_reference)
else:
result = bt_signal.find_reference_signal(file_reference)
return result return result
@ -358,6 +358,7 @@ def run_caller_task(t):
# Runs caller probe - load task list and perform calls # Runs caller probe - load task list and perform calls
def run_probe(): def run_probe():
global TASK_LIST, CURRENT_TASK global TASK_LIST, CURRENT_TASK
offline_mode : bool = False
while True: while True:
# Get task list update # Get task list update
@ -366,6 +367,7 @@ def run_probe():
# Check in cache # Check in cache
utils.log('Checking for task list in cache...') utils.log('Checking for task list in cache...')
new_tasks = CACHE.get_tasks(BACKEND.phone.name) new_tasks = CACHE.get_tasks(BACKEND.phone.name)
offline_mode = True
# Did we fetch anything ? # Did we fetch anything ?
if new_tasks: if new_tasks:
@ -401,7 +403,9 @@ def run_probe():
# Remove sheduled time # Remove sheduled time
del t['scheduled_time'] del t['scheduled_time']
# Run task # Run task if we are online
# Otherwise tasks run from the API point - via helper .apk
if not offline_mode:
run_caller_task(t) run_caller_task(t)
utils.log_verbose(f'Call #{CALL_COUNTER.value} finished') utils.log_verbose(f'Call #{CALL_COUNTER.value} finished')
@ -431,10 +435,13 @@ def run_probe():
if task is not None: if task is not None:
run_caller_task(task) run_caller_task(task)
except:
# Do nothing here, it is normal to get exception
except multiprocessing.Queue.empty:
# Ignore this exception, this is normal
pass pass
except Exception as err:
utils.log_error(message='Error when running t')
# In case of empty task list wait 1 minute before refresh # In case of empty task list wait 1 minute before refresh
# if len(TASK_LIST.tasks) == 0: # if len(TASK_LIST.tasks) == 0:

View File

@ -112,7 +112,7 @@ def start():
global ACCESS_POINT, SERVER_PROCESS global ACCESS_POINT, SERVER_PROCESS
ACCESS_POINT.start() ACCESS_POINT.start()
SERVER_PROCESS = multiprocessing.Process(target=web_process, args=(None,)) SERVER_PROCESS = multiprocessing.Process(target=web_process, args=(None,), name='agent_gsm_web')
SERVER_PROCESS.start() SERVER_PROCESS.start()
def stop(): def stop():

View File

@ -6,36 +6,36 @@ import pathlib
from utils_types import SignalBoundaries from utils_types import SignalBoundaries
from utils_sevana import speech_detector from utils_sevana import speech_detector
from pydub import silence, AudioSegment # from pydub import silence, AudioSegment
SILENCE_DELTA = 16 SILENCE_DELTA = 16
def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path = None, use_end_offset: bool = True) -> SignalBoundaries: # def find_reference_signal(input_file: pathlib.Path, output_file: pathlib.Path = None, use_end_offset: bool = True) -> SignalBoundaries:
myaudio = AudioSegment.from_wav(str(input_file)) # myaudio = AudioSegment.from_wav(str(input_file))
dBFS = myaudio.dBFS # dBFS = myaudio.dBFS
# Find silence intervals # # Find silence intervals
intervals = silence.detect_nonsilent(myaudio, min_silence_len=1000, silence_thresh=dBFS-SILENCE_DELTA, seek_step=50) # intervals = silence.detect_nonsilent(myaudio, min_silence_len=1000, silence_thresh=dBFS-SILENCE_DELTA, seek_step=50)
# Translate to seconds # # Translate to seconds
intervals = [((start/1000),(stop/1000)) for start,stop in intervals] # in sec # intervals = [((start/1000),(stop/1000)) for start,stop in intervals] # in sec
# print(intervals) # # print(intervals)
# Example of intervals: [(5.4, 6.4), (18.7, 37.05)] # # Example of intervals: [(5.4, 6.4), (18.7, 37.05)]
for p in intervals: # for p in intervals:
if p[1] - p[0] > 17: # if p[1] - p[0] > 17:
bounds = SignalBoundaries(offset_start=p[0], offset_finish=p[1]) # bounds = SignalBoundaries(offset_start=p[0], offset_finish=p[1])
if output_file is not None: # if output_file is not None:
signal = myaudio[bounds.offset_start * 1000 : bounds.offset_finish * 1000] # signal = myaudio[bounds.offset_start * 1000 : bounds.offset_finish * 1000]
signal.export(str(output_file), format='wav', parameters=['-ar', '44100', '-sample_fmt', 's16']) # signal.export(str(output_file), format='wav', parameters=['-ar', '44100', '-sample_fmt', 's16'])
if use_end_offset: # if use_end_offset:
bounds.offset_finish = myaudio.duration_seconds - bounds.offset_finish # bounds.offset_finish = myaudio.duration_seconds - bounds.offset_finish
return bounds # return bounds
return SignalBoundaries() # return SignalBoundaries()
def find_reference_signal_via_speechdetector(input_file: pathlib.Path) -> SignalBoundaries: def find_reference_signal_via_speechdetector(input_file: pathlib.Path) -> SignalBoundaries: