Chop a WAV into segments triggered by PowerShell

Questions, discussion and recipes for scripting and batch processing in Audacity.
See also the "Scripting" section of the Audacity manual.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
ORTF
Posts: 2
Joined: Sat Apr 24, 2021 12:51 pm
Operating System: Windows 10

Chop a WAV into segments triggered by PowerShell

Post by ORTF » Sat Apr 24, 2021 12:58 pm

Hello out there!

Background:
For every incoming call on a dedicated landline number answering machine my router sends an e-mail to my MS Outlook. Detecting a registered caller ID Outlook takes a VBA script to forward the attached WAV-file to a local folder. It shows up with a modified filename in a pattern like [YYYY-MM-DD]-[HH-MM]-[Caller ID].wav. Now PowerShell triggers audacity to do its job.

The registered caller is sending DTMF codes to be converted in TXT-data and published on a webserver. The conversion and the publishing to TXT is handled by VBA in MS Excel 2019 (and works already).

#####
Audacity's job is to chop the incoming call into the contained 1 to 15 pulses, do a plot spectrum export to files named as above plus -[Segment-ID] for example "2021-04-30-Bon Jovi-1...15"

The execution of following procedure shall be triggered by a Command Line / PowerShell script:
1.) open a WAV file
Cut all unneeded frequencies:
- high pass filter 650 Hz and above
- low pass filter 1500 Hz and below ' frequencies from 650 to 1500 Hz must remain
- noise gate threshold -65 dB ' only louder segments should be processed
2.) find all pulses greater than 1,5 seconds
- chop into selections
- plot a spectrum (Spectrum / Blackman-Harris) of the selection / segment and export to [path/]2021-04-30-Bon Jovi-1...15.txt
3.) close Audacity without saving
#####

Now it's VBA's job to continue.

My problem is that I've got no idea how to implement this procedure in Audacity. I found some information about macros and Nyquist but that's all far away of my knowledge.

If we -you and me- can make it run, I'll publish here a free DTMF decoder without any Linux help. Windows can do too ...

THX a lot 'n more! for any help

Henning

steve
Site Admin
Posts: 81388
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Chop a WAV into segments triggered by PowerShell

Post by steve » Sat Apr 24, 2021 2:14 pm

ORTF wrote:
Sat Apr 24, 2021 12:58 pm
My problem is that I've got no idea how to implement this procedure in Audacity.
You can probably do this using "named pipes" (see: https://rkeithhill.wordpress.com/2014/1 ... med-pipes/)

Most of the documentation for controlling Audacity through named pipes use Python as the programming language, but the commands are the same for any language. The prerequisite is that the language being used must support named pipes.

See here for an introduction to scripting Audacity through named pipes: https://manual.audacityteam.org/man/scripting.html

See here for the list of available commands: https://manual.audacityteam.org/man/scr ... rence.html

Because the commands used are the same for scripting and for Macros, you can test the commands by creating a macro.
(See: https://manual.audacityteam.org/man/macros.html)

Unfortunately there is currently no way to export the spectral data using scripting commands.
One possible workaround might be to open "Plot Spectrum" with the scripting command "PlotSpectrum:", and then emulate keystrokes to perform the export. I don't know if PowerShell can do that. There are a number of libraries available for Python to emulate keystrokes, but the ones that I've seen are platform dependent.
ORTF wrote:
Sat Apr 24, 2021 12:58 pm
The execution of following procedure shall be triggered by a Command Line / PowerShell script:
1.) open a WAV file
Cut all unneeded frequencies:
- high pass filter 650 Hz and above
- low pass filter 1500 Hz and below ' frequencies from 650 to 1500 Hz must remain
- noise gate threshold -65 dB ' only louder segments should be processed
2.) find all pulses greater than 1,5 seconds
- chop into selections
- plot a spectrum (Spectrum / Blackman-Harris) of the selection / segment and export to [path/]2021-04-30-Bon Jovi-1...15.txt
3.) close Audacity without saving
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

ORTF
Posts: 2
Joined: Sat Apr 24, 2021 12:51 pm
Operating System: Windows 10

Re: Chop a WAV into segments triggered by PowerShell

Post by ORTF » Sat Apr 24, 2021 8:24 pm

Hi Steve,

thx a lot for this detailed information. I'm sure it will help me to do the next steps. If it's not PowerShell it's VBA to emulate keystrokes, so I guess the described difficulties can be solved at the end.

Thank you so much!!

Henning

hockulus
Posts: 1
Joined: Thu May 06, 2021 9:07 am
Operating System: Windows XP

Re: Chop a WAV into segments triggered by PowerShell

Post by hockulus » Thu May 06, 2021 9:10 am

Hey Henning,
did you find a solution for Powershell? I was wondering how to start and export recordings :(

Post Reply