Trying to find silences from python script

https://forum.audacityteam.org/t/pipeclient/65283/1


Opero con Audacity 3.2.1 en windows 11 con python 3.10.6
Trato de localizar silencios en un track desde un script python utilizando test.py. (En interactivo funciona perfectamente).
No sé si es un problema de sintaxis o el comando no existe en Python.
Los comandos que envío son:
do_command(“Import2: Filename=C:\users\isaac\downloads\knico.mp3”) OK
do_command(“SelectAll:”) Ok
time.sleep(2)
do_command (“LabelSounds:treshold=0.0,measurement=‘avg’,sil-dur=0.4,snd-dur=0.01,type=‘between’,pre-offset=0,post-offset=0,text=‘nosound’”) Fail
do_command(“LabelSounds:type=‘between’”) Fail


Otra prueba:
do_command(‘Help: Command=“LabelSounds”’)
Send: >>>
Help: Command=“LabelSounds”
Rcvd: <<<
Command not found
BatchCommand finished: OK

Si ejecuto analizar etiquetas de sonidos interactivamente en el menú, audacity genera los tramos de silencio que le he solicitado y entonces si ejecuto desde el script python la siguiente línea, obtengo con éxito una cadena perfectamente procesable.
kk=do_command(“GetInfo: Type=Labels”) OK



I use Audacity 3.2.1 on windows 11 with python 3.10.6
I’m trying to locate silences in a track from a python script using test.py. (In interactive mode it works perfectly and I locate the silences).
I don’t know if it’s a syntax issue or the command doesn’t exist in Python.
The commands I send are:

do_command(“Import2: Filename=C:\users\isaac\downloads\knico.mp3”) It works OK
do_command(“SelectAll:”) It works OK
time.sleep(2)
do_command ("LabelSounds:treshold=0.0,measurement=‘avg’,sil-dur=0.4,snd-dur=0.01,type=‘between’,pre-offset=0,post-offset=0,text=‘nosound’ ") Fail
do_command(“LabelSounds:type=‘between’”) Fail


Another test:
do_command(‘Help: Command=“LabelSounds”’)
Send: >>>
Help: Command=“LabelSounds”
Rcvd: <<<
Command not found
BatchCommand finished: OK

If I select analyze - sound label - interactively from the menu, audacity generates the silent chunks I’ve asked for, and then if I run the following line from the python script, I successfully get a perfectly processable string.
kk=do_command(“GetInfo: Type=Labels”) Works, OK

Is there any command or method to generate the sections of silence from Python?

That should be: threshold
and the value needs to be negative.

Try changing the command to:

LabelSounds:measurement='avg' post-offset=0 pre-offset=0 sil-dur=0.4 snd-dur=0.01 text='nosound' threshold=-30 type='between'

Thanks for your quick answer.
when I try:

do_command ("LabelSounds:measurement='avg' post-offset=0 pre-offset=0 sil-dur=0.4 snd-dur=0.01 text='nosound' threshold=-30 type='between")

It fails and finish with de next message.
‘The LabelSounds script was not recognized.\nBatchCommand finished: Failed!\n’
Some idea?

Is “Label Sounds” present in the “Analyze” menu? If so, does it work?

“Label Sounds” IS NOT present in the “Analyze” menu. Instead, Etiquetar sonidos… appears.
Thanks to your answer I have found the command that helps me to find the silences.
The name of the command is unintuitive and I have found it after many attempts.

  do_command("EtiquetarSonidos:measurement='avg' post-offset=0 pre-offset=0 sil-dur=0.4 snd-dur=0.01 text='nosound' threshold=-30 type='between'") #It works OK

The biggest problem is that I hadn’t read anywhere that some, not all, commands had to be translated. The language of my OS, windows, is Spanish and it may be that this is the cause of the mixture (in the menus and in the scripting commands) of English and Spanish languages.

It’s due to a combination of design decision that were made several years ago:

  1. Names of effects are translated so that they are easier to understand in Audacity’s menus.
  2. The same names are used in the “Manage Macros” interface (for the same reason): https://manual.audacityteam.org/man/manage_macros.html
  3. The same commands are used for Python scripting as are used in Macros: https://manual.audacityteam.org/man/scripting_reference.html

Tip: It can often be useful to look in the Macro Manager to check names and syntax for Scripting commands.

Note that when using translated names in a script (or macro), Audacity must be using the same language settings as when the script / macro was created.

Thanks for the help and precise clarification.