Export individual label when multiple labels in project

Share your Audacity/Nyquist plug-ins here, or test drive the latest plug-ins submitted by Audacity users.

After testing a plug-in from this forum, please post feedback for the plug-in author.
agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Sun Oct 04, 2020 7:08 pm

Thanks a lot again, Steve, for your great help. It now works as I wanted.
If you think by any chance this plugin may help others, let me know and how to post it on audacity site.
Best regards,
Paul

steve
Site Admin
Posts: 81239
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Export individual label when multiple labels in project

Post by steve » Sun Oct 04, 2020 7:11 pm

agua wrote:
Sun Oct 04, 2020 7:08 pm
If you think by any chance this plugin may help others, let me know and how to post it on audacity site.
Please do post it here, and I'll move this topic to the Nyquist Plug-ins forum board.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

agua
Posts: 117
Joined: Wed Mar 14, 2018 3:15 am
Operating System: Windows 7

Re: Export individual label when multiple labels in project

Post by agua » Mon Oct 05, 2020 4:07 am

Here it is :

Code: Select all

;nyquist plug-in
;version 1
;type tool
;name "ExportLabelTrack"

(setq slash (format nil "~a" *file-separator*)) 
(setq ch #\tab)
(setq *float-format* "%#1.6f")

(defun home ()
  (strcat "C:" slash "TMP")); customized
(setq savepath (string-right-trim slash (home)))

(defun get-selected-label-tracks ()
  ;; Returns a list of selected label tracks as (list (list ID TrackName) ...)
  (let ((tracks (aud-get-info "Tracks"))
         (tracklist ())
         (id 0)
         trackname
         selected
         is-label)
    (dolist (track tracks tracklist)
      ;; Get name if a selected label track
      (dolist (e track)
        (let ((tn (member 'NAME e))
              (sel (member 'SELECTED e))
              (kind (member 'KIND e)))
        (when tn
          (setf trackname (second tn)))
        (when sel
          (setf selected (second sel)))
        (when kind
          (setf is-label (string-equal (second kind) "label")))))
      ;; If selected label track found, push it to the tracklist.
      (when (and trackname selected is-label)
		(if (= selected 1)
         (push (list id trackname) tracklist))
        (incf id)); index (0-based) relative to label track (only) list
      ;(incf id); index (0-based) relative to all tracks (audio and labels)
	)))
(setf selected-label-track (first (get-selected-label-tracks))); grab first of the possibly several selected label tracks only

(if (first selected-label-track)
 (progn
  ;(format nil "~a" selected-label-track); display this track
  (setf selected-label-track-id (first selected-label-track)); get its track id (relative to label track (only) list)
  ;(format nil "~a" selected-label-track-id); display this track id
  (setf selected-label-track-name (second selected-label-track)); get its track name
  ;(format nil "~a" selected-label-track-name); display this track name
  (setf selected-label-track-content (second (nth selected-label-track-id (aud-get-info "labels")))); get its track content
  ;(format nil "~a" selected-label-track-content); display this content
  
  ; Write data to label track name named outputfile in fixed save path location
  (setq outputfile (format nil "~a~a~a (labels).txt" savepath slash selected-label-track-name))
  (setf file-pointer (open outputfile :direction :output));
  (dolist (line selected-label-track-content)
   (format file-pointer (format nil "~a~a~a~a~a~%" (first line) ch (second line) ch (third line)))
  )
  (close file-pointer)
  (format nil "Label track  id = ~a, name = ~a~%has been exported to the file named: ~%~a" selected-label-track-id selected-label-track-name outputfile); display all data+filename
 )
 (print "No LABEL TRACK selected.  Please select ONE first.")
)
Thanks again to you for this, Steve.

Winand
Posts: 10
Joined: Wed Oct 21, 2020 8:35 pm
Operating System: Windows 10

Re: Export individual label when multiple labels in project

Post by Winand » Wed Oct 21, 2020 8:41 pm

Is it somehow possible to add unicode support? I get underscore symbols instread of cyrillic

steve
Site Admin
Posts: 81239
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Export individual label when multiple labels in project

Post by steve » Wed Oct 21, 2020 8:53 pm

Winand wrote:
Wed Oct 21, 2020 8:41 pm
Is it somehow possible to add unicode support? I get underscore symbols instread of cyrillic
What are you referring to? agua's plug-in?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Winand
Posts: 10
Joined: Wed Oct 21, 2020 8:35 pm
Operating System: Windows 10

Re: Export individual label when multiple labels in project

Post by Winand » Thu Oct 22, 2020 7:55 am

well.. yes. I'm not familiar with LISP and plugin development, so i don't know where to start. Is it possible?

I need to add labels to an audio track. Audacity projects take much space so I want to store original audio file and txt files with labels. If I have two label tracks I have to remove one of them, export, ctrl-z, remove another one, export, ctrl-z.

steve
Site Admin
Posts: 81239
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Export individual label when multiple labels in project

Post by steve » Thu Oct 22, 2020 8:21 am

Audacity supports Unicode but Nyquist doesn't. Nyquist expects characters to be 8 bits. Converting Nyquist to support multi-byte characters would be a very big job.
Nyquist is a programming language written by Professor Dannenberg at CMU https://www.cs.cmu.edu/~music/nyquist/ It was designed for working with sounds and MIDI rather than text, hence it has fantastic abilities for manipulating sounds, but rather limited abilities with text.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Winand
Posts: 10
Joined: Wed Oct 21, 2020 8:35 pm
Operating System: Windows 10

Re: Export individual label when multiple labels in project

Post by Winand » Sat Oct 24, 2020 9:06 pm

hmm... Completely different solution: read all labels tracks to Python script using "GetInfo: Type=Labels" scripting command and then save them individually. And there's no unicode problem.

polaritypulse
Posts: 1
Joined: Thu Feb 18, 2021 9:46 pm
Operating System: Windows 10

Re: Export individual label when multiple labels in project

Post by polaritypulse » Thu Feb 18, 2021 9:50 pm

agua, You feel my pain. I am new to Audacity and just using it to splice my language instructors audio for seperate words into labels and exporting multiple labels. Can you help me install this nyquist plug in to do this very same thing you have done? thanks

Samse26
Posts: 78
Joined: Tue Nov 27, 2018 12:05 pm
Operating System: Windows 8 or 8.1

Re: Export individual label when multiple labels in project

Post by Samse26 » Wed Apr 14, 2021 4:41 pm

[using v2.4.2]
I tried the above plugin after copying to plug-in directory and selecting one of my label tracks (clicking on "select") - but nothing happened.
From the code I assume the export should land in C:\temp, but nothing was there.
Then I loaded the code into the Nyquist prompt and ran it using "debug", which produced the following:

Code: Select all

error: bad argument type - NIL
Function: #<Subr-CLOSE: #452c868>
Arguments:
  NIL
Function: #<FSubr-PROGN: #452ee48>
Arguments:
  (SETF SELECTED-LABEL-TRACK-ID (FIRST SELECTED-LABEL-TRACK))
  (SETF SELECTED-LABEL-TRACK-NAME (SECOND SELECTED-LABEL-TRACK))
  (SETF SELECTED-LABEL-TRACK-CONTENT (SECOND (NTH SELECTED-LABEL-TRACK-ID (AUD-GET-INFO "labels"))))
  (SETQ OUTPUTFILE (FORMAT NIL "~a~a~a (labels).txt" SAVEPATH SLASH SELECTED-LABEL-TRACK-NAME))
  (SETF FILE-POINTER (OPEN OUTPUTFILE :DIRECTION :OUTPUT))
  (DOLIST (LINE SELECTED-LABEL-TRACK-CONTENT) (FORMAT FILE-POINTER (FORMAT NIL "~a~a~a~a~a~%" (FIRST LINE) CH (SECOND LINE) CH (THIRD LINE))))
  (CLOSE FILE-POINTER)
  (FORMAT NIL "Label track  id = ~a, name = ~a~%has been exported to the file named: ~%~a" SELECTED-LABEL-TRACK-ID SELECTED-LABEL-TRACK-NAME OUTPUTFILE)
Function: #<FSubr-IF: #452e4b8>
Arguments:
  (FIRST SELECTED-LABEL-TRACK)
  (PROGN (SETF SELECTED-LABEL-TRACK-ID (FIRST SELECTED-LABEL-TRACK)) (SETF SELECTED-LABEL-TRACK-NAME (SECOND SELECTED-LABEL-TRACK)) (SETF SELECTED-LABEL-TRACK-CONTENT (SECOND (NTH SELECTED-LABEL-TRACK-ID (AUD-GET-INFO "labels")))) (SETQ OUTPUTFILE (FORMAT NIL "~a~a~a (labels).txt" SAVEPATH SLASH SELECTED-LABEL-TRACK-NAME)) (SETF FILE-POINTER (OPEN OUTPUTFILE :DIRECTION :OUTPUT)) (DOLIST (LINE SELECTED-LABEL-TRACK-CONTENT) (FORMAT FILE-POINTER (FORMAT NIL "~a~a~a~a~a~%" (FIRST LINE) CH (SECOND LINE) CH (THIRD LINE)))) (CLOSE FILE-POINTER) (FORMAT NIL "Label track  id = ~a, name = ~a~%has been exported to the file named: ~%~a" SELECTED-LABEL-TRACK-ID SELECTED-LABEL-TRACK-NAME OUTPUTFILE))
  (PRINT "No LABEL TRACK selected.  Please select ONE first.")
1> 
Any clue what's wrong here? From the debug output I can't even tell at what line of code it bailed out.
Thanks for any hints.
Last edited by Samse26 on Wed Apr 14, 2021 4:54 pm, edited 1 time in total.

Post Reply