I needed to build a plugin that makes sure every time I export audio it exports as stereo. For example if there is a project without a stereo track, I needed to add an empty stereo track before exporting, so the output file is stereo. The plugin also helps me to pre-set my preferred settings - MP3 256kbps CBR. But these can be changed in the Export Audio dialog. The plugin will always show the dialog, so you can select the location, set the name and format.
Here it is. Feel free to download and adjust according to your specific need. This was created in Audacity 2.4.2. I am afraid that it needs to be updated to work for 3.x, because of the different “macro-output” path declaration. Export Stereo Audio.ny (2.07 KB)
(v2; Updated: 2022/09/06)
I have overcome the ASCII limitation by generating an ASCII stamp for a project name. That stamp is stored in the directory macro-output along with the empty MP3 file. The empty MP3 file is necessary to create so Audacity is forced to show the Export dialogue when running the export command second time. And the stamp gives a solid confirmation if the fake MP3 exist or not. It is not possible to check this directly because of possible unicode characters in the project names.
Also I am using (setdir “.”) to set the working directory (the project location) as the export path. I do not know why, but this allows to set a path even it contains the unicode characters.
There is only one last thing that I wish to implement - clean up at the end. Is there a way within Nyquist plugin to delete the folder macro-output or at least its content? The only possible solution what I see is to adjust export settings in preferences, so when I run export it calls (external program) and there would be a powershell command that removes the macro-output folder. I have already went through this path and it really works nicely. But still this is a workaround, so I would prefer to use a real solution if possible within Nyquist plugin.
Nyquist plugin can use SetPreference: to set ExternalProgramExportCommand and Export/Format values. Then again in the same plugin, you call Export:. It will use the command(s) that you set.
I have just discovered that (setdir “.”) does not give me always the project location.
Is there a way to get the project location path? It is important that it supports unicode. Alphabet of many languages does not consist from ASCII characters.
I want to set this Export/Path the project directory. Is it possible?
If you know PowerShell well, and since PowerShell supports “named pipes”, you could run the entire thing with PowerShell and not use Nyquist at all.
If you enable “mod-script-pipe” in “Preferences > Modules” (and then restart Audacity), macro scripting commands can be sent via “named pipes” to Audacity from an external program.
The next option is imperfect, but avoids wasting disk space…
Your question:
Is there a way within Nyquist plugin to delete the folder macro-output or at least its content?
In short, no. The Audacity developers thought that the security implications of allowing Nyquist to use system commands was too dangerous (malware plug-ins, or just accidentally wrecking your OS).
(let ((fp (open path-to-file :direction :output)))
(when fp ;True if "path-to-file" could be opened for writing.
(format fp "") ;Overwrite the file with an empty string.
(close fp)))
The result is that the file “path-to-file” is replaced with a new, zero byte file with the original file name.
The final option that comes to mind is to ensure that the macro-output directory is located in a system “temp” directory. Well behaved operating systems automatically clear out their temp folder periodically (most Linux distributions use “/tmp” and clear it on reboot). I’m not sure what Windows does, but hopefully it does clear its Temp folder occasionally.