-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathlinux_parecord.sh
executable file
·50 lines (44 loc) · 1.75 KB
/
linux_parecord.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Credit: This code is based on answers provided by Waschtl and KrisWebDev
# https://askubuntu.com/questions/60837/record-a-programs-output-with-pulseaudio
cleanup(){
if [ -z "$module_id" ]
then
exit 3
fi
# Revert the input sink back to it's original value
pactl move-sink-input $index $curr_sink
# Unload the module I've previously loaded
pactl unload-module $module_id
exit 0
}
# Call cleanup function when user press ctrl+c
trap "cleanup" SIGINT SIGTERM
if ! default_output=$(pacmd list-sinks | grep -A1 "* index" | grep -oP "<\K[^ >]+")
then
echo "Can't seem to find proper output sink, are you using pulseaudio?"
exit 1
fi
pacmd list-sink-inputs|grep -E '(index|application.name)'
while read -p "Choose recording index: " index
do
if [ "$index" = "exit" ]
then
exit 0
fi
curr_sink=$(pacmd list-sink-inputs|grep -EA 8 "index: $index\b"|grep sink|sed -E 's/.*sink:\s*([0-9]+)\s*.*/\1/')
if echo "$curr_sink"|grep -qE '^[0-9]+$'
then
break
fi
echo 'Invalid index, type exit to quit'
echo '-------------------------------'
pacmd list-sink-inputs|grep -E '(index|application.name)'
done
module_id=$(pactl load-module module-combine-sink sink_name=record-n-play slaves=$default_output sink_properties=device.description="Record-and-Play")
pactl move-sink-input $index record-n-play
parec --raw --process-time=10 --latency=10 --rate 16000 --format=s16le --channels 2 -d record-n-play.monitor | ffmpeg -f s16le -ar 16000 -ac 2 -c:a pcm_s16le -i - -f s16le -ar 16000 -c:a pcm_s16le udp://192.168.178.22:2224?pkt_size=120
#nc 192.168.178.22 2224 #192.168.178.22 2222
# export my variables so that cleanup function can access them
export index,curr_sink,module_id
cleanup