3

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 ?

  • 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 -. – cas Apr 4 '16 at 10:15
3

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.

  • 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. – chirlu Apr 4 '16 at 11:37
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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