Page 1 of 8

Convert Label text to LRC file

Posted: Sat Feb 08, 2020 6:36 am
by bigboss97
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

Re: Convert Label text to LRC file

Posted: Sat Feb 08, 2020 10:01 pm
by steve
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/fil ... ort_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/imp ... abels.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.

Re: Convert Label text to LRC file

Posted: Sun Feb 09, 2020 1:10 am
by bigboss97
Thanks for the response.
steve wrote:
Sat Feb 08, 2020 10:01 pm
Alternatively, if you know any programming languages such as Perl or Python, you could write a script to perform the necessary conversion.
Yes, that was my plan. I just want to confirm what is already around and don't want to re-invent the wheel :-) 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?
https://wiki.audacityteam.org/wiki/Crea ... wn_Plug-in
Can I find a "Hello world" example somewhere? :-)

Re: Convert Label text to LRC file

Posted: Sun Feb 09, 2020 11:48 am
by steve
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: https://manual.audacityteam.org/man/nyquist.html
There's a list of reference documents here: viewtopic.php?f=39&t=77214 (If you are interested in working with Nyquist, it's worth bookmarking the links in that post).
bigboss97 wrote:
Sun Feb 09, 2020 1:10 am
Can I find a "Hello world" example somewhere?
At it's simplest, Nyquist can be run in the "Nyquist Prompt" https://manual.audacityteam.org/man/nyquist_prompt.html
The simplest form of "Hello World" using the Nyquist Prompt is simply:

Code: Select all

(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: https://wiki.audacityteam.org/wiki/Nyqu ... _Reference

A simple "Hello World" Nyquist plug-in:

Code: Select all

;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:

Code: Select all

;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)


Re: Convert Label text to LRC file

Posted: Sun Feb 09, 2020 5:37 pm
by steve
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.

Code: Select all

;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.")


Re: Convert Label text to LRC file

Posted: Sun Feb 09, 2020 11:30 pm
by bigboss97
Thank you so much. That's a lot of information. I'll try to work on that.

Re: Convert Label text to LRC file

Posted: Tue Feb 11, 2020 3:19 am
by bigboss97
steve wrote:
Sun Feb 09, 2020 5:37 pm
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.
Great! You basically have done all the work :lol: 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.

Code: Select all

;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?

Re: Convert Label text to LRC file

Posted: Tue Feb 11, 2020 9:03 am
by steve
bigboss97 wrote:
Tue Feb 11, 2020 3:19 am
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: https://wiki.audacityteam.org/wiki/Nyqu ... ce#widgets

The "File button widget" is the most complex and difficult to use of all the Nyquist plug-in widgets. See:
https://wiki.audacityteam.org/wiki/Nyqu ... ton_Widget
and
https://wiki.audacityteam.org/wiki/Nyqu ... n_Tutorial

Re: Convert Label text to LRC file

Posted: Tue Feb 11, 2020 11:16 pm
by bigboss97
Thank you for all the links. I'm going to work on that.

Re: Convert Label text to LRC file

Posted: Wed Feb 12, 2020 6:20 am
by bigboss97
I got stuck. I tried to google a solution without success :(
I added following piece of code:

Code: Select all

;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:

Code: Select all

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.