How to label sounds with their duration?

I know how to produce a label track using the Tool>Label sounds… but I would like to have the text for label regions corresponding to each sound be the duration of each sound (in seconds).

Right now the only way I know how to do that is to export the labels as a label.txt file, import those values into a spreadsheet, calculate the sound durations there, and then reimport a new label.txt file with those values.

Since I need to do this a lot as part of a much larger workflow, it would be really nice if there is an easier way to do this part

Thanks

@tlm

I don’t know if it’s possible to create a Macro or script to do this automatically - but since you are doing it manually right now this a[[roach may simplify it a bit for you (avoids your calculations).

  1. Set your selection toolbar to be Start and Length of Selection, click on tthe cogwheel in the selection toolbar to get the context menu.

  2. Use your Label Sounds

  3. For each sound in turn:
    a) click on the bar under the label text to select the audio defined by the label
    b) read the length from the selection toolbar
    c) edit the label, typing in the length

This will probably be a bit quicker than exporting labels and messing around with spreadsheets.

UPDATE: I’ve just been experimenting and you can smooth this up a bit:

d) after editing hitting the label click on return to finish the edit and then click on Tab to move to the select the range of the next labelled region
on.

Peter

After benefiting from Peter’s (@waxcylinder) help, I realized there was another way to do this manually: using the Label Editor as shown in my screen recording below. Notice that I open the editor with the label I want to edit already highlighted. Then in the editor I double click on the label to type the text I see in the selection duration at lower right. And then I use tab repeatedly to advance to subsequent labels (or shift-tab to go backwards) and finally hit return to exit the editor. The labels in the label track do not update until after the editor closes.
s

I often have many labels that I want to change like this, so it will be a little tedious (after about 20) to do it this way. It would be even better if the Label Editor included a column with the label duration – and if that could be copied and pasted into the label text column.

Yes, I would prefer to have a macro or .ny script to do this. I have a lot of experience with VBA (Excel) programing and I would REALLY like to be able to control Audacity with macros like that. I’ve tried in the past to edit or make my own Audacity macros/Nyquist scripts, but have never met with much success.

It is possible to do with a Nyquist script, but with a few limitations:

  1. Nyquist cannot edit label tracks, but it can create a new label track.
  2. If the project contains multiple label tracks, there will still only be one new label track when running the script. The script below merges data from all label tracks in the project into one new label track.
  3. The new label track times are relative to the start of the selection when running the script, so it is essential to ensure that the cursor position / start of the current selection, is at “time = 0.0”.

Use the Nyquist Prompt to run the script.

Some versions of Audacity require an audio selection for Nyquist scripts to run, so I would suggest that you first click on an audio track, then press “Shift + Home” to select from the cursor position to the start of the project, and then open the Nyquist Prompt and run the script.

The original label track(s) can be deleted manually by clicking the in the top left corner of the track.

Here is the script:

;type analyze

(let ((labels (aud-get-info "Labels"))
      new-labels)
  (dolist (label-track labels)
    (dolist (label (second label-track))
      (psetq start (first label)
             end (second label))
      (push (list start
                  end
                  (format nil "~a" (- end start)))
            new-labels)))
  new-labels)

1 Like

@steve thank you – I got it working – I realized I needed to first generate a label track (when you said it can only make new label tracks I thought that meant I shouldn’t have any). But of course, it has to have labels to work with.

This is exactly what I wanted! In my screen recording I show it in action. But I confess, the code itself is a mystery. Thanks again.
s

This topic was automatically closed after 30 days. New replies are no longer allowed.