- today's changes
This commit is contained in:
@@ -63,10 +63,11 @@ def set_headset_mic_volume(vol: float):
|
||||
|
||||
|
||||
# Function to get the phone stream index to capture the downlink.
|
||||
def get_headset_spk_idx():
|
||||
def get_headset_spk_idx(timeout: int = 10):
|
||||
utils.log('Waiting for phone stream index (please ensure all PA Bluetooth modules are loaded before)... ')
|
||||
phoneIdx = ''
|
||||
while phoneIdx == '':
|
||||
startTime = time.time()
|
||||
while phoneIdx == '' and (time.time() - startTime < timeout):
|
||||
time.sleep(1)
|
||||
# grep 1-4 digit
|
||||
phoneIdx = os.popen('pacmd list-sink-inputs | grep -B5 alsa_output | grep index | grep -oP "[0-9]{1,4}"').read()
|
||||
@@ -116,6 +117,9 @@ def answer_call(play_file: str):
|
||||
# Record downlink.
|
||||
def capture_phone_alsaoutput(output_path: str):
|
||||
default_output = get_headset_spk_idx().rstrip('\n')
|
||||
if default_output == '':
|
||||
return None
|
||||
|
||||
cmd = f'parec --monitor-stream={default_output} --file-format=wav {output_path}'
|
||||
utils.log(cmd)
|
||||
# Example: parec --monitor-stream=34 --file-format=wav sample1.wav
|
||||
@@ -281,6 +285,11 @@ def run(play_file: str, record_file: str, timelimit_seconds: int, target: str):
|
||||
# Start recording
|
||||
utils.log(f'Start recording with ALSA to {record_file}')
|
||||
process_recording = capture_phone_alsaoutput(record_file)
|
||||
if process_recording is None:
|
||||
utils.log_error(f'Failed to start recording downlink, exiting.')
|
||||
cleanup()
|
||||
return
|
||||
|
||||
utils.log(f'Main loop PID: {os.getpid()}, TID: {threading.get_ident()}')
|
||||
|
||||
# Wait until call is finished
|
||||
|
||||
Reference in New Issue
Block a user