Files
pulse-soundboard/play.sh

30 lines
690 B
Bash
Executable File

#!/usr/bin/env bash
set -e
FILE="$1"
[[ -f "$FILE" ]] || { echo "Usage: $0 <file>"; exit 1; }
STATE="$HOME/.soundboard"
mkdir -p "$STATE"
DEFAULT_SINK=$(pactl get-default-sink)
# Start paplay processes in foreground
# Store PIDs so we can clean up
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 this process in PID file for stop_all.sh
echo $$ >> "$STATE/playing.pids"
# Wait for both streams to finish
wait $PID_MIC $PID_OUT
# Remove from PID file when done
sed -i "\|^$$\$|d" "$STATE/playing.pids"