diff --git a/docs/gsm_agent_install.pdf b/docs/gsm_agent_install.pdf new file mode 100644 index 0000000..96b0624 Binary files /dev/null and b/docs/gsm_agent_install.pdf differ diff --git a/src/agent_gsm.py b/src/agent_gsm.py index bacbe6d..0784645 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -87,15 +87,19 @@ def remove_oldest_log_audio(): def detect_degraded_signal(file_test: Path, file_reference: Path) -> SignalBoundaries: - global USE_SILENCE_ERASER, LOG_AUDIO, LOG_AUDIO_DIR + global USE_SILENCE_ERASER, LOG_AUDIO, LOG_AUDIO_DIR, BackendServer + + is_caller : bool = 'caller' in BackendServer.phone.role + is_answerer : bool = 'answer' in BackendServer.phone.role if utils.get_wav_length(file_test) < utils.get_wav_length(file_reference): # Seems some problem with recording, return zero boundaries return SignalBoundaries() r = bt_signal.find_reference_signal(file_test) - if r.offset_finish == 0.0: - r.offset_finish = 20.0 # Remove possible ring tones in the end of call on my test system + + if r.offset_start == 0.0 and is_caller: + r.offset_start = 5.0 # Skip ringing tones return r @@ -120,16 +124,20 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool: # Check how long audio file is audio_length = utils.get_wav_length(file_test) - + + is_caller : bool = 'caller' in BackendServer.phone.role + is_answerer : bool = 'answer' in BackendServer.phone.role + + utils.log(f'Recorded audio call duration: {audio_length}s') # Check if audio length is strange - skip such calls. Usually this is missed call. - if ('caller' in BackendServer.phone.role and audio_length >= utils_mcon.TIME_LIMIT_CALL) or ('answer' in BackendServer.phone.role and audio_length >= utils_mcon.TIME_LIMIT_CALL * 1.2): - utils.log_error(f'Recorded audio call duration: {audio_length}s, skipping analysis') + if (is_caller and audio_length >= utils_mcon.TIME_LIMIT_CALL) or (is_answerer and audio_length >= utils_mcon.TIME_LIMIT_CALL * 1.2): + utils.log_error(f'Recorded call is too big - looks like mobile operator prompt, skipping analysis') return False try: bounds_signal : SignalBoundaries = detect_degraded_signal(Path(file_test), Path(file_reference)) - bounds_signal.offset_start = 0 - bounds_signal.offset_finish = 0 + # bounds_signal.offset_start = 0 + # bounds_signal.offset_finish = 0 print(f'Found signal bounds: {bounds_signal}') # Check if there is a time to remove oldest files @@ -221,13 +229,12 @@ def make_call(target: str): # Add prefix and suffix silence for reference to give a chance to record all the file reference_filename = '/dev/shm/prepared_reference.wav' - utils.prepare_reference_file(fname=REFERENCE_AUDIO, silence_prefix_length=5.0, silence_suffix_length=5.0, output_fname=reference_filename) + utils.prepare_reference_file(fname=REFERENCE_AUDIO, silence_prefix_length=10.0, silence_suffix_length=5.0, output_fname=reference_filename) # Find duration of prepared reference file reference_length = int(utils.get_wav_length(reference_filename)) # Compose a command - # target = '+380995002747' cmd = f'/usr/bin/python3 {DIR_THIS}/bt_call_controller.py --play-file {reference_filename} --record-file {record_file} --timelimit {reference_length} --target {target}' retcode = os.system(cmd) if retcode != 0: @@ -247,8 +254,6 @@ def perform_answerer(): while True: # Remove old recording record_file = f'/dev/shm/bt_record.wav' - # if Path(record_file).exists(): - # os.remove(record_file) cmd = f'/usr/bin/python3 {DIR_THIS}/bt_call_controller.py --play-file {REFERENCE_AUDIO} --record-file {record_file} --timelimit {int(reference_length)}' retcode = os.system(cmd)