Sox recording to null of an audio loopback?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Sox recording to null of an audio loopback?

JamesH
Aloha from Hawaii!

I'm using a Raspberry Pi and am trying to make an alarm kinda thing...

What I need to figure out how to do, and what I'm looking for help with is to figure out how to make sox (using the rec command I believe) record into a null file (meaning it doesn't really record, just goes through the motions) until there's 5 seconds of silence...

Being that the Raspberry Pi doesn't have any kind of audio capture setup, I was able to run a command that brought up a loopback audio device (that command is "sudo modprobe snd-aloop")

Now, how can I give sox a command to record from the loopback until there's 5 seconds of audio, or should I be looking at a different way of checking if the audio output of the raspberry pi has no sound?

Thanks!
--James
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

Eric Wong
JamesH <[hidden email]> wrote:
> Aloha from Hawaii!
>
> I'm using a Raspberry Pi and am trying to make an alarm kinda thing...

Alarms play noises, not record, right?

> What I need to figure out how to do, and what I'm looking for help with is
> to figure out how to make sox (using the rec command I believe) record into
> a null file (meaning it doesn't really record, just goes through the
> motions) until there's 5 seconds of silence...
>
> Being that the Raspberry Pi doesn't have any kind of audio capture setup, I
> was able to run a command that brought up a loopback audio device (that
> command is "sudo modprobe snd-aloop")

I'm not sure I follow.  You want to record 5 seconds of
generated silence into nothing?

> Now, how can I give sox a command to record from the loopback until there's
> 5 seconds of audio, or should I be looking at a different way of checking if
> the audio output of the raspberry pi has no sound?

I'm not familiar with recording with sox and have never
compiled snd-aloop into my kernels, but probably:

        AUDIODEV=... rec -n trim 0 5

You'll need to figure out the value of AUDIODEV for the aloop,
though.   If your kernel has support compiled, looking at the
contents of /proc/asound might help; as would using alsamixer.
(There's more/better supported ways, but I forget them).

Based on what I'm reading, running: sleep 5
would accomplish the same thing, right?

------------------------------------------------------------------------------
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

Måns Rullgård
In reply to this post by JamesH
JamesH <[hidden email]> writes:

> Aloha from Hawaii!
>
> I'm using a Raspberry Pi and am trying to make an alarm kinda thing...
>
> What I need to figure out how to do, and what I'm looking for help with is
> to figure out how to make sox (using the rec command I believe) record into
> a null file (meaning it doesn't really record, just goes through the
> motions) until there's 5 seconds of silence...
>
> Being that the Raspberry Pi doesn't have any kind of audio capture setup, I
> was able to run a command that brought up a loopback audio device (that
> command is "sudo modprobe snd-aloop")
>
> Now, how can I give sox a command to record from the loopback until there's
> 5 seconds of audio, or should I be looking at a different way of checking if
> the audio output of the raspberry pi has no sound?

Could you explain in a bit more detail what it is you are trying to
achieve?

--
Måns Rullgård

------------------------------------------------------------------------------
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

Jeremy Nicoll - ml sox users
In reply to this post by JamesH
On 2016-08-24 08:49, JamesH wrote:

> Aloha from Hawaii!
>
> I'm using a Raspberry Pi and am trying to make an alarm kinda thing...
>
> What I need to figure out how to do, and what I'm looking for help with
> is
> to figure out how to make sox (using the rec command I believe) record
> into
> a null file (meaning it doesn't really record, just goes through the
> motions) until there's 5 seconds of silence...
>
> Being that the Raspberry Pi doesn't have any kind of audio capture
> setup, I
> was able to run a command that brought up a loopback audio device (that
> command is "sudo modprobe snd-aloop")
>
> Now, how can I give sox a command to record from the loopback until
> there's
> 5 seconds of audio, or should I be looking at a different way of
> checking if
> the audio output of the raspberry pi has no sound?

I think you might need to use sox to record to a real (or null) file &
use the stat
or stats effect to get output telling you what the peak sound level was
in that five
second period.  Your alarm process would need to read the output of
stat/stats to
see whether the silence you want to find had occurred.   I'm not sure
how you limit
sox so that it only produces a 5-second recording.

If you needed, say, 1 second granularity you'd need to start five such
processes at
one second intervals so each one would look at a different (overlapping)
5-second
period.  That might also not be possible, for all I know.

If you're unable to overlap 5-second periods you could do one-second
analyses of sound
levels and have a separate process that repeatedly looks at the last
five such levels.


--
Jeremy Nicoll - my opinions are my own

------------------------------------------------------------------------------
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

JamesH
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...

I had thought to use pulseaudio but I couldn't get that to work for me at all because all of the commands will be given from Node-Red in the end...

Thanks for the help guys and girls!
I really am a newbie at linux and raspberry pi's...

--James
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

Måns Rullgård
JamesH <[hidden email]> 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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

JamesH
That looks like it might work for me!  Thank you!

Now, I need to figure out how to do it...  I looked for the two files you listed and couldn't find them at all...   as i'd said, I'm a real newbie at this stuff so am trying to figure it out as I go...

If you've got a few minutes, a bit of extra instructions on how to get this loop-back working would be wonderful...   will keep trying to figure it out on my own too :)

Thanks for all the help now and going forwards!
--James
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

JamesH
ok, I spoke too soon..

I found the file and put in what you said, replacing the part that had the same begining line, and rebooted and it just started giving me errors when I tried to do any kind of sound or mixer command in ssh...

I'm going to keep looking up more info on this!  
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

Fmiser
In reply to this post by JamesH
> JamesH wrote:
>
> Now, I need to figure out how to do it...  I looked for the two
> files you listed and couldn't find them at all...   as i'd said,
> I'm a real newbie at this stuff so am trying to figure it out as
> I go...

Meaning you couldn't find .asoundrc or asound.conf?

.asoundrc typically would be in the users home
directory.  /home/fmiser/.asoundrc and typically will NOT exist.
When alsa starts, it should look for it - again, typically.

The system wide asound.conf I would expect to live in /etc/.
Again, it probably doesn't exist.

Create one file or the other (depending on if you want the
configuration for one user or for all users) and put in it the text
Måns sent.

I suspect you will have to restart alsa with either:
 
 /etc/init.d/alsa-utils restart         #or maybe "reload"

or

invoke-rc.d alsa-utils restart

-- f

------------------------------------------------------------------------------
_______________________________________________
Sox-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/sox-users
Reply | Threaded
Open this post in threaded view
|

Re: Sox recording to null of an audio loopback?

JamesH
no, I had found the .asoundrc file and made the changes but when I rebooted the pi after that, in alsamixer it doesn't show any other device and when I try arecord -l there's no capture devices listed...