5

I am trying to record 2 different microphones through Sox for one of my application. I am currently just testing on Mac terminal for the audio recording. However, I am only able to get audio through one microphone.

The sox command I am using is:

sox -b 32 -e unsigned-integer -r 96k -c 2 -d --clobber --buffer $((96000*2*10)) /tmp/soxrecording.wav trim 0 10

Which give me a good .wav file.

I have two different usb microphones which show up as 2 channel I/p each in Sound/System Preferences. I tried to do -c 4 with the sox command to record from both microphones.

sox -b 32 -e unsigned-integer -r 96k -c 4 -d --clobber --buffer $((96000*2*10)) /tmp/soxrecording.wav trim 0 10

However, I get a warning saying; sox WARN formats: can't set 4 channels; using 2

And I can just get audio in from only one usb microphone. I have been trying to fiddle and understand what’s wrong but any hints would be really helpful.

Cipher
  • 5,894
  • 22
  • 76
  • 112
  • I think just because you have two devices doesn't mean you have double the channels. You need to specify the two input files using the `hw:1,0,0` format. So basically you have two input files. See this thread for more details http://sox.10957.n7.nabble.com/Multiple-inputs-with-SOX-td5061.html. AUDIODEV is the environment variable to control the device. But I am not sure if you can have two device specified in that. But specifying them as multiple files in input should work. The format of the command is `sox file file outputfile` – Tarun Lalwani Jan 23 '18 at 18:40
  • @TarunLalwani I am not sure what this means. I don't have input files. I have input devices. So running `AUDIODEV=hw:1,0,0 sox -b 32 -e unsigned-integer -r 44100 -c 2 ~/Desktop/tempRecord1.wav ~/Desktop/tempRecording2.wav` gives me `sox FAIL formats: can't open input file `/Users/blah/Desktop/tempRecord1.wav': No such file or directory` – Cipher Jan 24 '18 at 22:28
  • @TarunLalwani Also, not sure how to get those `hw` device numbers on Mac. I can't run `aplay -l` or `aplay -L` – Cipher Jan 24 '18 at 22:32
  • @TarunLalwani : Also, just using `sox -r 44100 hw:1,0 -t .ogg ch1_.ogg silence 1 0.1 5% 1 1.0 5% : newfile : restart` for one default microphone on Mac gives me `sox FAIL formats: can't open input file `hw:1,0': No such file or directory` – Cipher Jan 24 '18 at 22:39

1 Answers1

0

You need to specify that you are using ALSA, then run two different SOX command and have to specify the hardware you use for each one.

Please refer to soc, play, rec man page, basically you may use the -d, --default-device parameter when starting your command to specify which device you want to use.

Something like (simplified):

sox -r 44100 -c 2 -e s -t alsa hw:4,0 -d 
sox -r 44100 -c 2 -e s -t alsa hw:3,0 -d 

This page and this page may also help you.

A. STEFANI
  • 6,707
  • 1
  • 23
  • 48
  • 1
    I am on Mac OS and running your commands gives me `sox FAIL formats: no handler for given file type `alsa` – Cipher Jan 24 '18 at 22:19