Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hardware/software used:
- Satellite Pro ET10-G-106
- A4tech TK-5 Mini Numeric Keypad
- Lubuntu 18.04.6 LTS
- GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
- usage, every laptop / 2 in 1 laptop / or just a tablet
- 1. setup Audacious (4.3)
- sudo add-apt-repository ppa:ubuntuhandbook1/apps
- sudo apt update
- sudo apt -y install audacious
- File/Settings/Appearance/Restart in GTK (legacy) mode
- 2. setup xbindkeys
- sudo apt -y install xbindkeys
- 3. setup xev
- sudo apt -y install xautomation
- 4. (optional) check keycodes in terminal via xev (A4Tech TK-5):
- keycode 87 - KP_End ( rewind )
- keycode 88 - KP_Down ( fast forward )
- keycode 89 - KP_Next ( play/pause )
- keycode 104 - KP_Enter ( bookmark audio )
- keycode 83 - KP_Left ( split audio )
- keycode 84 - KP_Begin ( join & play audio )
- 5. setup speech-dispatcher
- sudo apt -y install speech-dispatcher
- 6. setup scripts:
- rewind, terminal:
- leafpad ~/Music/rewind.bash
- paste code:
- #!/bin/bash
- audtool playback-seek-relative -10
- spd-say -t female2 p
- save & close text editor, make it executable:
- chmod +x ~/Music/rewind.bash
- _________________________________
- fast forward, terminal:
- leafpad ~/Music/fforward.bash
- paste code:
- #!/bin/bash
- audtool playback-seek-relative 10
- spd-say -t female2 n
- save & close text editor, make it executable:
- chmod +x ~/Music/fforward.bash
- _________________________________
- play/pause, terminal:
- leafpad ~/Music/play_pause.bash
- paste code:
- #!/bin/bash
- function play_pause() {
- status=$(audtool playback-status)
- if grep 'paused\|stopped' <<< $status ; then
- audtool playback-play
- else
- audtool playback-pause
- fi
- }
- play_pause
- spd-say -t female2 s
- save & close text editor, make it executable:
- chmod +x ~/Music/play_pause.bash
- _________________________________
- bookmark audio, terminal:
- leafpad ~/Music/mark_in_out.bash
- paste code:
- #!/bin/bash
- function mark_audio() {
- out_loc=$(echo ~/Music/marks.txt)
- status=$(audtool playback-status)
- current_song_pos=$(audtool --current-song-output-length-seconds)
- minutes=$((current_song_pos / 60))
- if [[ "$minutes" -lt 10 ]]; then
- minutes=$(printf "%02d" $minutes)
- fi
- seconds=$((current_song_pos % 60))
- if [[ "$seconds" -lt 10 ]]; then
- seconds=$(printf "%02d" $seconds)
- fi
- write_marker=$(echo $minutes":"$seconds)
- if [[ -f "$out_loc" ]]; then
- echo -n " $write_marker" >> $out_loc
- else
- echo -n "$write_marker" >> $out_loc
- fi
- }
- mark_audio
- spd-say -t female2 m
- save & close text editor, make it executable:
- chmod +x ~/Music/mark_in_out.bash
- _________________________________
- 7. make audio clips:
- install dependencies:
- sudo apt -y install ffmpeg
- split audio & backup marks.txt before its deletion, terminal:
- leafpad ~/Music/split_audio.bash
- paste code:
- #!/bin/bash
- function check_out_loc() {
- w_dir="$(pwd)/clips"
- echo $w_dir
- if [ -d "$w_dir" ]; then
- # re-creatates subdir clips in the current folder
- rm -rf $w_dir
- mkdir "$(pwd)/clips"
- echo direcotry re-created
- else
- mkdir "$(pwd)/clips"
- echo direcotry created
- fi
- }
- function cut_audio() {
- readarray -t mp3_files < <(find ./ -maxdepth 1 -type f -regex '.*\.\(mp3\|flac\)$' | sed "s/.*\///")
- if [ ${#mp3_files[@]} -eq 1 ]; then
- j=0
- for i in "$@"; do
- ((j++))
- if [ $((j%2)) -eq 0 ]; then
- end_time=$i
- MPHR=60
- IFS=':' read -ra start_array <<< "$start_time"
- IFS=':' read -ra end_array <<< "$end_time"
- len_start_min=${#start_array[0]}
- len_start_sec=$(( $len_start_min + 1 ))
- len_end_min=${#end_array[0]}
- len_end_sec=$(( $len_end_min + 1 ))
- start_time_sec=$(( ( 10#${start_time:0:$len_start_min} ) * MPHR + 10#${start_time:$len_start_sec} ))
- duration=$(( ( 10#${end_time:0:$len_end_min} - 10#${start_time:0:$len_start_min} ) * MPHR + 10#${end_time:$len_end_sec} - 10#${start_time:$len_start_sec} ))
- file_name=$(basename "${mp3_files[0]}" | cut -d. -f1)
- file_extension=$(basename "${mp3_files[0]}" | cut -d. -f2)
- escape=("[" "]" "~" "!" "{" "}" "(" ")" "$" "@" "<" ">" ":" ";" "," '`' "%" "+" "=" '"' "|" "?" '*' "&" " " "'")
- for e in "${escape[@]}"
- do
- file_name=${file_name//[$e]/\\$e}
- done
- file_name=${file_name//"\\'"/"'\"\'\"'"}
- w_dir="$(pwd)/clips/"
- out_name=$w_dir$(echo $file_name"_"$start_time"-"$end_time"."$file_extension | sed s/:/_/g)
- # removes metadata
- cmd=$(echo ffmpeg -y -ss $start_time_sec -t $duration -i "$file_name"."$file_extension" -map_metadata -1 -c:a copy "$out_name")
- # no metadata removal
- # cmd=$(echo ffmpeg -y -ss $start_time_sec -t $duration -i "$file_name"."$file_extension" -c:a copy "$out_name")
- # echo $cmd
- bash -c "$cmd"
- else
- start_time=$i
- fi
- done
- # backup marks.txt file
- if [ -f "$(pwd)/marks.txt" ]; then
- marks_out_loc=$(echo $(pwd)/marks_$(date +%s).txt)
- cp "$(pwd)/marks.txt" "$marks_out_loc"
- echo -n " $file_name"."$file_extension" >> $marks_out_loc
- echo marks.txt backup done
- rm marks.txt
- fi
- else
- echo "error, only 1 mp3/flac file allowed in the current working directory"
- fi
- }
- check_out_loc
- cut_audio $(cat ~/Music/marks.txt)
- spd-say -t female2 "split audio"
- save & close text editor, make it executable:
- chmod +x ~/Music/split_audio.bash
- _________________________________
- 8. join & listen:
- join clips & play, terminal:
- leafpad ~/Music/join_play.bash
- paste code:
- #!/bin/bash
- function check_out_loc() {
- w_dir="$(pwd)/joins"
- echo $w_dir
- if [ -d "$w_dir" ]; then
- echo direcotry exists
- else
- mkdir "$(pwd)/joins"
- echo direcotry created
- fi
- }
- function join_clips() {
- readarray -t files < <(find ./clips -maxdepth 1 -type f -regex '.*\.\(mp3\|flac\)$' | sed "s/.*\///")
- file_extension=$(basename "${files[0]}" | cut -d. -f2)
- out_loc=$(echo joins/$(date +%s).$file_extension)
- cat ./clips/*.* > ./"$out_loc"
- audacious "$(echo $(pwd)/$out_loc)"
- }
- check_out_loc
- join_clips
- spd-say -t female2 "join & play"
- save & close text editor, make it executable:
- chmod +x ~/Music/join_play.bash
- _________________________________
- 9. setup keyboard keybindings:
- create & edit config file:
- leafpad ~/.xbindkeysrc
- paste code:
- "/home/$(whoami)/Music/rewind.bash"
- c:87
- "/home/$(whoami)/Music/fforward.bash"
- c:88
- "/home/$(whoami)/Music/play_pause.bash"
- c:89
- "/home/$(whoami)/Music/mark_in_out.bash"
- c:104
- "/home/$(whoami)/Music/split_audio.bash"
- c:83
- "/home/$(whoami)/Music/join_play.bash"
- c:84
- save & close text editor, exectue following commands in terminal:
- xbindkeys
- killall xbindkeys && xbindkeys
- _________________________________
- 10. power manager settings:
- xfce power manager, terminal:
- xfce4-power-manager-settings
- Laptop lid - On battery / Plugged in - Switch off display
- _________________________________
- further optimization is up to the user imagination
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement