sox in between two pipes to resample a voice audio

13,754

Solution 1

You need to declare the type of the sox output by adding -t wav before the second -.

When it's a file name, sox peeps at the name and deduces the type from there, but when it's stdout, the type needs to be declared.

You might also want to declare all other settings as well (-b 16 -e signed -c 1) rather than assuming they are transferred from the input; all before the last - that nominates the output.

Solution 2

When you give an explicit file name, such as toto.wav, SoX will deduce from the .wav extension that it is supposed to use WAV format. In case of - being the output “file name”, that deduction can’t be done, so you have to specify the type explicitly with -t wav. The same would apply if you wanted to give the file a different extension (toto.sound) or none at all (toto).

On an unrelated note, WAV files store the length of the contained audio at the beginning of the file. In your case, the final length isn’t known when that part of the file is written to the pipe; therefore, a value indicating “unknown length” will be written instead. This may or may not be an issue depending on what you want to do with the file.

Share:
13,754

Related videos on Youtube

SebMa
Author by

SebMa

Updated on September 18, 2022

Comments

  • SebMa
    SebMa over 1 year

    I'm trying to put the "sox" utility in a two pipes command to resample a mono 44kHz audio file to a 16kHz audio file.

    It works fine with a single pipe :

    $ speexdec toto.oga - | sox -V -t raw -b 16 -e signed -c 1 -r 44.1k - -r 16k toto.wav
    

    But when I add onather pipe, the sox utility complains :

    $ speexdec toto.oga - | sox -V -t raw -b 16 -e signed -c 1 -r 44.1k - -r 16k - | cat - > toto.wav
    sox FAIL formats: can't determine type of `-'
    

    Any idea ?

    • Admin
      Admin about 8 years
      does sox understand that - is supposed to mean stdout? looks like it's being used to mean stdin. try /dev/stdout instead of the final -.
  • chirlu
    chirlu about 8 years
    The input format will by default be propagated to the output file unless changed explicitly (by output options, extension or certain effects), so it shouldn’t normally be necessary. But it doesn’t hurt either, of course.