From d5ca81b9914a619dd35e5a44b29998233946ff15 Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Tue, 9 Jun 2020 20:19:40 -0500 Subject: [PATCH] Add sxmo_record.sh script and Record entry to scripts menu --- scripts/appscripts/sxmo_record.sh | 69 +++++++++++++++++++++++++++++++ scripts/core/sxmo_appmenu.sh | 1 + 2 files changed, 70 insertions(+) create mode 100755 scripts/appscripts/sxmo_record.sh diff --git a/scripts/appscripts/sxmo_record.sh b/scripts/appscripts/sxmo_record.sh new file mode 100755 index 0000000..a1ce0d7 --- /dev/null +++ b/scripts/appscripts/sxmo_record.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env sh +RECDIR=~/Recordings +OLDAUDIOF="$(mktemp)" +alsactl --file "$OLDAUDIOF" store +mkdir -p "$RECDIR" + +restoreaudio() { + alsactl --file "$OLDAUDIOF" restore +} + +record() { + TEMPFILE="$(mktemp --suffix=.wav)" + NOW="$(date '+%y%m%d_%H%M%S')" + st -e arecord -vv -f cd -c 1 "$TEMPFILE" + DUR="$( + mediainfo "$TEMPFILE" | + grep ^Duration | + head -n1 | + cut -d: -f2 | + tr -d " " + )" + FILENAME="${NOW}_${DUR}.wav" + FILE="${RECDIR}/${FILENAME}" + mv "$TEMPFILE" "$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" -fn Terminus-18 -c -l 10 + )" + if echo "$PICK" | grep "Playback"; then + restoreaudio + st -e mpv -v "$FILE" + elif echo "$PICK" | grep "Delete Recording"; then + rm "$FILE" + echo "File deleted." | dmenu -fn Terminus-18 -c -l 10 + return + else + return + fi + done +} + +while true; do + NRECORDINGS="$(ls -1 "$RECDIR" | 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 + sxmo_megiaudioroute -l + record + elif [ "$OPTION" = "Microphone" ]; then + sxmo_megiaudioroute -m + record + elif echo "$OPTION" | grep "Recordings$"; then + restoreaudio + sxmo_files.sh "$RECDIR" + elif [ "$OPTION" = "Close Menu" ]; then + restoreaudio + exit 0 + fi +done diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 8f4e7ee..8401e1d 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -35,6 +35,7 @@ programchoicesinit() { echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo " Web Search ^ 0 ^ sxmo_websearch.sh Files ^ 0 ^ sxmo_files.sh + Record ^ 0 ^ sxmo_record.sh Timer ^ 0 ^ sxmo_timer.sh Youtube ^ 0 ^ sxmo_youtube.sh video Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio