Re: Sox recording to null of an audio loopback?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



JamesH <hauge.james@xxxxxxxxx> writes:

> ok, I guess I wasn't clear enough so I will go into a bit of more detail on
> what's going on...
>
> I'm using Node-Red with a Raspberry Pi for this project.
>
> I have an online video stream that plays all of the time on this device. 
> It's being used for several different functions all at the same time but
> once it's setup it will just be hooked up to a tv and no user interaction on
> it.
>
> What it does currently is, it plays the online stream without problem(it's a
> low quality stream so there's not a huge amount of bandwidth or cpu power
> needed).  It also checks every few seconds to see if the video is changing. 
> It does this by taking a picture of the screen every few seconds and
> compares it with the last picture taken (file size really, using the du
> command) to see if the video is continuing to play.  It will then send me an
> email and start an alarm if the video stops (I also got it setup to call me
> on the phone using Twilio too!  that was fun).
>
> What i want now is a similar check for audio.  for it to stop recording if
> there's silence (or sound below a certain threshold) for 5 seconds.
>
> Also, from reading the documentation of SoX and rec, it looks like it can
> record into a null file (not from a null file) so as to use the other parts
> of it (the silence detection).  The recording source needs to be the same as
> the system's audio output.
>
> Raspberry pi 3 with the normal Raspian distro of linux, doesn't have any
> built in way to record audio but by searching online I'd found a loopback
> device by running the command "sudo modprobe snd-aloop".
>
> My problem is that when i connect to the pi via ssh and run any kind of rec
> or sox command, I can't figure out how to get it to use the loopback for
> recording, and because I can't seem to be able to record from it, I can't
> even see if it's looping back the system audio...

The snd-aloop creates a virtual playback/capture device pair where
whatever is written to the playback side can be read back on the capture
side.  It is not connected to any other audio devices.

You can still use this to monitor the outgoing audio by using the ALSA
"multi" plugin.  Add something like this to your .asoundrc (or
system-wide asound.conf):

pcm.!default {
        type multi;
        slaves.a.pcm "hw:0,0";
        slaves.b.pcm "hw:CARD=Loopback,DEV=0";
        slaves.a.channels 2;
        slaves.b.channels 2;
        bindings.0.slave a;
        bindings.0.channel 0;
        bindings.1.slave a;
        bindings.1.channel 1;
        bindings.2.slave b;
        bindings.2.channel 0;
        bindings.3.slave b;
        bindings.3.channel 1;
}               

This sets the default output to a virtual device that copies stereo
input to the first physical device (hw:0,0) and the loopback device.
You can then capture the output with sox like this:

$ sox -t alsa hw:CARD=Loopback,DEV=1 <output> <effects...>

Note the different values for DEV used with CARD=Loopback.  Anything
written to DEV=0 is read from DEV=1 and vice versa.

Note also that whichever side is opened first (playback or capture)
dictates the parameters (sample rate and format), so make sure to use
matching settings.

-- 
Måns Rullgård

------------------------------------------------------------------------------
_______________________________________________
Sox-users mailing list
Sox-users@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/sox-users




[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux