I’m trying to write a Python script for Audacity 2.3.2 and I can’t seem to be able to use the NyquistPrompt command as seen on this page: https://alphamanual.audacityteam.org/man/Scripting_Reference. I’m able to execute other commands without issue, so I don’t think it’s a problem with the script pipe. I made sure to set the version to 4, but that doesn’t seem to change anything. Here’s the line I’m trying to execute:
I needed to modify your Python code a bit to get it to run with Python 3 on Linux, but the underlying problem is that the “NyquistPrompt:” command is broken (doesn’t work).
In case it’s any use to you, this was my version of your script (works with Python 3 on Linux). I think it should work with Python 3 on other platforms, but I’ve not tested. The main differences are:
Line 28
TOFILE = open(TONAME, 'w')
Some indentations were tabs rather than spaces.
Global variables in upper case
Removed excess spaces within parentheses.
Replaced final “do” command.
import os
import sys
import time
if(sys.platform == 'win32'):
print("recording-test.py, running on windows")
TONAME = '\\\\.\\pipe\\ToSrvPipe'
FROMNAME = '\\\\.\\pipe\\FromSrvPipe'
EOL = '\r\n\0'
else:
print("recording-test.py, running on linux or mac")
TONAME = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
FROMNAME = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
EOL = '\n'
print("Write to \"" + TONAME +"\"")
if not os.path.exists(TONAME) :
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit();
print("Read from \"" + FROMNAME +"\"")
if not os.path.exists(FROMNAME) :
print(" ..does not exist. Ensure Audacity is running with mod-script-pipe.")
sys.exit();
print("-- Both pipes exist. Good.")
TOFILE = open(TONAME, 'w')
print("-- File to write to has been opened")
FROMFILE = open(FROMNAME, 'rt')
print("-- File to read from has now been opened too\r\n")
def sendCommand(command) :
print("Send: >>> "+command)
TOFILE.write(command + EOL)
TOFILE.flush()
def getResponse() :
result = ''
line = ''
while line != '\n' :
result += line
line = FROMFILE.readline()
#print(" I read line:["+line+"]")
return result
def doCommand(command) :
sendCommand(command)
response = getResponse()
print("Rcvd: <<< " + response)
return response
def do(command) :
return doCommand(command)
do("SelectTracks: Track=0 TrackCount=1 Mode=Set")
do("SelTrackStartToEnd")
#do("NyquistPrompt: Command=\"(get '*selection* 'rms)\" Version=4")
do("MeasureRms:")