Import Labels

Audacity has the ability to export label tracks as a text file, and/or import labels from a text file. More information about this is available in the Audacity manual. A limitation of this feature is that it is not available to use in batch processing. There is a macro command ImportLabels: but it only opens the file selection window where you can choose which file to import – it doesn’t actually do the import without manual interaction. Perhaps Nyquist can come to the rescue…

With Nyquist, we can open a file and read it as text, and we can generate labels with a specially crafted list, so it looks like this should be possible, but with a few limitations.

Limitations

  1. Nyquist does not support Unicode.
    (Partial support may be added in the future, but it is unlikely that Unicode will ever be fully supported).
    If the label text file contains multi-byte characters, attempting to import with Nyquist will probably fail in an unpredictable manner.
  2. Nyquist is currently unable to create labels with frequency ranges, though there is a feature request logged for this. For now, the plug-in will just ignore the frequency properties if present in the file.

Parsing the Label Text file

This is possibly the most difficult part of this plug-in. We can easily read the text file, but we need to interpret numbers as numbers, and the label text needs to be “quoted” so that Nyquist will treat it as a string value. In this function, you should notice:

  1. We step through the line of text, character by character.
  2. We know that in a properly formed Label Text file, the first two parts are numbers, and the third part is the label text. The parts are separated by tab characters.

The plug-in:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.