#!/usr/bin/env bash set -e STATE="$HOME/.soundboard" # Check if the soundboard is started if [[ ! -f "$STATE/remap.id" ]]; then echo "Soundboard not started" exit 1 fi FILE="$1" if [[ -z "$FILE" || ! -f "$FILE" ]]; then echo "Usage: $0 " exit 1 fi DEFAULT_SINK=$(pactl get-default-sink) # Start paplay processes in foreground paplay --device=soundboard_sink "$FILE" & PID_MIC=$! paplay --device="$DEFAULT_SINK" "$FILE" & PID_OUT=$! # Trap signals to stop both outputs if script is killed trap "kill $PID_MIC $PID_OUT 2>/dev/null" EXIT INT TERM # Register paplay PIDs for stop_all.sh mkdir -p "$STATE" echo "$PID_MIC" >> "$STATE/playing.pids" echo "$PID_OUT" >> "$STATE/playing.pids" # Wait for both streams to finish wait $PID_MIC $PID_OUT # Remove these PIDs from PID file when done sed -i "\|^$PID_MIC\$|d" "$STATE/playing.pids" sed -i "\|^$PID_OUT\$|d" "$STATE/playing.pids"