- import changes from master repo
This commit is contained in:
parent
2e53d412a0
commit
3a075e56da
Binary file not shown.
|
|
@ -87,15 +87,19 @@ def remove_oldest_log_audio():
|
||||||
|
|
||||||
|
|
||||||
def detect_degraded_signal(file_test: Path, file_reference: Path) -> SignalBoundaries:
|
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):
|
if utils.get_wav_length(file_test) < utils.get_wav_length(file_reference):
|
||||||
# Seems some problem with recording, return zero boundaries
|
# Seems some problem with recording, return zero boundaries
|
||||||
return SignalBoundaries()
|
return SignalBoundaries()
|
||||||
|
|
||||||
r = bt_signal.find_reference_signal(file_test)
|
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
|
return r
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -121,15 +125,19 @@ def run_analyze(file_test: str, file_reference: str, number: str) -> bool:
|
||||||
# Check how long audio file is
|
# Check how long audio file is
|
||||||
audio_length = utils.get_wav_length(file_test)
|
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.
|
# 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):
|
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 audio call duration: {audio_length}s, skipping analysis')
|
utils.log_error(f'Recorded call is too big - looks like mobile operator prompt, skipping analysis')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bounds_signal : SignalBoundaries = detect_degraded_signal(Path(file_test), Path(file_reference))
|
bounds_signal : SignalBoundaries = detect_degraded_signal(Path(file_test), Path(file_reference))
|
||||||
bounds_signal.offset_start = 0
|
# bounds_signal.offset_start = 0
|
||||||
bounds_signal.offset_finish = 0
|
# bounds_signal.offset_finish = 0
|
||||||
|
|
||||||
print(f'Found signal bounds: {bounds_signal}')
|
print(f'Found signal bounds: {bounds_signal}')
|
||||||
# Check if there is a time to remove oldest files
|
# 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
|
# Add prefix and suffix silence for reference to give a chance to record all the file
|
||||||
reference_filename = '/dev/shm/prepared_reference.wav'
|
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
|
# Find duration of prepared reference file
|
||||||
reference_length = int(utils.get_wav_length(reference_filename))
|
reference_length = int(utils.get_wav_length(reference_filename))
|
||||||
|
|
||||||
# Compose a command
|
# 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}'
|
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)
|
retcode = os.system(cmd)
|
||||||
if retcode != 0:
|
if retcode != 0:
|
||||||
|
|
@ -247,8 +254,6 @@ def perform_answerer():
|
||||||
while True:
|
while True:
|
||||||
# Remove old recording
|
# Remove old recording
|
||||||
record_file = f'/dev/shm/bt_record.wav'
|
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)}'
|
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)
|
retcode = os.system(cmd)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue