Generate Five Seconds of Silence "in situ"

I want to generate a fixed five seconds of silence. Right now I don’t care whether I have a point-selection (zero-length) or an area selection (up to twenty seconds in some cases). For the second time in my life I have waded through Macro equivalent fro “insert silence”? and this time around I understand why the dialogue box, where I can enter duration accurate to 1/100,000 of a second - is completely ignored. Also why it is ignored.
Finally I broke my task down into atomic units (I think I’ll name it “modular programming” :smiley: ) as I slide more comfortably into the Audacity-macro way of thinking. FORTRAN II it isn’t.

Perhaps I need to break this down:
(a) Delete the current selection
(b) Copy a five-second chunk of Audio from the current selection
(c) Paste(Insert) that five-second chunk of Audio at the current selection
(d) Generate Silence in the currently selected chunk of junk

The macro “GenerateSilence8”
Comment:_=“Please see attached PKZip file”

I am feeling particularly pleased with myself, and am looking forwards to many hearty congratulations on my achievement, but you ought to use that energy to bestow thanks to Steve and all participants of the previously mentioned thread,

With many, many thanks to you all.
PS “GenerateSilence8” because it was my eighth attempt, not 8 seconds of silence.
C (1.98 KB)

Please clarify what you want to happen:

  • If 10 seconds is selected, do you want to replace the 10 seconds with 5 seconds of silence?
  • If 10 seconds is selected, do you want to replace the the first 5 seconds of the selection with 5 seconds of silence?
  • Do you want to insert 5 seconds of silence at the beginning of the selection?
  • Do you want to insert 5 seconds of silence at the end of the selection?
  • Something else?

Hi Steve.
I have a single audio track.
I use the mouse to select a piece of that track; I might click the mouse (zero-length or “point” selection) or I might click-and-drag the mouse (any length selection).
The selection of length may be all-silence, all-sound, or a mixture of sound and silence that I want to replace.
(I am reading text from a book and recording it to Audio)
Whatever I have indicated by my selection - point or line - is to disappear completely, and in its place must appear exactly five seconds of silence.

I thank you for asking, but I should tell you that I have tested the macro a little this afternoon, and am about to give it a grueling test later today in My Real World.

Most if not all the macros I have seen to date insert silence at the start or at the end of a track. I am editing a track and need place exactly five seconds of silence, replacing whatever, if anything, I have selected.

I hope that makes sense. I haven’t felt tis happy since I started using Audacity about twelve years ago.

It certainly isn’t :smiley:

Each macro is just a list of commands that are run in sequence, usually without any additional user interaction.
The last point; “without user interaction” is an important prerequisite for batch processing.

Each command is basically the same as a normal Audacity command, though there are a few subtle differences from the normal Audacity commands.

One example of the difference can be seen in the “Silence” generator. There are actually two “Silence” commands that can be found in the menus:

  1. “Edit menu > Remove Special > Silence Audio”
  2. “Generate menu > Silence”
    Both commands use the same code within Audacity.
    The “Silence” Macro command works like the “Silence Audio” command, in that it replaces the current selection with the same amount of audio.
    You may have noticed that Audacity’s built-in generators all do this - the duration of audio generated is the same as the length of the selection.

Once we know that, the task becomes quite simple.

Breaking that down into a sequence of steps (Macros are a sequence of commands):

  1. “Whatever is selected is to disappear:”
  1. “and in its place must appear exactly five seconds of silence.”
    So now we need to generate 5 seconds of silence, but we know that to generate 5 seconds of silence we must have a 5 second selection:
Select:End="5" Mode="Set" RelativeTo="SelectionStart" Start="0"

That has selected 5 seconds, but it has selected 5 seconds of audio that we want to keep. We need to somehow shift the audio in the selection 5 seconds later so that it isn’t overwritten by the silence:

Select:End="5" Mode="Set" RelativeTo="SelectionStart" Start="0"

Now we can silence the first 5 seconds:

Silence:Use_Preset="<Current Settings>"

Putting the whole thing together:

Select:End="5" Mode="Set" RelativeTo="SelectionStart" Start="0"
Select:End="5" Mode="Set" RelativeTo="SelectionStart" Start="0"
Silence:Use_Preset="<Current Settings>"

Thanks Steve. I think you will find that this parallels what I did in the ZIP files attached to my post.
My macros will be classified either as “Command” or “Compound”.
The Command macros will be cover functions for the 360 commands in Audacity (or at least, those that I can code).
The Compound macros will be composed of “Command” and “Compound” macros.
PS I rather like the “360”. Makes me think “Audacity encompasses all your needs …”

Super :slight_smile:

When you’ve worked through all 360, you may be interested in looking at using Nyquist to handle conditional branching. For example, something like this (pseudo code) requires requires conditional branching that is not available to Macros directly, but can be implemented by including a Nyquist macro as one of the steps:

FOR (each track) DO: {
   IF (stereo track) { <some commands> }
   ELSE { <some other commands> }