├── README.md └── sound-board.bash /README.md: -------------------------------------------------------------------------------- 1 | # Bash Soundboard 2 | 3 | A soundboard written hastily in bash. 4 | It can download sounds from the web. 5 | 6 | See video: [https://youtu.be/8juEYavtAVg](https://youtu.be/8juEYavtAVg) 7 | 8 | ## Usage 9 | 10 | ``` 11 | See this help message 12 | sound-board.bash -h (or --help) 13 | 14 | List sounds 15 | sound-board.bash -l (or --list) 16 | 17 | Play downloaded sound 18 | sound-board.bash soundname 19 | 20 | Download sound 21 | sound-board.bash url start_time end_time soundname 22 | ``` 23 | 24 | ## sxhkdrc snippet example 25 | 26 | ``` 27 | shift + ctrl + {n,e,i,o} 28 | { sound=yeah; text='yeah yeah yeah!'; \ 29 | , sound=diesel; text='VIM diesel'; \ 30 | , sound=supereasy; text='super easy! barely an inconvenience'; \ 31 | , sound=garbage; text='Proprietary garbage!'; \ 32 | } \ 33 | notify-send $text; sb $sound 34 | ``` 35 | -------------------------------------------------------------------------------- /sound-board.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euf -o pipefail 4 | 5 | REQUIREMENTS=('mpv' 'ffmpeg' 'youtube-dl') 6 | 7 | play() { 8 | filepath="$HOME"/sounds/"$1".mp3 9 | 10 | if [[ ! -f $filepath ]]; then 11 | echo \""$1"\" not found 12 | exit 1 13 | fi 14 | 15 | mpv "$filepath" 16 | 17 | exit 18 | } 19 | 20 | list() { 21 | ls "$HOME"/sounds 22 | } 23 | 24 | download() { 25 | filepath="$HOME"/sounds/"$4".mp3 26 | # get the urls needed for ffmpeg 27 | # based on https://unix.stackexchange.com/a/388148 28 | audio_url=$(youtube-dl --youtube-skip-dash-manifest -g "$1" | awk 'NR==2') 29 | 30 | ffmpeg -y -ss "$2" -to "$3" -i "$audio_url" -map 0:a -c:a mp3 "$filepath" 31 | 32 | play "$4" 33 | } 34 | 35 | help() { 36 | cat << EOF 37 | usage: 38 | 39 | See this help message 40 | $0 -h (or --help) 41 | 42 | List sounds 43 | $0 -l (or --list) 44 | 45 | Play downloaded sound 46 | $0 soundname 47 | 48 | Download sound 49 | $0 url start_time end_time soundname 50 | EOF 51 | } 52 | 53 | check_requirements() { 54 | for requirement in "${REQUIREMENTS[@]}"; do 55 | command -v "$requirement" > /dev/null 2>&1 || { 56 | echo "You need to install $requirement" 57 | exit 1 58 | } 59 | done 60 | } 61 | 62 | # no args 63 | [[ $# -eq 0 ]] && help && exit 1 64 | 65 | # help 66 | [[ $# -eq 1 ]] && [[ $1 == -h ]] && help && exit 67 | [[ $# -eq 1 ]] && [[ $1 == --help ]] && help && exit 68 | 69 | # list 70 | [[ $# -eq 1 ]] && [[ $1 == -l ]] && list && exit 71 | [[ $# -eq 1 ]] && [[ $1 == --list ]] && list && exit 72 | 73 | check_requirements 74 | 75 | # play 76 | [[ $# -eq 1 ]] && play "$1" 77 | 78 | # download sound 79 | [[ $# -ne 4 ]] && help && exit 1 80 | download "$@" 81 | --------------------------------------------------------------------------------