Convert Label text to LRC file
Forum rules
This forum is for Audacity on Windows.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Please state which version of Windows you are using,
and the exact three-section version number of Audacity from "Help menu > About Audacity".
Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
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
Is there a tool which can convert the label text file to LRC format?
Thanks in advance
Re: Convert Label text to LRC file
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.
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Convert Label text to LRC file
Thanks for the response.
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?
Yes, that was my plan. I just want to confirm what is already around and don't want to re-invent the wheel
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
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).
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")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")
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)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Convert Label text to LRC file
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.")
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Convert Label text to LRC file
Thank you so much. That's a lot of information. I'll try to work on that.
Re: Convert Label text to LRC file
Great! You basically have done all the work
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.")
How do I popup a dialog and allow user to save the output to a file?
Re: Convert Label text to LRC 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
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
Re: Convert Label text to LRC file
Thank you for all the links. I'm going to work on that.
Re: Convert Label text to LRC file
I got stuck. I tried to google a solution without success
I added following piece of code:
I'm testing with writing a single line and received:
Not sure what this message means. I was only able to find information about "unbound variables".
I also tried with a fixed path.
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 ~%"))
Code: Select all
error: unbound function - WITH-OPEN-FILE
if continued: try evaluating symbol again
1>I also tried with a fixed path.