Pipe Sox Play Command to Stdout

pipe sox play command to stdout

As far as I'm aware you can't pipe the output from play, you'll have to use the regular sox command for that.
For example:

# example sound file
sox -n -r 48k -b 16 test16.wav synth 2 sine 200 gain -9 fade t 0 0 0.1

# redundant piping
sox test16.wav -t wav - | sox -t wav - gain 8 -t wav - | play -

In the case of the command in your question it should be sufficient to change play to sox and add -t wav to let sox know in what format you want to pipe the sound.

arecord -D plughw:1,0 -f dat -r 44100 | \
sox -t raw -b 16 -e signed -c 2 -v 7 -r 44100 - -t wav -

sox - pipe input broken?

After some more experiments, I finally found out that it is only related to the sox spectrogram effect, because it cannot deduct the duration from the input but it needs that for calculating the layout.

Apparently, that requirement is not documented.

However, to specify a duration precisely, we have to provide it with the number of samples of the input.

I am using ffprobe and jq for that:

ffprobe -v error -print_format json -select_streams a:0 -show_entries frame=nb_samples input_orig.aac \
| jq --stream 'select(.[0][2] == "nb_samples")[1]' \
| jq --slurp 'add'

(yes, there are simpler ways, but they don't scale)

...which gives me 4797440 samples for my input files.

Now it actually works with adding -d 4797440s to the spectrogram effect:

sox -S -m \
-v 1 -t s24 -r 48k -c 2 -L "|ffmpeg -v error -i input_orig.aac -vn -f s24le -" \
-v -1 -t s24 -r 48k -c 2 -L "|ffmpeg -v error -i input_faac.aac -vn -f s24le -" \
-n \
spectrogram -d 4797440s -x 1600 -y 480 -o diff.faac.png

New result:

Sample Image

Sox - Piping output in windows

I was using SoX 14.0.x, and downgrading to 13.0 mended my problem immediately.
Seems like output piping is broken in 14.0.x

Thanks.

Text Based User Interface to stdout

Try the following (it would appear that sox outputs on STDERR):

play File.wav >> output.txt 2>&1

Whether it's going to be easy to parse is a different story ... :)

Namely the

[00:01:30.31] Out:532k [ -===|===- ] Clip:0

bit gets broken up over individual lines with your redirect.

How to concatenate SoX commands?

You can combine them via a pipe, like this:

rec -p trim 0 50 | sox -p out.wav trim 0 10 : newfile : restart

The -p option is shorthand for -t sox -, i.e. write to stdout/read from stdin using SoX’s internal format.

In this particular case, you could also unroll the restart loop and do it in one invocation, like this:

rec out.wav trim 0 10 : newfile : trim 0 10 : newfile : trim 0 10 : newfile : trim 0 10 : newfile : trim 0 10

That’s not always possible, of course.

Capture console text of piped app to another app

When bash start executing sox -d -t wav - | lame - test.mp3, because of the pipe character bash will fork two processes to execute each command, and then connects stdout from the first process with stdin to the second one. Bash will not do anything specific with stderr of either process, so the screen output you see from sox (Input File ...) is not part of the pipe operation.

From what I can understand from your question, you have one java program that starts those two sox and lame processes. More details about how you are doing this would be good. But in any case to get the screen output you showed example of you have to read stderr from the sox process.



Related Topics



Leave a reply



Submit