linuxaudiostreampipesox

pipe sox play command to stdout


So I'm currently trying to stream my microphone input from my raspberry pi (rasbian) to some sort of network stream in order to receive it later on my phone. In order to do this I use arecord -D plughw:1,0 -f dat -r 44100 | top pipe the soundstream from my usb-microphone to stdout which works fine as far as I can see but I needed it to be a bit louder so I can understand people standing far away from it .

So i piped it to the sox play command like this :

arecord -D plughw:1,0 -f dat -r 44100| play -t raw -b 16 -e signed -c 2 -v 7 -r 44100 - test.wav (test.wav is just some random wav file id doesn't work without it and there is a whitespace between the - behind 44100 and test.wav because i think - is a seperate parameter:

SPECIAL FILENAMES (infile, outfile): - Pipe/redirect input/output (stdin/stdout); may need -t -d, --default-device Use the default audio device (where available))

I figured out by using the -v parameter i can increase the volume. This plays the recorded stream to the speakers I connected to the raspberry pi 3 .

Final goal : pipe the volume increased soundstream to the stdout(or some fifopipe file) so i can get it from stdin inside another script to send it to my phone.

However im very confused by the manpage of the play command http://sox.sourceforge.net/sox.html

i need to select the outputdevice to pipe or stout or something
if you know a better way to just increase the voulme of the i think Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereosoundstream let me know


Solution

  • 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 -