Convert Label text to LRC file

I’m using v2.3.3. I want to create CD+G file using the label information.
Is there a tool which can convert the label text file to LRC format?

Thanks in advance

I don’t know of any ready made tools for converting labels to LRC.

If you export the label track (see: https://manual.audacityteam.org/man/file_menu_export.html#export_labels) then you could use a spreadsheet application (such as Microsoft Excel, or LibreOffice Calc) to remove the columns that are not required for LRC and to reformat the time as hh:mm:ss.
Then export as a .TXT file. Then use a plain text editor (such as NotePad++) to do a “search and replace” to add the square brackets.

See also:
https://manual.audacityteam.org/man/importing_and_exporting_labels.html
and
https://en.wikipedia.org/wiki/LRC_(file_format)

Alternatively, if you know any programming languages such as Perl or Python, you could write a script to perform the necessary conversion.

Thanks for the response.

Yes, that was my plan. I just want to confirm what is already around and don’t want to re-invent the wheel :slight_smile: because Audacity and LRC have been around for very long time.
I might consider writing a plug-in. But I’m a newbie and have to collect information first. Is this the place I have to go?

Can I find a “Hello world” example somewhere? :slight_smile:

Of those plug-in types, writing a “Nyquist” plug-in is by far the easiest option.

IMPORTANT
Nyquist scripts and plug-ins are written in “plain text”. To write Nyquist code, you need to use a plain text editor (I recommend NotePad++ https://notepad-plus-plus.org/). Do NOT use Microsoft Word or any word processor, because these do not use plain text. Microsoft NotePad is NOT recommended as it will frequently cause strange problems due to it messing up character encoding.


We have quite a lot of information / documentation for Nyquist these days, though we are still a bit lacking in tutorials.
The “landing page” for Audacity’s Nyquist documentation is this page in the Audacity manual: Nyquist - Audacity Manual
There’s a list of reference documents here: Manuals and reference material (If you are interested in working with Nyquist, it’s worth bookmarking the links in that post).

At it’s simplest, Nyquist can be run in the “Nyquist Prompt” Nyquist Prompt - Audacity Manual
The simplest form of “Hello World” using the Nyquist Prompt is simply:

(print "Hello World")

The Nyquist Prompt is very handy for testing code and for running short snippets of code, but for more complex scripts, and for usability, there are advantages in creating a self-contained Nyquist plug-in that may be installed in Audacity.

A Nyquist plug-in is simply a plain text file, that begins with some “header” commands, followed by the Nyquist code. The “header” commands tell Audacity that the text file is a Nyquist plug-in, the name of the plug-in, the type of plug-in, and what controls (“widgets”) are required in the plug-in’s GUI (if any). If a GUI is defined in the header, then Audacity creates the plug-in GUI, and passes the values from the GUI to Nyquist. More details here: Missing features - Audacity Support

A simple “Hello World” Nyquist plug-in:

;nyquist plug-in
;version 4
;type tool
;name "Hello World"
;copyright "Released under terms of the GNU General Public License version 2"

(print "Hello World")

When installed, the above plug-in will appear in the “Tools” menu as “Hello World”.


A simple “Hello World” plug-in with a GUI:

;nyquist plug-in
;version 4
;type tool
;name "Hello World GUI"
;copyright "Released under terms of the GNU General Public License version 2"

;control text "Enter text" string "" "Hello World"
(print text)

As this is a bit tricky for a first Nyquist program, here’s some code to help you along. It is not a full plug-in, but it can be run in the Nyquist Prompt and I think it will do most of what you want.

;type tool
;debugflags trace

;; Format time (seconds) as mm:ss.xx
(defun time-format (sec)
  (let* ((seconds (truncate sec))
         (mm (truncate (/ seconds 60)))
         (ss (rem seconds 60))
         (xx (round (* (- sec seconds) 100))))
    (format nil "~a:~a.~a" (pad mm) (pad ss) (pad xx))))

;; Reurn number as string with at least 2 digits
(defun pad (num)
  (format nil "~a~a" (if (< num 10) 0 "") num))

;; Get labels from first label track
(let ((labels (second (first (aud-get-info "labels")))))
  (dolist (label labels)
    (setf time (time-format (first label)))
    (format t "[~a] : ~s~%" time (third label))))

(format nil "Click OK to view LRC.")

Thank you so much. That’s a lot of information. I’ll try to work on that.

Great! You basically have done all the work :laughing: Thank you so much!
I have now updated the output format a little to be able to feed the file to KarLyricEditor where I can then export to CD+G etc.

;type tool
;debugflags trace

;; Format time (seconds) as mm:ss.xx
(defun time-format (sec)
  (let* ((seconds (truncate sec))
         (mm (truncate (/ seconds 60)))
         (ss (rem seconds 60))
         (xx (round (* (- sec seconds) 100))))
    (format nil "~a:~a.~a" (pad mm) (pad ss) (pad xx))))

;; Reurn number as string with at least 2 digits
(defun pad (num)
  (format nil "~a~a" (if (< num 10) 0 "") num))

;; Get labels from first label track
( format t "[ti:]~%[ar:]")
(let ((labels (second (first (aud-get-info "labels")))))
  (dolist (label labels)
    (setf timeS (time-format (first label)))
    (setf timeE (time-format (second label)))
;;    (format t "[~a] : ~s~%" time (third label))))
    (format t (if (string= (third label) "^") "~%[~a]" "<~a>~a<~a>") timeS (third label) timeE)))

