Cleanup record script; respect $SXMO_RECDIR; cut ms in file; allow ext calling

master
Miles Alan 5 years ago
parent c7eb70dde8
commit c86761334c
  1. 104
      scripts/appscripts/sxmo_record.sh

@ -1,29 +1,34 @@
#!/usr/bin/env sh #!/usr/bin/env sh
RECDIR=~/Recordings [ -z "$SXMO_RECDIR" ] && SXMO_RECDIR=~/Recordings
OLDAUDIOF="$(mktemp)" mkdir -p "$SXMO_RECDIR"
alsactl --file "$OLDAUDIOF" store
mkdir -p "$RECDIR"
restoreaudio() { getdur() {
alsactl --file "$OLDAUDIOF" restore mediainfo "$1" |
grep ^Duration |
head -n1 |
cut -d: -f2 |
tr -d " " |
sed -E 's/[0-9]+ms//'
} }
record() { record() {
PRETTYNAME="$1"
DEVICE="$2"
CHANNELS="$3"
TEMPFILE="$(mktemp --suffix=.wav)" TEMPFILE="$(mktemp --suffix=.wav)"
NOW="$(date '+%y%m%d_%H%M%S')" NOW="$(date '+%y%m%d_%H%M%S')"
sxmo_megiaudioroute "$1" st -e arecord -D plug:"$DEVICE" -vv -f cd -c "$CHANNELS" "$TEMPFILE"
st -e arecord -vv -f cd -c 1 "$TEMPFILE" FILENAME="${NOW}_${PRETTYNAME}_$(getdur).wav"
restoreaudio FILE="${SXMO_RECDIR}/${FILENAME}"
DUR="$(
mediainfo "$TEMPFILE" |
grep ^Duration |
head -n1 |
cut -d: -f2 |
tr -d " "
)"
FILENAME="${NOW}_${DUR}.wav"
FILE="${RECDIR}/${FILENAME}"
mv "$TEMPFILE" "$FILE" mv "$TEMPFILE" "$FILE"
echo "$FILE"
}
recordconfirm() {
FILE="$1"
FILENAME="$(basename "$FILE")"
DUR="$(getdur "$FILE")"
while true; do while true; do
PICK="$( PICK="$(
@ -47,20 +52,51 @@ record() {
done done
} }
while true; do
NRECORDINGS="$(find "$RECDIR" -type f | wc -l)"
OPTION="$(
printf %b "Line Jack\nMicrophone\n($NRECORDINGS) Recordings\nClose Menu" |
dmenu -fn Terminus-30 -c -p "Record" -l 20
)"
if [ "$OPTION" = "Line Jack" ]; then recordmenu() {
record -l while true; do
elif [ "$OPTION" = "Microphone" ]; then NRECORDINGS="$(find "$SXMO_RECDIR" -type f | wc -l)"
record -m OPTIONS="
elif echo "$OPTION" | grep "Recordings$"; then Line Jack
sxmo_files.sh "$RECDIR" Microphone
elif [ "$OPTION" = "Close Menu" ]; then System Audio
exit 0 ($NRECORDINGS) Recordings
fi Close Menu
done "
OPTION="$(
printf %b "$OPTIONS" |
xargs -0 echo |
sed '/^[[:space:]]*$/d' |
awk '{$1=$1};1' |
dmenu -fn Terminus-30 -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
"$1" "$2" "$3"
fi

Loading…
Cancel
Save