zoengjyutgaai / to_wav.sh
laubonghaudoi's picture
Multi-process wav conversion
9e73582
raw
history blame contribute delete
870 Bytes
#!/bin/bash
# Set the number of parallel processes
NUM_PROCESSES=16
# Create the wav directory if it doesn't exist
mkdir -p wav
# Function to convert a single file
convert_file() {
local opus_file="$1"
local wav_file=$(echo "$opus_file" | sed 's|opus/|wav/|; s|\.opus$|\.wav|')
# Create the subdirectory in wav/ if it doesn't exist
mkdir -p "$(dirname "$wav_file")"
# Use the line below to keep the original sample rate 48kHz
# ffmpeg -i "$opus_file" "$wav_file" -loglevel error
# Or change the -ar 16000 to other sample rates
ffmpeg -i "$opus_file" -ar 16000 "$wav_file" -loglevel error
echo "Converted: $opus_file -> $wav_file"
}
export -f convert_file
# Find all .opus files and process them in parallel
find opus/ -name "*.opus" -print0 | xargs -0 -P "$NUM_PROCESSES" -I{} bash -c 'convert_file "$@"' _ {}
echo "Conversion complete."