#!/bin/bash # Auto-route iPhone HFP calls (the nodes exist only during a call): # uplink (what far-end hears) <- micgate.out (GATED mic only -> no self-echo) # far-end voice (bluez_input) -> callmix (recorded digitally, clean) # and remove WirePlumber's default callrec_mix->uplink auto-link (that mix carried # the ungated mic which picks up the far-end acoustically = echo). export XDG_RUNTIME_DIR=/run/user/1000 MAC=B4_96_A5_42_BD_D6 PL(){ pw-link "$@" 2>/dev/null; } while true; do # uplink sink node (has input_FL) present = a call is up UPPORT=$(pw-link -i 2>/dev/null | grep -m1 "bluez_output\.${MAC}.*:input_FL") if [ -n "$UPPORT" ]; then B=${UPPORT%%:*} I=$(pw-link -o 2>/dev/null | grep -m1 "bluez_input\.${MAC}.*:output_FL"); I=${I%%:*} if ! pw-link -l "$B" 2>/dev/null | grep -q micgate.out; then PL -d callrec_mix:capture_FL "$B:input_FL"; PL -d callrec_mix:capture_FR "$B:input_FR" PL micgate.out:output_FL "$B:input_FL"; PL micgate.out:output_FR "$B:input_FR" [ -n "$I" ] && { PL "$I:output_FL" callmix:playback_FL; PL "$I:output_FR" callmix:playback_FR; } logger -t aime-iphone-route "applied iPhone call routing ($B)" fi fi sleep 2 done