forked from bfields/openwrt-recording
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
It could be interesting - even more for @bfields' original script applications - to have a slimmer/lighter/better-latency version for lower specs devices, so here's a TinyALSA (which don't support probing unfortunately):
#!/bin/sh
#
# tinyALSA-compatible recorder script
# Original: FORART/hALSAmrec, arecord version
# Adapted for tinycap (tinyALSA)
#
# This program is free software: see <https://www.gnu.org/licenses/>.
#
# CONFIGURE THESE FOR YOUR HARDWARE
CHANNELS=2
RATE=48000
FORMAT=S16_LE # One of: S8, S16_LE, S24_LE, S32_LE, etc.
MNT=/tmp/mnt
recorder=""
trap 'true' SIGHUP
sleep infinity &
dummy=$!
trap ' kill $dummy;
[ -n "$recorder" ] && kill $recorder;
umount -l "$MNT";
exit' SIGTERM
first=0
while true; do
if [ $first -eq 0 ]; then first=1; else
if [ -n "$recorder" ]; then waiton=$recorder;
else waiton=$dummy; fi
wait $waiton
fi
# Detect the only exFAT partition available in the system
disk=""
exfat_parts=$(lsblk -o NAME,FSTYPE -nr | awk '$2=="exfat"{print "/dev/"$1}')
count=$(echo "$exfat_parts" | wc -w)
if [ "$count" -eq 1 ]; then
disk="$exfat_parts"
fi
[ -e "$disk" ] && [ -c /dev/snd/pcmC0D0c ] # crude "soundcard present" test
ready=$?
if [ -n "$recorder" ] && [ ! -e /proc/$recorder ]; then
recorder=""
umount -l "$MNT"
fi
if [ $ready -ne 0 ]; then
if [ -n "$recorder" ]; then
umount -l "$MNT"
kill -9 $recorder
recorder=""
fi
continue
fi
if [ -n "$recorder" ]; then continue; fi
mkdir -p "$MNT"
mount $disk "$MNT" || continue
# Check available disk space (after mounting, before recording)
avail_kb=$(df -k "$MNT" | awk 'NR==2 {print $4}')
avail_mb=$((avail_kb / 1024))
if [ "$avail_mb" -le 100 ]; then
if [ -n "$recorder" ]; then
kill -9 $recorder
recorder=""
fi
umount -l "$MNT"
sleep 5
continue
fi
while true; do
name=$(date +%s)
logfile="${MNT}/${name}.log"
if [ ! -e "$logfile" ]; then break; fi
sleep 1
done
# Start recording with tinycap
filename="${name}_${CHANNELS}-${RATE}-${FORMAT}"
tinycap "${MNT}/${filename}.wav" -c $CHANNELS -r $RATE -b 16 &
recorder=$!
done
Metadata
Metadata
Assignees
Labels
No labels