Minimum length mod for Silence Marker and Sound Finder

Using Nyquist scripts in Audacity.
Post and download new plug-ins.

If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like

Minimum length mod for Silence Marker and Sound Finder

Permanent link to this post Posted by cco059 » Mon Nov 02, 2009 2:39 am

I need modification for this Nyquist Plugin - Silence Marker. Seems like when the labels are exported using the "Export Labels", the content of the label.txt file only contains the location of the silence label in the audio file and not the duration of the silence. Can you please change the plug-in so that the labels contain the start and end of the silence and also the duration of the silence ?


Current Sample of Labels.txt file
1.010068 1.010068 S

Expected Sample of Labels.txt:
1.010068 1.020068 0.01 S

Thanks a lot.
cco059
 
Posts: 2
Joined: Mon Nov 02, 2009 1:30 am
Operating System: Please select

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by steve » Mon Nov 02, 2009 5:25 pm

cco059 wrote:Can you please change the plug-in so that the labels contain the start and end of the silence and also the duration of the silence ?

If you do that, then the labels created by the plug-in will be in the wrong format and will not be accepted by Audacity as valid labels. Labels have only three parameters - start time, stop time and label text.

If you can explain what you want and why you want it, there may be some other approach that will work.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46554
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by Storer » Mon Nov 02, 2009 5:47 pm

Since the label text now is only a single 'S', the duration could be included in the label text.
Win XP Pro/SP3 ---- Audacity 1.3.12RC2
Storer
 
Posts: 91
Joined: Wed Mar 04, 2009 8:02 pm
Operating System: Please select

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by cco059 » Tue Nov 03, 2009 9:51 am

I want it to detect audio hole in the audio file recorded. I am recording a continous 1kHz tone from a source for 10seconds. If the source is good there should not be any audio hole or silence detected throughout the duration of the 10 seconds.
If the silence is detected, I want to be able to know where it started and how long is the duration of the silence.

Seems like the label exported contains only 2 numbers ( which I believe denotes the start of the silence) and the "S" label
I was hoping the plug-in could be modified to include more information on the labels like the example I sent earlier.

Thanks in advance for your help.
cco059
 
Posts: 2
Joined: Mon Nov 02, 2009 1:30 am
Operating System: Please select

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by steve » Tue Nov 03, 2009 11:30 am

A couple of things to avoid confusion in our readers:
"SilenceMarker.ny" is the file name of the "Silence Finder" effect.
"Silence Finder" is only accurate to within a few milliseconds, not to the nearest sample.
This may require the latest version of Audacity 1.3 to work correctly.

If you want to export a list of start times and stop times for the silence you can do it like this:

1) The silence finder places markers based on the end of the silence. Set it to place markers at 0.00 seconds before the end of the silence.
Set the other settings as required and run Silence Finder.

2) Now Reverse the track (Effect > Reverse).

3) Add a new label track from the Tracks menu.

4) Drag the new label track so that it is directly under the audio track.

5) Run Silence Finder again with the same settings.

6) Check that "Link tracks" is ON (ling button depressed) and select ONLY the audio track and Reverse it. The label track that is directly below the audio track is linked, so it will also reverse.

Your audio is now the right way round again and you have markers at the start points in one label track and end points of any silences in the other label track.

Select all (Ctrl+A) and Export the labels. The two label tracks will be merged in the Exported file.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46554
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by triola » Fri Nov 27, 2009 1:49 pm

Hey! I solved it!
I modified the SilenceMarker so, that he marks both:
1) begin of silence - as end of previous track
2) end of silence - as begin of next track
Labels are not only "S", but "Track 01" etc. and "End Of Track 01" etc.

Use: Save the attached file to Audacity Plug-Ins folder. Or save the code as a new plain-text file "SilenceTrackMarker.ny".copy the code to new You should

You should have only 1 long track loaded form MC or LP
Then you should only run:
1) Run: Analyze > Track Finder By Silences
2) Export all to MP3's: File > Export multiple
3) manualy delete the "End Of Track*.mp3" files
That's all!

