Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #set some defaults
- BUFLEN=80
- DOSUDO=0
- FFMPEG=0
- VOLUME=100
- MPLAYER=0
- showhelp()
- {
- echo 'Supported flags:'
- echo '-b, --buffer-time : Specify duration of buffer. Default: '"$BUFLEN"'.'
- echo '-f, --use-ffmpeg : Use ffmpeg instead of an arecord -> aplay pipe.'
- echo '-c, --cap-device : Use specified device for capturing'
- echo '-m, --use-mplayer : Use ffmpeg to capture and pipe to mplayer.'
- echo '-r, --root, --nice : Run as root so process can be given higher priority.'
- echo '-v, --volume : Set volume percentage (implies -f).'
- echo '-h, --help : Show this help message.'
- }
- while [ "$#" -gt 0 ]; do
- case "$1" in
- '-b' | '--buffer-time' | '--buffer')
- # shift required whenever an arg-value pair needs passed
- shift 1
- if [ "$#" -gt 0 ]; then
- BUFLEN="$1"
- else
- 1>&2 echo 'Error: need a value for buffer duration if -b is passed.'
- exit 1
- fi
- ;;
- '-f' | '--use-ffmpeg')
- FFMPEG=1
- ;;
- '-m' | '--use-mplayer')
- FFMPEG=1
- MPLAYER=1
- ;;
- '-r' | '--root' | '--nice')
- DOSUDO=1
- ;;
- '-v' | '--volume')
- if [ "$#" -gt 1 ]; then
- FFMPEG=1 # -v implies ffmpeg
- VOLUME="$2"
- VOLUME="$(echo '10 k '"$VOLUME"' 100 /p' | dc)"
- shift # param needs a shift-out
- else
- echo 'Error: No volume level to set was given but -v was passed.'
- exit 1
- fi
- ;;
- '-c' | '--cap-device')
- if [ "$#" -gt 1 ]; then
- CAPTURE_DEV="$2"
- shift # param needs a shift-out
- else
- echo 'Error: No volume level to set was given but -v was passed.'
- exit 1
- fi
- ;;
- '-h' | '--help')
- showhelp
- exit 0
- ;;
- *)
- 1>&2 echo 'Error: unknown parameters passed to program.'
- 1>&2 showhelp
- ;;
- esac
- shift 1
- if [ "$1" = '-b' ]; then
- if [ -z "$2" ]; then
- BUFLEN="$2"
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment