Simple Automatic Silence Generator


Can someone help me write a Nyquist plugin that generates silence with a value hard-coded into the script? I’d like to insert the silence without a GUI ever being presented.

I’m looking to insert 153 milliseconds exactly at the cursor on the current track and and easy to click script to do this would be a huge help. Never written a Nyquist plugin before but hoping that learning from someone helping me with this one will get me on my way!

Any help appreciated :slight_smile:

I think there already is a plug-in for this somewhere (or at least something similar), but you’ll probably learn a lot more about writing plug-ins by doing it from scratch.

The first thing you need is a plain text editor - preferably one that has “parentheses matching”.
If you’re on Windows I’d recommend Notepad++ (it’s open source and free)
You can use the standard windows NotePad program, but you’ll soon get tired of having to count the number of brackets.

If you’re on Linux, then just about any text editor will do (I usually use “Scite” as it has syntax highlighting for the Lisp language, which is quite similar to Nyquist).

I’d also recommend that you use Audacity 1.3.13 as the old 1.2.6 version is due to retire quite soon and has a very old version of Nyquist.

There’s a really good, up to date introduction to creating Nyquist plug-ins here:

Note that in the current version of Nyquist you can write the code in one of two different forms - either using LISP or SAL syntax.
SAL syntax may be more familiar to people that have previously programmed in C++ or similar languages. I use LISP syntax as that was the only option available when I started to learn Nyquist programming, so any code example that I give will use Lisp syntax. Edgar-rft is another regular contributor to this forum and he also uses the Lisp syntax. Most of the current plug-ins are written using Lisp syntax. Any recent code written by Roger Dannenberg (the creator of the Nyquist language) will probably be written using the SAL syntax.

You’ll see that the first part of a plug-in is the “Header”.
Because your plug-in will not have a GUI, it will be a “version 1” plug-in.

For the actual coding part, to generate silence you can use the (s-rest [duration]) function.

Have a go, and post what you come up with. If you have any problems, give a shout.


Thanks for your help :slight_smile:

I made this:

;nyquist plug-in
;version 1
;type generate
;name "Generate Latency Offset"
;action "Generating silence..."
;info "Latency offset silence generator"

(s-rest (sum 0.153))

It does the job, but the first time I use it on any project, it insists on making its own audio track for the silence. It only does that first time, subsequent times I use it, the silence is added to whatever track I’m using like it should be.

Is there any way to fix this?

Is this Audacity_1.3.13-beta? There had been issues in the past where Nyquist “generate” plugins always created a new track and similar things.

I have tested your plugin with Audacity_1.3.14-alpha (not officially released yet) on Debian Linux and a new track is only created if there in no audio selected in any Audacity audio track. This means that before I apply your plugin for the first time after starting Audacity I first have to click with the mouse into an existing Audacity audio track, to make the plugin know where to insert the piece of silence. If I do not click into an existing audio before, then a new audio track will be created because the plugin doesn’t know where to insert the silence. This behaviour is intentional.

Reading “Latency offset silence generator” - have you tried the Audacity “Edit > Preferences > Recoding > Latency” settings?

Some minor notes: you do not necessarily need the “sum” in the plugin code, this also works:

(s-rest 0.153)

The “sum” doesn’t hurt, but you only need it if you want to add some numbers (where “+” would work faster).

If there are still problems we would need the exact Audacity version number and the operation system (and it’s version) you’re working with.

  • edgar

Congratulations, your first plug-in :smiley:

Generate plug-ins will return audio to the selected track if there is a track selected, but will create a new track (so that there is somewhere for the generated audio to go) if no track is selected. When you use it on your project, ensure that at least one track is selected. You don’t actually want a selected region, you just need to click in the track at the point where you want the audio (silence) inserting.

An easy way to insert the same amount of silence at the very beginning of all tracks is to press Ctrl+A (select All), then click the Home key (cursor to the beginning), then run the plug-in.

You can toggle whether a track is selected or not by using the up/down cursor keys to move to the appropriate track, then press the Return key to toggle the selection.

We generally add a line indicating the software license terms of plug-ins. For example, if you want the plug-in to be open source, just add something like

Released under GPL v2

into the ;info line, and add a comment below the header to say:

;; Released under terms of the GNU General Public License version 2

There’s some information about “conventions” that we’d like to encourage plug-in authors to adopt here: Conventions for Nyquist Plug-ins Of course there is no compulsion to follow these suggestions, but consistency between plug-ins will be helpful to both users of the plug-ins and to anyone that is looking to learn from the code. You are also welcome to add your own comments to that topic if you wish.

I notice that you’ve named the plug-in “Generate Latency Offset”. In Audacity 1.3.x there is already an automatic way to do this. See here:

Hi people :slight_smile:

Thanks for the replies! The only reason I’ve made the plugin is; I’ve already set my Audacity latency value (using the 1.3.13 beta btw under Linux) to -153 milliseconds, which is perfect for ensuring newly recorded tracks are fully aligned up. The problem occurs if I record something simultaneously via Gnome Sound Recorder (using an Autokey script I’ve written to trigger record in both Audacity and Gnome Sound Recorder at the same time - both set to record different sinks). The subsequent WAV file from Gnome Sound Recorder, once imported, needs adjusting within Audacity to line up, and I wanted a plugin to do that quickly for me.

What would be perfect for me, would be a way to make Audacity offset all imported WAVs exactly like it offsets internally recorded WAV files. Or a way to subtract/add the required latency to multiple tracks simultaneously. Any advice? :slight_smile:

Are you using, or can you use Jack?

I can use JACK, but I find it complicates things. I’m happy to stick with ALSA routed through Pulseaudio. Also latency isn’t an issue except when importing and recording from Audacity. Obviously the recording side of things is compensated for automatically by Audacity, but the importing is not.

It’s ok. If I’ve reached the limits of what is currently possible with the technology I’m using, I will endeavour to find a way to work within that to achieve what I want (i.e. offsetting imported WAVs manually, using custom Nyquist scripts)

Really appreciate everyone’s help :slight_smile:

By Shift-clicking into the Audacity audio track headers you can select several audio tracks at once. (Hold the “Shift” modifier key and click with the mouse into the background area of the box with the “Mute” and “Solo” buttons etc. at the beginning of the Audacity audio track.)

If all desired audio tracks are selected, release the “Shift” key and press the “Home” key to make the Audacity cursor jump to the beginning of the tracks.

Now go to the Audacity “Generate” menu and apply your “Latency Offset” plugin to the beginning of all selected audio tracks at once.

Cheers man :slight_smile:

You guys rule. The world would be a better place if all technology was like Audacity :slight_smile: