LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-16-2014, 04:01 PM   #1
TheGlenn88
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Rep: Reputation: Disabled
sox audio recording on a VOX like basis


Hi,

I'm not new to using Linux, my experience is using the command line for setting up headless servers i.e LAMP, NAS and Media Servers just for personal use. I have little experience with writing scripts but do have an understanding of them.

I have found a very good solution to record audio based on audio level input so it records when sound is inputted and doesn't record silence. The command is:
Code:
rec recording.wav silence 1 5 8% 1 0:00:01 8%
This detects the audio when there is more than 8% sound and records until it hears 1 second of silence.

I need it to record into date and time file formats which i have accomplished in this script. Although it's very very far from ideal and awfully dirty, it works but it's no good for a long term 24/7 solution.

Code:
#!/bin/bash
NAME=`date +%m-%d-%Y_%H-%M-%S`
rec $NAME.wav silence 1 5 8% 1 0:00:02 8%
~/voxrecord.sh
because rec exits when it has finished recording i need a solution to restart it and wait again for more audio, preferebly as a service?

The goal is to have all the recordings in a web interface to be played back as needed.

Can anyone help me get this system to wait-record-save-repeat?

Thanks
 
Old 02-16-2014, 04:59 PM   #2
TheGlenn88
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
Actually, thinking about the timestamp filename method like in that basic script. it will only take the date and time from when the script was executed. So if it was executed at 10AM and it didn't record anything till 10:45 it will still have a 10AM timestamp so this would not be the way to do it.

Perhaps

Code:
#!/bin/bash

rec temp.wav silence 1 5 8% 1 0:00:02 8%
NAME=`date +%m-%d-%Y_%H-%M-%S`
mv temp.wav $NAME.wav
~/voxrecord.sh
This seems to work more accurately for timestamping
 
Old 02-17-2014, 06:45 PM   #3
TheGlenn88
LQ Newbie
 
Registered: Feb 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
I have actually progressed further with the script and i think the only thing i need to do is daemonise it and test. the rec command creates the temp.mp3 file even if no sound is recorded, i imagine it's to check that it is able to write before waiting to find out it can't as the recording starts. So the temp file it creates is usually 384 bytes or 768 bytes, perhaps writing headers? i don't know so i've set the script to remove the temp.mp3 file anyway at the start as a failsafe, then wait for audio via rec command. Once it records it saves the file, if it's above 800 bytes it will move to a date-stamped file and add the info to the database, then remove temp file and restart the script. If the script is aborted before anything is recorded it will simply remove temp and exit.

All of the code is borrowed from various sources like stack exchange and modified to work together, no credit goes to me, really.

If anyone can have a professional input and a solution to daemonise that would be greatly appreciated.

Regards
Mike

Code:
#!/bin/bash

rm -rf temp.mp3
rec temp.mp3 silence 1 5 4% 1 0:00:01 4%


for i in temp.mp3 ; do
   b=`stat -c %s "$i"`
if [ $b -ge 800 ] ; then

NAME=`date +%Y-%m-%d_%H-%M-%S`
TIME=`date +%H:%M:%S`
FILENAME=/var/www/Recordings/$NAME.mp3
FILEWWW=Recordings/$NAME.mp3
mv temp.mp3 $FILENAME
rm -rf temp.mp3

mysql --host=localhost --user=root --password=password database << EOF
insert into recordings (id,time,filename,active,status) values('NULL','$TIME','$FILEWWW','1','1');
EOF

~/vox



else
rm -rf temp.mp3
echo 'no sound'
fi
done

Last edited by TheGlenn88; 02-18-2014 at 06:12 PM.
 
Old 07-19-2014, 08:39 PM   #4
Freddythunder
LQ Newbie
 
Registered: Apr 2012
Posts: 11

Rep: Reputation: Disabled
I stumbled upon this post while looking for a solution to something I'm working on.. Don't know if it could help you now, but it looks like sox has a built in function that will split up a file by silences and put them into separate files. Here's a site I found that mentions it... I have not tried it
http://digitalcardboard.com/blog/200...ox-of-silence/

Maybe you can suggest something for me? I'd like to have my computer listen to a webstream and save segments of audio between silences. I was planning on trying to feed sox a URL for the input but I'm pretty sure that won't work. Thansk
 
Old 06-03-2015, 02:48 AM   #5
LADave
LQ Newbie
 
Registered: Jun 2015
Posts: 5

Rep: Reputation: Disabled
Carrying this a little further....

And does SOX have a way to take input and do the VOX thing starting a new file each time etc. Meanwhile take the same input and replicate what a sound meter does, so you get a second file giving you a series of sound levels (with no breaks)? A sound meter would give you readings every 35 ms (impulse), 125 ms (fast) or 1 s (slow) with "A", "C", flat, or some other weighting scheme. Perhaps even produce more than one file using different weightings and time periods, maximum vs. RMS, etc.
 
Old 09-25-2018, 08:57 AM   #6
duncanlinux
LQ Newbie
 
Registered: Feb 2008
Location: Troy, Alabama
Distribution: Fedora or Debian
Posts: 7

Rep: Reputation: 0
Have you tried CRON?

I know this is an old thread, but it seems like you could have this script run every minute using CRON then exit upon completion. The only problem would be you would be if you had a recording that lasted 15 seconds, you would have to wait 45 seconds before CRON would run again. People more versed in CRON than me may have a solution to run it in smaller intervals than 60 seconds.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
does sox convert .mp3 to .aiff audio file? ejames82 Linux - Software 3 09-15-2011 08:06 PM
saa7133 tv card: audio only via sox Kropotkin Linux - Hardware 3 04-29-2009 12:17 AM
recording radio using sox CrashedAgain Linux - Software 14 05-12-2008 12:43 AM
syntax with SoX & lame audio recording rotezecke Linux - Newbie 0 02-25-2008 07:52 PM
Sox recording command outputs blank files anid.iitk Linux - Newbie 2 05-29-2006 01:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration