Macro equivalent fro "insert silence"?

When comparing macros to menu items, I found some inconsistent behaviour (Audacity 2.3.0)
Start: the cursor is anywhere in an audio track but no region selected

  1. Generate > Silence inserts silence of the duration specified in the dialogue (and remembered)
  2. Edit > Remove Special > Silence Audio replaces the whole track with silence
  3. The macro “Silence” brings up the dialogue as in 1) - however it behaves like 2), i.e. all audio in the track is silenced!

Once a region is selected, everything is as expected.

Is there a macro to insert silence (at the cursor position)?

Only if the whole track is selected (which may happen automatically if you have the non-default “Auto-select, if selection required:” Preference enabled).
“Edit > Remove Special > Silence Audio” silences the selected audio.

“Silence” has always been a bit peculiar in Audacity. The “Silence Audio” command (in the “Edit” menu) is actually an “effect” (belongs in the “Effect” menu) rather than an edit command. Some time way back in Audacity’s history, someone thought it should be classed as an “edit command” (although it is really an “effect”), and it has been that way ever since.

To complicate the matter further, the “Silence” effect has two separate implementations - one is as an “effect” (in the “Edit” menu), and the other is as a “generator” (in the “Generate” menu).

As far as I can tell, the two Macro commands “Silence” and “Silence Audio” both reference the same code, which is the same code as the “Silence effect”. As with other built-in “generator” macro commands, it is applied to the “selection”, or to the entire project if there is no selection.
(I agree that this is confusing, but as far as I can tell, it is behaving “as designed”, with the caveat that the duplication of the Silence command / effect is an unfortunate legacy.)

There is no “built-in” macro to inset silence, though there are alternatives.

Probably the best alternative is to create a simple “Nyquist” plug-in to generate silence.
(More information about writing Nyquist plug-ins here: Missing features - Audacity Support)

Another way would be to add a new (temporary) track, then make a selection, generate some silence, then cut and paste it where you want it.

indeed this option was on - although I don’t remember having ever set it (never even knew about it).
Now, if I don’t make a selection it brings up a message that I need to make one. This explains 2)

However even after unticking this option the “silence” macro still behaves as before: it doesn’t complain about the missing selection, but silences the whole track.

Indeed, this was my feeling as well after I tried to understand which does what. The macros with Scripting-Id “Silence” and “Silence Audio” seem to map to the “Silence” (in the Macro Insert dialog) - only at second look there is a distinction between “Effect” and “menu item”.
Strange enough: The scripting reference (Scripting Reference - Audacity Manual) only lists the menu item and completely misses to describe the silence effect in the “generate menu” section.

not quite, as far I can tell: The silence effect allows to specify a duration, while the menu function strictly operates on the selected region. The macro however ignores the duration specified in the dialog.

Oh well - just too confusing…
Guess I will goy for your workaround suggestions.

Thanks anyway for the explanation.

Yes, that’s correct.

“Macros” have developed out of the old “Chains” feature, which was rather more limited than the new Macros. Chains were simply a list of effects - a similar idea to “chaining” multiple hardware effects in sequence. The chained effects would always be applied to the entire project (which is typically what you would want to happen for “batch conversions” of multiple files).

Macros retain backward compatibility with Chains, but also support Analyze, Generate and Tools type effects, plug-ins, and “commands”. In Macros (but not Chains), any type of effect or plug-in can be applied to a selection, or if there is no selection, then it is applied to the entire track / project.

In built-in effects / generators / analyzers, “time controls” are ignored. Either the selected region, or the entire track / project are used.

In the Macro editor, whether you select “Silence” (Silence Effect) or “Silence Audio” (Menu Command (No Parameters)), you can click on the “Edit Parameters” button and you get the same GUI appear:
In both cases, setting a duration is ignored by the macro.

Do you agree that there are two issues here that could do with some improvement:

  1. The duplication of “Silence” and “Silence Audio” is confusing.
  2. The apparent availability of a “duration” setting in built-in generator effects is confusing because the duration is ignored.

Anything else?

Yes, I agree that these 2 issues could so with some improvement.
Nothing else jumps into my mind at this time, but I only spent little time on macros so far.
If the preset duration of silence was observed, then the only meaningful effect for me was to insert silence of the set duration at a given position (provided that no selection is made). This would then address my original question :slight_smile:

Thanks for considering this for an improvement.

Thought you might be interested in an update.

I’ve discussed the question of “duration” controls from built-in generator effects in relation to “Macros”, with the lead developer of the Macro / Scripting features. Here’s some of his comments, which I think will give you an insight into his thinking:

“Durations should not even be offered in macros for generators, not even greyed out, where the selection is going to be used.”
(In future versions of Audacity, it may be possible to show the generator GUI without the time control.)

“I think generators and effects via macros are best used with selections. We should not support durations.”

“There are so many possible things to automate where it would be nice to have it in ‘one step’ that we can’t directly cater for them all. Automation could be improved in its ability to move clips around.
It is possible to already, just, but I wouldn’t do it from a macro. Too inflexible. Moving clips around is a case where Python or Nyquist is needed.”

The point here is that “Macros” could be extended indefinitely, but in doing so we would, in effect, be inventing a new programming language. We don’t want to do that - there are already many excellent scripting languages (such as Python and Nyquist), so there is little to gain from a lot of effort by reinventing that particular wheel.

“I don’t think we need to make Generators from Macros more complex so that they can insert as well as replace. At the same time, if someone goes ahead and implements that nicely, I wouldn’t be too worried by the extra complexity. In the end Audacity code evolves based on what people need and what people are prepared to write.”

He did also suggest an easy way to insert silence, using only the functionality already available in Macros:

  1. Start: the cursor is anywhere in an audio track but no region selected
  2. Set a selection from the cursor position (Start = 0) with “End” set to the required silence duration.
  3. Copy
  4. Set the selection to “Start = 0, End = 0” (the cursor is back at the original position
  5. Paste (a copy of the audio is inserted - the length is the required length of the silence, and is selected)
  6. Silence Audio (the copied / pasted audio is replaced with silence.

Thanks for the update and insights, Steve.
I can complete follow the developer’s thoughts that customers always want more complexity in one area - and then complain about it in another area which happens to be out of their focus of interest :slight_smile:
I was on the other side of the desk long enough, working in SW support for 20 years …
The learning and position I internalized from this time is: You can offer customers anything, as long as it is correctly documented. Then at least you can refer them to “RTFM” …
Therefore I would divert my improvement request to:
Please spend a little more efforts in documenting this behavior, namely

  • add the missing secription of “silence” to the Generate section of the scripting reference
  • mention the behavior if no selection is made (no insertion and predefined duration ignored)

Additionally you may consider a warning about the fact that macro will silently silence the whole track, if no selection is made, even if the “Auto-select, if selection required:” Preference is disabled. I guess a prompt or warning during execution of the macro (like when using the edit silence function from the GUI) is not a good idea.
Preventing undesired silencing may be worth a warning also because I found that undo-ing a multi-step macro may not work completely. For me only parts of it got undone, but the fades (in/out) didn’t. Hence I suspect that there is a limit in complexity of what can be undone.
If unintended silencing of a whole track could not be undone, this might be a disaster.

Ah - and thanks for the developer’s suggestion just using existing macros. I will give it a try as well.
It looks pretty straight forward and it may be worth mentionig in the documentation as a workaround to inserting silence (given that the duration is ignored).

Regarding Macros and Scripting, there has been a huge amount of new stuff added very recently. The documentation is catching up, but as the features are so new, it is still in part a moving target (example: the change in “GetInfo: Labels” from 2.3.0 to 2.3.1). At this stage, Macros and Scripting should probably be considered as “experimental”, and there will probably be changes as we get feedback from people (like yourself) that experiment with these features.

There’s about 50 new Nyquist commands available in Audacity 2.3.1 which are not documented yet - that’s a task that I need to try and complete before Audacity 2.3.1 is released (scheduled for January, but the manual has to be complete before the release candidates can come out.)

“Undo” is still a bit peculiar with Macros (not always working properly). As I understand it, a Macro should be treated as “one” event, so “one” undo should undo the entire Macro. Currently, this does not always happen (the developer is aware of this bug). What works for me in most cases, is to Undo to one step before the Macro, then Redo one step.

I see - since I’m new to the forum and so far never looked into macros, I was not aware of the state of flux that all this is in.
I’ll be glad to watch how this develops.
I’m more and more amazed what a sophisticated tool you and the community are developing here - keep up the great work!

Glad to hear you are enjoying it :slight_smile:
Audacity has had “Chains” for years, and while they were stable and effective, we had many requests for greater flexibility. Then we got Macros and Scripting, which massively extend the ability to automate tasks. Personally I find this one of the most exciting areas of development in Audacity in a long time.

Hi Steve,

I was just wondering about this thread. I have a couple Macros that I use for deleting and silencing sections of audio. As I’m listening to the audio to find spots to edit, I press the ‘X’ key to pause and then I have assigned the two Macros mentioned above to a shortcut key that is also assigned to my mouse buttons. So I select the audio to delete or silence, then the Macro does a Select Zero Crossing, Delete or Silence, Cursor Short Jump Left, then a Play/Stop and Set Cursor. This allows me to do the edit, hear the edited section, and keep moving with just a mouse button click. But as this thread talks about, the Macro can’t be undone. So if I mess up, I can’t easily recover when I use the Macro approach - at least I can’t find a way to easily do that. Has the Macro issue made it to a point where it is being worked on and/or is there another approach I might use to do my editing. I’m a newbie to all this so still at the beginning of the learning curve. Thanks, Mike

Most of that can be done without using Macros. In the “full” set of keyboard shortcuts:

“C” = Cut Preview
“Del” = Delete
“Ctrl + L” = Silence Audio
“Z” = Zero Snapping
“Shift + Ctrl + F5” = Play After Selection Start

The full list of default shortcuts is here: Commands and Keyboard Shortcut Reference - Audacity Manual

There is still a bit of a problem with undoing Macros. Some Macros seem to Undo correctly, but others don’t. This is logged as a bug that needs fixing.
I find that in most cases I can successfully undo a Macro with “Undo” followed by “Redo” (“Ctrl + Z”, “Shift + Ctrl + Z” or “Ctrl + Y” depending on platform).

Hello from NZ. I have been searching for a way to automate the insertion of 2 seconds silence at the end of set of tracks, and found this forum. I was grateful to find some very useful tips here that enabled me to write a viable macro, so thanks to those who contributed, with a special thanks to steve » Fri Nov 30, 2018 6:40 pm.
For the benefit of anyone else who may be interested, here is the method:
20210223_231231 Audacity insert silence at end of track.png
Audacity version = 2.4.2

If the project has only one track, there’s a simpler way:

SelectTime:End="-2" RelativeTo="ProjectEnd" Start="0"
Silence:Use_Preset="<Current Settings>"

(Notice that “End” is set to negative 2, relative to “Project End”)

For a single track in a multi-track project, one additional command is required (“Select Track Start to End”), and then select relative to the end of the selection (but this version would not be used for batch processing):

SelectTime:End="-2" RelativeTo="SelectionEnd" Start="0"
Silence:Use_Preset="<Current Settings>"

That’s excellent, Steve; works perfectly, including processing multiple files, which is what I was wanting to achieve. Load file, add silence at end and then re-save (export as FLAC); repeat. It’s much more concise than my effort.
Thank you. :smiley:

here is a macro to insert silence of 1 second at cursor

Select:End=“1” RelativeTo=“Selection” Start=“0”

duration of silence can be changed in second line

Marvelous! Thanks a lot Zahoor.

In the current version of Audacity (3.1.3) with default settings, this will throw an error:

"There is not enough room available to paste the selection"

If anyone gets that error, the solution is to change one of Audacity’s Preference Settings:
“Preferences > Track Behaviors > Editing a clip can move other clips: Selected”
(see: Tracks Behaviors Preferences - Audacity Manual)