user3310334
user3310334

Reputation:

Concatenate wav files ignore if # channels is 2

I need to concatenate all the wav files in a folder.

I tried using the command

sox folder_name/*.wav folder_name.wav

But got the error

sox FAIL sox: Input files must have the same # channels

Turns out only 21 of 2864 wav files in that folder have 2 channels instead of 1.

How can I just ignore the 21 files with 2 channels and concatenate all the 2843 wavs with 1 channel?

Upvotes: 2

Views: 964

Answers (1)

codeforester
codeforester

Reputation: 42999

Use soxi to get all one channel files, put them in an array and then call sox:

for file in folder_name/*.wav; do
  if soxi "$file" | grep -q 'Channel.*1'; then
    files+=("$file")
  fi
done

sox "${files[@]}" folder_name.wav

Upvotes: 1

Related Questions