0

Want to record a radio broadcast into separated files.

receiver | sox -traw -r8k -es -b16 -c1 - -b16 -es -c1 -r48000 -t wav ~/myfolder/$(date +%H_%M_%S).wav silence 1 0.10 0.1% 1 1 0.1% : newfile : restart

What i want at output:

  • 15_02_47.wav
  • 15_11_23.wav

What i have:

  • 15_02_47001.wav
  • 15_02_47002.wav

pls help

1
  • date +"%T" or date +"%R:%S" is what you want.
    – JayCravens
    Commented May 11 at 4:52

1 Answer 1

0

From man 1 sox [emphasis mine]:

SoX […] has limited ability to split the input into multiple output files.

[…]

SoX's default behaviour is to take one or more input files and write them to a single output file.

This behaviour can be changed by specifying the pseudo-effect newfile within the effects list. SoX will then enter multiple output mode.

In multiple output mode, a new file is created when the effects prior to the newfile indicate they are done. The effects chain listed after newfile is then started up and its output is saved to the new file.

In multiple output mode, a unique number will automatically be appended to the end of all filenames. If the filename has an extension then the number is inserted before the extension. This behaviour can be customized by placing a %n anywhere in the filename where the number should be substituted. An optional number can be placed after the % to indicate a minimum fixed width for the number.

It seems the only way to turn this feature off is not to use newfile.

In your command $(date +%H_%M_%S) (and the tilde) is expanded by the shell before sox is started. The tool gets one static pathname without any wildcards it could dynamically interpret (unless ~/ gets expanded to something that includes %n or so, but apparently this does not happen in your case; if it happened, it would be worse). If you want a single sox process to output to multiple files then the process has to create different names on its own; I don't think there is a way to make sox (re-)evaluate date.

I can think of two methods to do what you want:

  1. Run multiple sox processes one after another, while splitting the input stream in the right places. (An example of using split for something similar: here; but it splits by counting bytes, not by detecting silence.) If you manage to do this, then it will be possible to evaluate date separately for each sox just before it starts.

  2. Create a bunch of files like you did and rename each afterwards according to its creation time (birth time, btime). Note there are filesystems without support for btime.

2
  • You can create chunk files. sox audio_file.wav chunks/%05d.wav trim 0 30 : new : channels 2 will create 30 second segments. I used it once to output RMS to file.
    – JayCravens
    Commented May 11 at 5:19
  • thanks for the answer, but it looks like there is no beautiful solution and I will have to use "inotifywait". Also 0 signal =! SILENCE for SoX and it trims audio to separated files very bad.
    – Oleg M
    Commented May 14 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .