~mil/sxmo-utils

ref: 262418637f878d9325f6fb5a0a2844b3e20c95b2 sxmo-utils/scripts/appscripts/sxmo_record.sh -rwxr-xr-x 2.1 KiB
26241863Stacy Harper Rework of the sxmo_modemtext with benefit 1 year, 4 months ago
                                                                                
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env sh

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"

[ -z "$SXMO_RECDIR" ] && SXMO_RECDIR="$XDG_DATA_HOME"/sxmo/recordings
mkdir -p "$SXMO_RECDIR"

getdur() {
	mediainfo "$1" |
	grep ^Duration |
	head -n1 |
	cut -d: -f2 |
	tr -d " " |
	sed -E 's/[0-9]+ms//'
}

record() {
	PRETTYNAME="$1"
	DEVICE="$2"
	CHANNELS="$3"

	TEMPFILE="$(mktemp --suffix=.wav)"
	NOW="$(date '+%y%m%d_%H%M%S')"
	st -e arecord -D plug:"$DEVICE" -vv -f cd -c "$CHANNELS" "$TEMPFILE"
	FILENAME="${NOW}_${PRETTYNAME}_$(getdur "$TEMPFILE").wav"
	FILE="${SXMO_RECDIR}/${FILENAME}"
	mv "$TEMPFILE" "$FILE"
	echo "$FILE"
}

recordconfirm() {
	FILE="$1"
	FILENAME="$(basename "$FILE")"
	DUR="$(getdur "$FILE")"

	while true; do
		PICK="$(
			printf %b "
				Save: $FILENAME
				Playback: ($DUR)\n
				Delete Recording
			" |
			xargs -0 echo | sed '/^[[:space:]]*$/d' | awk '{$1=$1};1' |
			dmenu -p "$DUR" -c -l 10
		)"
		if echo "$PICK" | grep "Playback"; then
			st -e mpv -ao=alsa -v "$FILE"
		elif echo "$PICK" | grep "Delete Recording"; then
			rm "$FILE"
			echo "File deleted." | dmenu -c -l 10
			return
		else
			return
		fi
	done
}


recordmenu() {
	while true; do
		NRECORDINGS="$(find "$SXMO_RECDIR" -type f | wc -l)"
		OPTIONS="
			Line Jack
			Microphone
			($NRECORDINGS) Recordings
			Close Menu
		"
		OPTION="$(
			printf %b "$OPTIONS" |
			xargs -0 echo |
			sed '/^[[:space:]]*$/d' |
			awk '{$1=$1};1' |
			dmenu -c -p "Record" -l 20
		)"

		if [ "$OPTION" = "Line Jack" ]; then
			OLDAUDIOF="$(mktemp)"
			alsactl --file "$OLDAUDIOF" store
			sxmo_megiaudioroute -l
			FILE="$(record line dsnoop 1)"
			alsactl --file "$OLDAUDIOF" restore
			recordconfirm "$FILE"

		elif [ "$OPTION" = "Microphone" ]; then
			OLDAUDIOF="$(mktemp)"
			alsactl --file "$OLDAUDIOF" store
			sxmo_megiaudioroute -m
			FILE="$(record mic dsnoop 1)"
			alsactl --file "$OLDAUDIOF" restore
			recordconfirm "$FILE"

		elif echo "$OPTION" | grep "Recordings$"; then
			sxmo_files.sh "$SXMO_RECDIR"
		elif [ "$OPTION" = "Close Menu" ]; then
			exit 0
		fi
	done
}

if [ -z "$1" ]; then
	recordmenu
else
	"$@"
fi