Batch processing - is it possible with Audacity

Hi,
I have task that will come soon.

Let’s say I have two audio files:

  1. generated by application (mp3) with number of insertion of second file
  2. source file (wav, PCM, 12kHz, 16bit, Mono - short marker to be defined as convenient)

Each insertion of second file in first one has silence (break) before and after. Durations of silence are both approx. 0.2 - 0.6 sec and might be defined equal one to another if it is convenient.

Below you will find the definition of the processing to be performed:

  1. find each insertion of second file in first one according the sequence (first, second, third, etc from the begining)
  2. save start time (precision: 0.001 sec is welcome, 0.01 sec is acceptable) of the insertion to text file.
  3. cut second file content from the first one but silence before and after should be left in output file
  4. save output
  5. loop defined by 1-4 should be repeated for number of files’ pairs

If you really believe above processing is to be performed in Audacity, please give me some hints which Audacity tools should be used.
I am programmer amateur but I know other implementations of Lisp very well.

Thanks in advance

Pawel

“Chains” is Audacity’s batch tool and it’s pretty simple. It can’t, as far as I know, do branching functions. IF this is the second pass THEN do something different.

It’s more like: Open a file, Normalize it, Save it. Repeat with the next file.

Koz

I think that such a plug-in could be written in Nyquist, under certain conditions.

  1. Import the files manually. It doesn’t matter which format, as long as Audacity can import them.
  2. arrange them as follows:
  • The sound your searching for
  • The wave (formerly the mp3), where it is presumably contained.
  • a (empty) track that will represent the second track without the first one.
    keep this order for other files you want to proceed.

The plug-in would perform from top to bottom. So you must save the first track (I guess it is a short sound) in the global value scratch (i. e. in its property list), or you don’t have the data when the plug-in is envoked for the next track. The trickiest part is to analyse the second track, it greatly depends on how close the relationship is between the sounds. It gets highly mathematical if it comes to correlation.
You could use the convolution function if the sound you’re searching for is less than 100000 samples (~2.5 s at 44100). The sound you’re looking for must be turned backward (either in the effect menu or write your own function). If you then do something like

(setq new-sig (convolve sig turned-sig))

you’ll get a new sound where all appearences of the sample-sound are very prominent, but as mentioned above, this depends on how strong the different sounds are related. In a other function you can gather these high level times. You can send this times to the debug window, write them into a file or send them to a label track. Finally, you can extract the portions of the second track that do not contain the sample-sound and re-combine them (doesn’t work if you produce a label track at the same time) and return this sound to Audacity (by destroying the second track or saving it again in scratch and put it in the third track).
So you see, it could be done but its hard labour if you’re not familiar with the Nyquist functions.
Regards

Thanks so much, Robert. I think I will try create the plug-in using your advice.
Regards
Pawel

Only to show that it works:

;; Reduce Samplerate for faster calculation
(set-sound-srate 4410)
(setq long-sound; 60 ramdomly chosen notes in 1 octave 
(seqrep (i 60)
(abs-env (osc-note  (+ 60 (random 12))))))
(setf search-item (osc-note  64)); Note E
; to reverse the sound, we use an array
; Note that snd-fetch destroys the original sound 
; This doesn't matter in our case 
(setq length (snd-length search-item ny:all))
(setf reversed-item (make-array length ))
(dotimes (num length )
(setf (aref reversed-item (- length num 1)) 
(snd-fetch search-item))) 
(setf search-item (snd-from-array 0 *sound-srate* reversed-item))
(setf s (convolve long-sound search-item)) 
(setf factor (/ 1 (peak s ny:all))); for normalisation (important!)
; Back to normal samplerate
(force-srate 44100 (mult factor s))

you can create a mono track and afterwards run the code above in the Nyquist prompt. To retrieve the time data, I would use those functions:

  • snd-oneshot: sets samples above a level to one, all other samples are zero.
    gives: 0001110011110
  • trigger: put a sample of one everywhere where the signal goes from 0 to 1
    gives: 0001000010000
  • integrate (multiplied by the sound-srate)
    gives: 0001111122222
  • sref-inverse returns the time when value is reached for the first time.
    search for 0.999, 1.999 and so on.
    A similar procedure is needed for the end times.
    I hope this helps

Thanks so much, Robert.
One more question. Let’s say I have one audio file opened. Can I get file name with Nyquist?
Regards

Pawel

Hi Paul
Sadly enough, the information that Audacity passes to Nyquist is very restricted.
Only the sound inside the selection and its length in samples are passed over, i. e. the variables

  • s (a sound or a vector of sounds, if stereo)
  • len (The selection length in samples)
  • (get-duration 1) gives the length in seconds
  • sound-srate stores the sample rate for the selected track.
    We all miss badly further information, such as start and stop times, track names envelope data RMS and normalisation values etc.
    You could of course work with saved files. You could provide the file names in a
    text file. In Audacity, you would create sufficient empty tracks and start the plug-in. A counter that you install in the variable scratch keeps track of the file pair you’re just proceeding. The output is then sent to Audacity’s empty track. The collected time information will be sent to the Debug-window or continuously appended to a text file. Make sure that the sounds are saved as wave or aiff, mp3 or ogg is not supported within Nyquist. Ask back in case of doubt.
    Good luck.

That’s it. Thanks again Robert.
Basic information are really appraciated.
I am new both in Audacity and audio processing.
I am gratefull for your feedback.
I’ve got that my challange may be reformulated to potentially easier problem.

So, I need some examples how to:

  1. Open saved files and load them for analysis.
  2. Extract part of audio file based on time range. SoundFinder.ny might be a basis but I need extract parts of file and join them to create output. That mens: SoundFinder.ny type analysis give a time/samples range for extraction to be performed from input file.
  3. Save sound created.
    I created some modifications to SoundFinder.ny but above topics does’n woork for me.
    I’ve downloaded ‘nyquist-2.37-manual.pdf’ and it is my source on Nyquist.

Regards

Paul