I attache the file, but here's also the code:
Code: Select all
;nyquist plug-in
;version 1
;type analyze
;name "Track Finder By Silence..."
;action "Finding silence and mark cutting points for each track ..."
;info "JMA (http://tuzka.cz/jma) 2009 Based on: Silence finder written by Alex S. Brown, PMP (http://www.alexsbrown.com)nVersion 1.0 released Apr 3 2005 under the GPL licensen(http://www.opensource.org/licenses/gpl-license.php)n
;control sil-lev "Silence level" real "dB" 26 0 100
;control sil-dur "Minimum silence duration" real "seconds" 1.5 0.1 5.0
;control labelbeforedur "Place label" real "seconds before silence ends" 0.3 0.0 1.0

;Create a function to make the sum the two channels if they are stereo
(defun mono-s (s-in) (if (arrayp s-in) (snd-add (aref s-in 0) (aref s-in 1))
s-in))

;Create a function to reduce the sample rate and prepare the signal for
;analysis. RMS is good to monitor volume the way humans hear it, but is not
;available in Audacity. Used a peak-calculating function instead.
;NOTE: this is the place to add any processing to improve the quality of the
;signal. Noise filters could improve the quality of matches for noisy signals.
;PERFORMANCE vs. ACCURACY
;Reducing the samples per second should improve the performance and decrease
;the accuracy of the labels. Increasing the samples per second will do the
;opposite. The more samples checked, the longer it takes. The more samples
;checked, the more precisely the program can place the silence labels.
;my-srate-ratio determines the number of samples in my-s. Set the number after (snd-srate s)
;higher to increase the number of samples.

(defun my-s (s-in)
 (setq my-srate-ratio (truncate (/ (snd-srate (mono-s s-in)) 100)))
 (snd-avg (mono-s s-in) my-srate-ratio my-srate-ratio OP-PEAK)
)

;Set the silence threshold level (convert it to a linear form)
(setq thres (db-to-linear (* -1 sil-lev)))
;Store the sample rate of the sound
(setq s1-srate (snd-srate (my-s s)))
;Initialize the variable that will hold the length of the sound.
;Do not calculate it now with snd-length, because it would waste memory.
;We will calculate it later.
(setq s1-length 0)
;Initialize the silence counter and the labels variable
(setq sil-c 0)
(setq l NIL)
;Convert the silence duration in seconds to a length in samples
(setq sil-length (* sil-dur s1-srate))

;Define a function to add new items to the list of labels
(defun add-label (l-time l-text)
 (setq l (cons (list l-time l-text) l))
)

;JMA: Initialize the track counter
(setq track-c 0)

;JMA: Get the track number as string with leading zeros
(defun int-to-string (iint iplaces)
 (strcat
  (if (> iplaces (length (format nil "~A" iint)))
   (subseq "00000000" 0 (+ 0 (- iplaces (length (format nil "~A" iint)))))
   ""
  )
  (format nil "~A" iint)
 )
)

;The main working part of the program, it counts
;the number of sequential samples with volume under
;the threshold. It adds to a list of markers ever time
;there is a longer period of silence than the silence
;duration amount.

;It runs through a loop, adding to the list of markers (l)
;each time it finds silence.
(let (s1) ;Define s1 as a local variable to allow efficient memory use
 ; Get the sample into s1, then free s to save memory
 (setq s1 (my-s s))
 (setq s nil)
 ;Capture the result of this "do" loop, because we need the sountd's legnth
 ;in samples.
 (setq s1-length
  ;Keep repeating, incrementing the counter and getting another sample
  ;each time through the loop.
  (do ((n 1 (+ n 1)) (v (snd-fetch s1) (setq v (snd-fetch s1))))
   ;Exit when we run out of samples (v is nil) and return the number of
   ;samples processed (n)
   ((not v) n)
   ;Start the execution part of the do loop
   ;if found silence, increment the silence counter
   (if (< v thres) (setq sil-c (+ sil-c 1)))

   ;If this sample is NOT silent and the previous samples were silent
   ;then mark the passage.
   (when (and (> v thres) (> sil-c sil-length))
     ;JMA: mark BEGIN of silent passage as end of previous Track
     ;JMA: Mark the user-set number of seconds AFTER first silence sample
    (add-label (+ (/ (- n sil-c) s1-srate) labelbeforedur)  (strcat "End Of Track " (int-to-string track-c 2)) )
     ;JMA: increment Track number
    (setq track-c (+ track-c 1))
     ;Mark the user-set number of seconds BEFORE this point to avoid clipping the start
     ;of the material.
    (add-label (- (/ n s1-srate) labelbeforedur) (strcat "Track " (int-to-string track-c 2)) )

   )
   ;If this sample is NOT silent, then reset the silence counter
   (if (> v thres) (setq sil-c 0) )
  )
 )
)

