sox-users@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* Sox recording to null of an audio loopback?
@ 2016-08-24  7:49 JamesH
  2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: JamesH @ 2016-08-24  7:49 UTC (permalink / raw
  To: sox-users

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




--
View this message in context: http://sox.10957.n7.nabble.com/Sox-recording-to-null-of-an-audio-loopback-tp5749.html
Sent from the SoX mailing list archive at Nabble.com.

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-24  7:49 Sox recording to null of an audio loopback? JamesH
@ 2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
  2016-08-24 18:49   ` JamesH
  2016-08-24 10:09 ` Eric Wong
  2016-08-24 10:22 ` Måns Rullgård
  2 siblings, 1 reply; 10+ messages in thread
From: Jeremy Nicoll - ml sox users @ 2016-08-24  9:51 UTC (permalink / raw
  To: sox-users

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

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-24  7:49 Sox recording to null of an audio loopback? JamesH
  2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
@ 2016-08-24 10:09 ` Eric Wong
  2016-08-24 10:22 ` Måns Rullgård
  2 siblings, 0 replies; 10+ messages in thread
From: Eric Wong @ 2016-08-24 10:09 UTC (permalink / raw
  To: sox-users

JamesH <hauge.james@gmail.com> 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?

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-24  7:49 Sox recording to null of an audio loopback? JamesH
  2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
  2016-08-24 10:09 ` Eric Wong
@ 2016-08-24 10:22 ` Måns Rullgård
  2 siblings, 0 replies; 10+ messages in thread
From: Måns Rullgård @ 2016-08-24 10:22 UTC (permalink / raw
  To: JamesH; +Cc: sox-users

JamesH <hauge.james@gmail.com> 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

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
@ 2016-08-24 18:49   ` JamesH
  2016-08-25  9:06     ` Måns Rullgård
  0 siblings, 1 reply; 10+ messages in thread
From: JamesH @ 2016-08-24 18:49 UTC (permalink / raw
  To: sox-users

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




--
View this message in context: http://sox.10957.n7.nabble.com/Sox-recording-to-null-of-an-audio-loopback-tp5749p5753.html
Sent from the SoX mailing list archive at Nabble.com.

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-24 18:49   ` JamesH
@ 2016-08-25  9:06     ` Måns Rullgård
  2016-08-25 18:18       ` JamesH
  0 siblings, 1 reply; 10+ messages in thread
From: Måns Rullgård @ 2016-08-25  9:06 UTC (permalink / raw
  To: JamesH; +Cc: sox-users

JamesH <hauge.james@gmail.com> 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

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-25  9:06     ` Måns Rullgård
@ 2016-08-25 18:18       ` JamesH
  2016-08-25 18:33         ` JamesH
  2016-08-26  0:13         ` fmiser
  0 siblings, 2 replies; 10+ messages in thread
From: JamesH @ 2016-08-25 18:18 UTC (permalink / raw
  To: sox-users

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




--
View this message in context: http://sox.10957.n7.nabble.com/Sox-recording-to-null-of-an-audio-loopback-tp5749p5755.html
Sent from the SoX mailing list archive at Nabble.com.

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-25 18:18       ` JamesH
@ 2016-08-25 18:33         ` JamesH
  2016-08-26  0:13         ` fmiser
  1 sibling, 0 replies; 10+ messages in thread
From: JamesH @ 2016-08-25 18:33 UTC (permalink / raw
  To: sox-users

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!  



--
View this message in context: http://sox.10957.n7.nabble.com/Sox-recording-to-null-of-an-audio-loopback-tp5749p5756.html
Sent from the SoX mailing list archive at Nabble.com.

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-26  0:13         ` fmiser
@ 2016-08-25 23:07           ` JamesH
  0 siblings, 0 replies; 10+ messages in thread
From: JamesH @ 2016-08-25 23:07 UTC (permalink / raw
  To: sox-users

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





--
View this message in context: http://sox.10957.n7.nabble.com/Sox-recording-to-null-of-an-audio-loopback-tp5749p5758.html
Sent from the SoX mailing list archive at Nabble.com.

------------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Sox recording to null of an audio loopback?
  2016-08-25 18:18       ` JamesH
  2016-08-25 18:33         ` JamesH
@ 2016-08-26  0:13         ` fmiser
  2016-08-25 23:07           ` JamesH
  1 sibling, 1 reply; 10+ messages in thread
From: fmiser @ 2016-08-26  0:13 UTC (permalink / raw
  To: sox-users

> 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
Sox-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-users

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-08-26  0:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-24  7:49 Sox recording to null of an audio loopback? JamesH
2016-08-24  9:51 ` Jeremy Nicoll - ml sox users
2016-08-24 18:49   ` JamesH
2016-08-25  9:06     ` Måns Rullgård
2016-08-25 18:18       ` JamesH
2016-08-25 18:33         ` JamesH
2016-08-26  0:13         ` fmiser
2016-08-25 23:07           ` JamesH
2016-08-24 10:09 ` Eric Wong
2016-08-24 10:22 ` Måns Rullgård

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).