From 937bafb4932af06fe33f8675a966870d8e4c1013 Mon Sep 17 00:00:00 2001 From: Dmytro Bogovych Date: Tue, 22 Aug 2023 08:50:48 +0300 Subject: [PATCH] - support offline mode --- src/agent_gsm.py | 20 ++++++++++++++------ src/utils_cache.py | 2 +- src/utils_mcon.py | 2 +- src/utils_qualtest.py | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/agent_gsm.py b/src/agent_gsm.py index bfa0c48..ea00c44 100644 --- a/src/agent_gsm.py +++ b/src/agent_gsm.py @@ -29,9 +29,9 @@ RECORD_FILE = "/dev/shm/qualtest_recorded.wav" BackendServer : utils_qualtest.QualtestBackend = None # Reference audio to play -REFERENCE_AUDIO = "/dev/shm/reference.wav" +REFERENCE_AUDIO = "/dev/shm/reference_original.wav" -# Loaded refernce audio (from backend) +# Loaded reference audio (from backend) LOADED_AUDIO = Path("/dev/shm/loaded_audio.wav") # Script to exec after mobile call answering @@ -105,6 +105,7 @@ def detect_reference_signal(file_reference: Path) -> SignalBoundaries: def upload_results(): + utils.log(f'Uploading remaining results...') probe_list = CACHE.get_probe_list() for t in probe_list: # Path to .json report @@ -113,8 +114,12 @@ def upload_results(): # Path to audio path_audio = t[1] - with open(path_report, 'rt') as f: - report = json.loads(f.read()) + try: + with open(path_report, 'rt') as f: + report = json.loads(f.read()) + except: + utils.log_error(f'Error when processing {path_report.name}') + continue upload_id, success = BackendServer.upload_report(report, cache=None) if success: @@ -136,6 +141,7 @@ def upload_results(): else: break else: + utils.log(f'Failed to upload report {path_report.name}') break def run_analyze(file_test: str, file_reference: str, number: str) -> bool: @@ -249,8 +255,10 @@ def make_call(target: str): # os.remove(record_file) # 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=10.0, silence_suffix_length=5.0, output_fname=reference_filename) + reference_filename = Path('/dev/shm/reference_built.wav') + if reference_filename.exists(): + os.remove(reference_filename) + utils.prepare_reference_file(fname=str(REFERENCE_AUDIO), silence_prefix_length=10.0, silence_suffix_length=5.0, output_fname=str(reference_filename)) # Find duration of prepared reference file reference_length = int(utils.get_wav_length(reference_filename)) diff --git a/src/utils_cache.py b/src/utils_cache.py index d878fb2..223f1af 100644 --- a/src/utils_cache.py +++ b/src/utils_cache.py @@ -84,7 +84,7 @@ class InfoCache: # Probe found p_audio = p.with_suffix('.wav') if p_audio.exists(): - r.append(p, p.with_suffix('.wav')) + r.append((p, p.with_suffix('.wav'))) return r diff --git a/src/utils_mcon.py b/src/utils_mcon.py index 90343f6..d6587e5 100644 --- a/src/utils_mcon.py +++ b/src/utils_mcon.py @@ -233,7 +233,7 @@ class CallState(enum.Enum): # Monitor logcat output and tell about events # on_start is lambda with 3 parameters (file_test, file_reference, phone_number) # on_finish is lambda with 3 parameters (file_test, file_reference, phone_number) -PREPARED_REFERENCE_AUDIO = '/dev/shm/reference_prepared.wav' +PREPARED_REFERENCE_AUDIO = '/dev/shm/built_reference.wav' def gsm_monitor(file_to_play: str, file_to_record: str, on_start, on_finish, on_error): global PREPARED_REFERENCE_AUDIO, STOP_FLAG, USE_ALSA_AUDIO, AUDIO_DEV_RECORD, AUDIO_DEV_PLAY diff --git a/src/utils_qualtest.py b/src/utils_qualtest.py index 33549f9..49067b1 100644 --- a/src/utils_qualtest.py +++ b/src/utils_qualtest.py @@ -66,12 +66,12 @@ class QualtestBackend: self.__phone = self.load_phone(cache) - def upload_report(self, report, cache: InfoCache) -> (str, bool): + def upload_report(self, report: dict, cache: InfoCache) -> (str, bool): # UUID string as result result = (None, False) # Log about upload attempt - utils.log_verbose(f"Uploading to {self.address} report: {json.dumps(report, indent=4)}") + utils.log_verbose(f'Uploading to {self.address} report with audio duration: {report["duration"]}s, AQuA MOS: {round(report["mos_aqua"], 3)}') url = utils.join_host_and_path(self.address, "/probes/") try: @@ -82,7 +82,7 @@ class QualtestBackend: result = (r.content.decode().strip(), True) except Exception as e: - utils.log_error(f"Upload report to {self.address} finished with error.", err=e) + utils.log_error(f'Upload report to {self.address} finished with error: {str(e)}') # Backup probe result if cache is not None: probe_id = cache.add_report(report)