2018-04-08 03:47:56 +02:00
|
|
|
#!/data/data/com.termux/files/usr/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
SCRIPTNAME=termux-microphone-record
|
|
|
|
|
|
|
|
show_usage () {
|
2018-04-09 01:07:30 +02:00
|
|
|
echo "Usage: $SCRIPTNAME [args]"
|
|
|
|
echo "Record using microphone on your device"
|
|
|
|
echo
|
|
|
|
echo "-h Shows this help"
|
|
|
|
echo "-d Start recording w/ defaults"
|
|
|
|
echo "-f <file> Start recording to specific file"
|
|
|
|
echo "-l <limit> Start recording w/ specified limit (in seconds)"
|
|
|
|
echo "-i Get info about current recording"
|
|
|
|
echo "-q Quits recording"
|
2018-04-08 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
usage_error () {
|
|
|
|
echo
|
|
|
|
show_usage
|
|
|
|
exit 1
|
2018-04-08 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
sole() {
|
|
|
|
if [ "$1 $2" != "-$option $OPTARG" ] || [ $# -gt 2 ]; then
|
|
|
|
echo "ERROR: No other options should be specified with -$option!"
|
|
|
|
usage_error
|
|
|
|
fi
|
2018-04-08 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
add_params() {
|
|
|
|
for i in "$@"; do
|
|
|
|
params[index++]="$i"
|
|
|
|
done
|
2018-04-08 03:47:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
call_api () {
|
|
|
|
/data/data/com.termux/files/usr/libexec/termux-api MicRecorder "$@"
|
|
|
|
}
|
2018-04-08 03:47:56 +02:00
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
while getopts h,f:,l:,d,i,q option
|
2018-04-08 03:47:56 +02:00
|
|
|
do
|
2018-04-09 01:07:30 +02:00
|
|
|
case "$option" in
|
|
|
|
h) sole "$@"
|
|
|
|
;;
|
|
|
|
f) record=yes
|
|
|
|
dir="$(dirname "$OPTARG")"
|
|
|
|
file="$(basename "$OPTARG")"
|
|
|
|
dir="$(realpath "$dir")"
|
|
|
|
add_params --es file "$dir/$file"
|
|
|
|
;;
|
|
|
|
# API takes limit in milliseconds
|
|
|
|
l) record=yes
|
|
|
|
add_params --ei limit $((OPTARG * 1000))
|
|
|
|
;;
|
|
|
|
d) record=yes
|
|
|
|
;;
|
|
|
|
i) sole "$@"
|
|
|
|
add_params -a info
|
|
|
|
;;
|
|
|
|
q) sole "$@"
|
|
|
|
add_params -a quit
|
|
|
|
;;
|
|
|
|
*) usage_error
|
|
|
|
;;
|
|
|
|
esac
|
2018-04-08 03:47:56 +02:00
|
|
|
done
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
if [ -v record ]; then
|
|
|
|
add_params -a record
|
2018-04-08 03:47:56 +02:00
|
|
|
fi
|
|
|
|
|
2018-04-09 01:07:30 +02:00
|
|
|
if [ -v params ]; then
|
|
|
|
call_api "${params[@]}"
|
|
|
|
else
|
|
|
|
show_usage
|
2018-04-08 03:47:56 +02:00
|
|
|
fi
|