diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-10-22 22:50:02 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-10-22 22:50:02 +0200 |
| commit | a4f18086ba7ce108ebb041b9b0c52bf522413000 (patch) | |
| tree | 8d63a98b329f4af486f38db47d0b6049c6e441d8 /.scripts/spec | |
| parent | bf45ef759815ad7ac3f6423114a96f4d56d1a2a2 (diff) | |
| parent | 68a2612c8b737f6770a4d23848fe6409ddce7888 (diff) | |
| download | dotfiles-a4f18086ba7ce108ebb041b9b0c52bf522413000.tar.gz dotfiles-a4f18086ba7ce108ebb041b9b0c52bf522413000.zip | |
Add '.scripts/' from commit 'a4ba0376ba73b1bb295d8bb459a4bf2b063ddca9'
git-subtree-dir: .scripts
git-subtree-mainline: 03c0cf66468d5e04c0e3559f9f89b5eec28feb9e
git-subtree-split: a4ba0376ba73b1bb295d8bb459a4bf2b063ddca9
Diffstat (limited to '.scripts/spec')
| -rwxr-xr-x | .scripts/spec | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/.scripts/spec b/.scripts/spec new file mode 100755 index 0000000..19810fc --- /dev/null +++ b/.scripts/spec @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Created By: srdusr +# Created On: Wed 18 Oct 2023 20:19:03 CAT +# Project: Create Spectrograms of audio files + +# Dependencies: sox + +# Define the timestamp function +timestamp() { + date +%Y%m%d%H%M%S +} + +spec() { + + if [[ $# -eq 0 ]]; then + echo "No audio files provided." + return + fi + + local outdir + + if [[ -d "$HOME/pictures" ]]; then + outdir="$HOME/pictures/spectrograms" + elif [[ -d "$HOME/Pictures" ]]; then + outdir="$HOME/Pictures/Spectrograms" + elif [[ -d "$HOME/Images" ]]; then + outdir="$HOME/Images/Spectrograms" + else + outdir="./spectrograms" # Save to the current directory if none of the expected directories exist + fi + + for file in "$@"; do + if [[ -f "$file" ]]; then + local filename + filename=$(basename "$file") + local filename_no_extension="${filename%.*}" + local target_dir="$outdir" + local outname="$target_dir/sox-spec-$(timestamp)-${filename_no_extension}.png" + + if [[ ! -d "$target_dir" ]]; then + mkdir -p "$target_dir" # Create the directory if it doesn't exist + fi + + sox "$file" -S -n spectrogram -o "$outname" + + # Add the generated spectrogram file name to the array + spectrogram_files+=("$outname") + else + echo "File not found: $file" + fi + done + + if [[ ${#} -gt 0 ]]; then + read -p "Do you want to open the spectrogram(s)? (y/n): " open_choice + case "$open_choice" in + [Yy]) + for file in "${spectrogram_files[@]}"; do + xdg-open "$file" # Open the spectrogram images generated from the provided audio files + done + ;; + [Nn]) + echo "Not opening the spectrogram(s)." + ;; + *) + echo "Invalid choice. Not opening the spectrogram(s)." + ;; + esac + fi +} + +# Call the spec function with provided arguments +spec "$@" |
