agent_gsm/src/bt_loop_caller.py

63 lines
1.9 KiB
Python

#!/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
import subprocess
from pathlib import Path
# Used audio files to testing
PLAY_FILE = '../audio/ref_woman_voice_16k.wav'
DIR_RECORD = '/dev/shm'
def run_test(nr_of_tests: int, delay: int, target_number: str):
# Find duration of play audio
sf = soundfile.SoundFile(PLAY_FILE)
# Use the reference audio with increased silence prefix length; as this is place for ringing.
duration = int(sf.frames / sf.samplerate + 0.5)
# Remove old recordings
os.system(f'rm -f {DIR_RECORD}/bt_record*.wav')
for i in range(nr_of_tests):
try:
# Recording file name
record_file = f'{DIR_RECORD}/bt_record_{i:05d}.wav'
cmd = f'/usr/bin/python3 bt_call_controller.py --play-file {PLAY_FILE} --record-file {record_file} --timelimit {duration} --target {target_number}'
os.system(cmd)
print('Call finished.')
print(f'Wait {delay}s for next scheduled call...')
time.sleep(delay)
except Exception as e:
print(e)
if __name__ == '__main__':
DEFAULT_FILE = '../audio/ref_woman_voice_16k.wav'
parser = argparse.ArgumentParser(description='Test caller.')
parser.add_argument('--tests', help='Number of tests', default=100, required=True)
parser.add_argument('--delay', help='Delay between calls', default = 30, required=True)
parser.add_argument('--target', help='Target number to call', required=True)
args = vars(parser.parse_args())
# Check if input audio file exists
if not os.path.exists(PLAY_FILE):
print(f'Problem: file to play ({PLAY_FILE}) doesn\'t exists.')
exit(os.EX_DATAERR)
run_test(int(args['tests']), int(args['delay']), args['target'])