23

I am trying to figure out how to combine two commands in SoX. My master file is 44.1 kHz. I first want to resample this file to 22 kHz and then convert it to mp3/opus/ogg. How can I do this with a single command?

BrechtDeMan
  • 6,589
  • 4
  • 24
  • 25
sylowgreen
  • 309
  • 1
  • 3
  • 4

1 Answers1

40

SoX determines the files type by looking at its extension. To adjust the rate of the output file, add the -r option to the output files formatting options. From the manual synopsis:

sox 
  [global-options]
  [format-options] infile1 [[format-options] infile2] ...
  [format-options] outfile
  [effect [effect-options]] ...

Items in brackets are optional, ... means zero or more of the previous item.

Here is an example of how to perform both actions with one command:

sox master.wav -r 22050 out.ogg

Alternatively, you could add the rate manipulation to the effects chain:

sox master.wav out.ogg rate 22050
Thor
  • 45,082
  • 11
  • 119
  • 130
  • Do you need additional libraries for this? I get: `sox FAIL formats: no handler for file extension \`ogg'` – awerchniak Jul 07 '21 at 15:06
  • 1
    @AndyW: you can see what audio formats your version of sox was compiled with by running: `sox -h` – Thor Nov 29 '21 at 08:12