(format nil "Click OK to view LRC.")

Need one more thing…
How do I popup a dialog and allow user to save the output to a file?

If the plug-in defines one or more “widgets” (GUI controls), then a GUI is created. See: Missing features - Audacity Support

The “File button widget” is the most complex and difficult to use of all the Nyquist plug-in widgets. See:

and

Thank you for all the links. I’m going to work on that.

I got stuck. I tried to google a solution without success :frowning:
I added following piece of code:

;control fName "Select file" file "" "*default*/karaoke.lrc" "LyRiCs|*.lrc;*.LRC|All files|*.*;*" "save,overwrite"
(format nil "Export LRC to ~s" fName)
(with-open-file(str fName :direction :output :if-exists :supersede :if-does-not-exist :create)
  (format str "write anything ~%"))

I’m testing with writing a single line and received:

error: unbound function - WITH-OPEN-FILE
if continued: try evaluating symbol again
1>

Not sure what this message means. I was only able to find information about “unbound variables”.
I also tried with a fixed path.

Where did that come from?


That means that the function “with-open-file” is unknown. It’s not a valid function name.
The function you need for opening a file is “open”. See: XLISP open

All good now. Thank you so much for your time.

This is a macro in Lisp because I googled for Lisp commands :smiley:

Although Nyquist is a form of Lisp, it is based on a very small version of Lisp called XLisp. Other, bigger versions of Lisp (such as “Common Lisp”) have many language features that are not part of XLisp.

The XLisp manual is here: https://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-index.htm
The part of the XLisp manual that you will use most frequently is the Language Reference: https://www.audacity-forum.de/download/edgar/nyquist/nyquist-doc/xlisp/xlisp-ref/xlisp-ref-index.htm

Virtually all XLisp commands are valid in Nyquist. The (very few) XLisp commands that don’t work in Nyquist are noted to that effect.
The XLisp manual is particularly helpful as it includes lots of examples.

Nyquist also has additional command that aren’t part of XLisp. These are nearly all audio related functions, and can be found in the Nyquist Index: https://www.cs.cmu.edu/~rbd/doc/nyquist/indx.html

Thank you so much, Steve.
I’ve bookmarked this thread. I’m sure I’ll revisit all these information.

Sorry, I have to come back and ask for help again :slight_smile: I did try to google and couldn’t find any usable results.
My plug-in is now working, but it can’t handle Unicode. How can I make it write Unicode file?

(setq f (open fName :direction :output :if-exists :supersede))
*snip*
    (format f (if (string= (third label) "^") "~%[~a]" "<~a>~a<~a>") timeS (third label) timeE)))
(close f)

I can see Export Labels have no problems in Unicode. I also tried to locate that plug-in without success. Is Export Labels a plug-in?

Nyquist doesn’t support Unicode, only ASCII.
If you really must have Unicode support, then it may be possible to use read-byte and write-byte, but there are lots of ways that the code can trip up with Unicode.

Does that mean when I retrieve the label (using Nyquist) the dual-byte information already lost? Which means I have no chance to write the unicode to a binary file. Is that correct?

I had to check. The answer is yes. The “aud-get-info” command returns ASCII characters. Audacity converts multi-byte character to underscore (“_”) before sending the data to Nyquist.

Yes, I got underscores in my files.

That means I’ve no chance of building an unicode plug-in. Okay, then I need a plan B… :smiley:
I can write a separate program to convert the exported label file to LRC. Is it possible to write a kind of macro to export the labels and then execute my converter? So the user can do all these in one step.

You can get multi-byte characters from labels using “GetInfo: Type=Labels Format=JSON” via Python.
See here for the latest information about scripting with Python: https://alphamanual.audacityteam.org/man/Scripting
(That is actually the manual for Audacity 2.4.0, which is not yet released, but it’s more up to date than the equivalent page in the 2.3.3 manual).