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:

2 thoughts on “Import Labels”

  1. I realized a difficulty with ImportLabels.ny: When there are quotes ” in the label, this causes the import to fail. Would it be possible to allow for double/single quotes in label texts?

    1. > Would it be possible to allow for double/single quotes in label texts?

      Yes, I expect it would be possible, but I’m not sure it is worth the effort. The Nyquist scripting language is designed for working with sound and MIDI, and is not a good language for working with text / strings. It has many shortcomings in this respect, including no support for Unicode.

      I would not generally recommend using quotes in label names, so I will not be adding that as a standard feature of this plug-in. If you want to add quote support for your own version, one approach would be to pre-process the data as it is read, so that you can prepend quotes with a backslash (the escape character).

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.