;Check for a long period of silence at the end
;of the sample. If so, then mark it.
(if (> sil-c sil-length)
 ;If found, add a label
 ;Label time is the time the silence began plus the silence duration target
 ;amount. We calculate the time the silence began as the end-time minus the
 ;final value of the silence counter
 (add-label (+ (/ (- s1-length sil-c) s1-srate) sil-dur) (strcat "End Of Track " (int-to-string track-c 2)))
)

;If no silence markers were found, return a message
(if (null l)
 (setq l "No silence found, no passages marked")
)
l
triola
 
Posts: 4
Joined: Thu Nov 26, 2009 11:17 am
Operating System: Please select

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by steve » Fri Nov 27, 2009 4:33 pm

Nice one triola ;)

Having seen your other posts regarding your modified plug-in, I think it is necessary to point out that for the usual "Export Multiple" method of splitting tracks (as described here: http://wiki.audacityteam.org/index.php? ... ate_tracks ) the original silence finder plug-in should be used as your modified version will cause too many files to be exported. The tracks will be exported (as required) but there will be an equal number of short silent tracks also exported.

A small modification to your code could improve the behaviour for using Export Multiple.
Rather than creating separate labels for the start and end of tracks, you could create region labels (not available in Audacity 1.2.x).
To specify a region label you need to create a list of lists (as you do now), but instead of the label being specified as (time text) it needs to be specified as (t0 t1 text) where t0 is the start time and t1 is the end time of the label.

Here's an example of how to create region labels:
Code: Select all
(let
   ((t1-start 0)(t1-end 1)
    (t2-start 3)(t2-end 4))
(list (list t1-start t1-end "label 1")(list t2-start t2-end "label 2")))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46554
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by Daga » Fri May 14, 2010 5:13 am

Slightly off-topic: I appreciate triola's script and have modified it to use stevethefiddle's region label suggestion. For my own uses, I needed the ability to specify a minimum track length and have added that ability to the script. If you would like, it is available on my website:

http://www.epicvoyage.org/node/55
Daga
 
Posts: 3
Joined: Fri May 14, 2010 5:09 am
Operating System: Please select

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by steve » Fri May 14, 2010 9:31 am

I like the idea of "minimum track length", a useful addition.

A couple of points:

Since you are splitting the track but not removing any silence between tracks, you do not need to use region labels. Simply using "point" labels before the start of the sound will do the same job. This would have the (minor) advantage that it could be made to be compatible with Audacity 1.2.x

The "integer to string" function can be simplified.
Current code:
Code: Select all
; Create a track number as a string, with leading zeros
(defun int-to-string (iint iplaces)
  (strcat
    (if (> iplaces (length (format nil "~A" iint)))
     (subseq "00000000" 0 (+ 0 (- iplaces (length (format nil "~A" iint)))))
     ""
    )
    (format nil "~A" iint)
  )
)


The "(+ 0" is superfluous. Cutting it out (and collapsing the end parentheses) gives:
Code: Select all
(defun int-to-string (iint iplaces)
  (strcat
    (if (> iplaces (length (format nil "~A" iint)))
      (subseq "00000000" 0 (- iplaces (length (format nil "~A" iint))))
      "")
  (format nil "~A" iint)))


Adding a "minimum track length" (minimum sound length) option to the "Silence Finder" effect that is included with Audacity would provide the same functionality. You might like to suggest that on the "Adding Features" section of the forum. viewforum.php?f=20
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 46554
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Nyquist Plugin Modification Needed for SilenceMarker.ny

Permanent link to this post Posted by Daga » Fri May 14, 2010 1:02 pm

stevethefiddle wrote:Adding a "minimum track length" (minimum sound length) option to the "Silence Finder" effect that is included with Audacity would provide the same functionality. You might like to suggest that on the "Adding Features" section of the forum. viewforum.php?f=20

Thanks! This was my first dabble in a Lisp-based language, and consequently my first attempt at an Audacity plugin. I'm afraid that it shows. You are right that I had modified the original intent of the code on this thread. Now that I understand the syntax, I may even be able to provide a patch for the SilenceMarker.ny script (such lofty dreams :P).
Daga
 
Posts: 3
Joined: Fri May 14, 2010 5:09 am
Operating System: Please select

Next

Return to Nyquist



Who is online

Users browsing this forum: No registered users and 1 guest