3
$\begingroup$

I have multiple stereo .wav recordings which I want to convert into mono files for further analysis. Is there a way in RavenPro/R/Audacity to batch convert them to mono sound files (channel 1 or channel 2)?

$\endgroup$
2
  • $\begingroup$ What is special to "further analysis" that inhibits you to read stereo but process selected channel? $\endgroup$
    – WMXZ
    Commented Feb 20 at 7:44
  • $\begingroup$ Hi, I'm a bit confused about reading and processing stereo audio files directly (for example, creating annotations in one channel in a stereo audio file as a training data for a ML model) $\endgroup$ Commented Feb 20 at 10:22

2 Answers 2

4
$\begingroup$

Is there a way to batch convert them in R - almost certainly yes; Audacity - probably; Raven Pro - not that I'm aware of, but possibly.

However, I tend to use the free open-source program SoX (https://sourceforge.net/projects/sox/) for this task with a little bit of shell scripting.

There are entire StackExchange sites dedicated to this sort of shell scripting, and I almost certainly adapted code from one of these. I'll leave searching for that as an exercise for the reader and I won't attempt to duplicate here.

Instead, I will post the recipe and script that I use to do this on the windows command line.

  1. Install SoX
  2. Add SoX installation to windows path
  3. Create a windows batch file (e.g. named splitStereo.bat) with the following content:
for %%n in (*.wav) do (
sox %%n -c 1 %%n_left.wav remix 1
sox %%n -c 2 %%n_right.wav remix 2)
PAUSE
  1. Place stereo wav files to split in a folder with this batch file.
  2. Run the batch file from the file manager.

This script will batch convert all wav files in a folder splitting channel 1 into files with the suffix with _left.wav and channel 2 into files with the suffix '_right.wav'.

$\endgroup$
3
  • $\begingroup$ Scripting is OK, but in my windows11 system the cmd.exe does not work/exist anymore and all is replaced by Powershell and WindowsTerminal (only a sidenote). $\endgroup$
    – WMXZ
    Commented Feb 20 at 11:51
  • $\begingroup$ Thanks for the alternate solution. I think I figured out a way using the tuneR package in R $\endgroup$ Commented Feb 21 at 7:37
  • $\begingroup$ Glad you found a solution indobatrachus. Would be great if you could post as an answer here. @WMXZ: I'm still on Windows 10, and surprised to hear that there's no cmd.exe. According to this link minitool.com/news/open-command-prompt-windows-11.html, it looks like cmd.exe still exists on Windows 11, it's just a little harder to find. $\endgroup$
    – Brian Miller
    Commented Feb 21 at 21:14
3
$\begingroup$

Here's a solution using the tuneR package in R. The function will map across all your stereo recordings and extract audio from the 1st channel in the listed directory

library(tuneR)
library(purrr)

List all stereo .wav files that needs to be converted

file_paths <- list.files("E:/test", pattern = "\\.wav$", full.names = TRUE)

Creating a function to extract left (channel 1) from a stereo audio file and save it in the working directory

extract_channel1 <- function(file_path) {
  audio <- readWave(file_path)
  channel_1 <- channel(audio, "left")
  writeWave(channel_1, paste0("mono_", basename(file_path)))
}

Applying the function to each file path in the list using purrr

map(file_paths, ~ extract_channel1(.))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.