88# Copyright (C) 2025 Arda Kilicdagi
99# Licensed under MIT License
1010
11+ # Define the sox command - can be overridden via environment variable
12+ : " ${SOX_COMMAND:= sox} "
13+
1114# Function to display usage
1215show_usage () {
1316 echo " Usage: $0 <source_directory> [options]"
@@ -53,8 +56,8 @@ while [[ $# -gt 0 ]]; do
5356done
5457
5558# Check if sox is installed
56- if ! command -v sox & > /dev/null; then
57- echo " Error: sox is not installed. Please install sox to continue."
59+ if ! command -v ${SOX_COMMAND %% * } & > /dev/null; then
60+ echo " Error: sox (or Docker) is not installed. Please ensure it is installed to continue."
5861 exit 1
5962fi
6063
@@ -70,7 +73,7 @@ mkdir -p "$TRANSCODED_DIR"
7073# Function to get audio file info using sox
7174get_audio_info () {
7275 local file=" $1 "
73- local info=$( sox --i " $file " )
76+ local info=$( $SOX_COMMAND --i " $file " )
7477 local bits=$( echo " $info " | grep " Sample Encoding" | grep -o " [0-9]\+" )
7578 local rate=$( echo " $info " | grep " Sample Rate" | grep -o " [0-9]\+" )
7679 echo " $bits $rate "
@@ -127,9 +130,9 @@ find "$SOURCE_DIR" \( -name "*.flac" -o -name "*.mp3" \) | while read -r file; d
127130 if [ " $needs_conversion " = true ]; then
128131 echo " Converting FLAC: $file "
129132 # Debugging
130- # echo "sox --multi-threaded -G '$file' $bitrate_args '$target_file' $sample_rate_args dither"
133+ # echo "$SOX_COMMAND --multi-threaded -G '$file' $bitrate_args '$target_file' $sample_rate_args dither"
131134 # shellcheck disable=SC2086
132- sox --multi-threaded -G " $file " $bitrate_args " $target_file " $sample_rate_args dither
135+ $SOX_COMMAND --multi-threaded -G " $file " $bitrate_args " $target_file " $sample_rate_args dither
133136 else
134137 echo " Copying FLAC: $file "
135138 cp " $file " " $target_file "
0 commit comments