#!/usr/bin/python3 # This file runs the call script N times. # The idea is to make long test and collect some statistics about reliability. import os import argparse import typing import time import soundfile # Used audio files to testing PLAY_FILE = 'audio/reference_answerer.wav' DIR_RECORD = '/dev/shm' def run_test(): # Find duration of play audio sf = soundfile.SoundFile(PLAY_FILE) duration = int(sf.frames / sf.samplerate + 0.5) # Remove old recordings os.system(f'rm -f {DIR_RECORD}/bt_record*.wav') # Tests test_idx = 0 while True: try: # Recording file name record_file = f'{DIR_RECORD}/bt_record_{test_idx:05d}.wav' # Answer the call cmd = f'/usr/bin/python3 call_controller.py --play-file {PLAY_FILE} --record-file {record_file} --timelimit {duration}' retcode = os.system(cmd) if retcode == 2: print('Call finished in strange way, probably Ctrl-C. Exiting.') exit(retcode) else: print(f'Call finished with return code {retcode}. Preparing to next one...') test_idx += 1 except Exception as e: print(e) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Test answerer.') args = vars(parser.parse_args()) # Check if input audio file exists if not os.path.exists('audio/example_1.wav'): print(f'Problem: file to play ({args["play_file"]}) doesn\'t exists.') exit(os.EX_DATAERR) run_test()