News:

LATEST RELEASE:  FPP 6.1 - Download from here - https://github.com/FalconChristmas/fpp/releases/tag/6.1

+-+-

+-User

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+-Site Stats

Members
Total Members: 15497
Latest: packhawk
New This Month: 5
New This Week: 33
New Today: 5
Stats
Total Posts: 127092
Total Topics: 15590
Most Online Today: 98
Most Online Ever: 7634
(January 21, 2020, 02:14:03 AM)
Users Online
Members: 2
Guests: 49
Total: 51

Problem with python script to generate xtiming lyric track

Started by Nburlarley, August 18, 2021, 01:16:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nburlarley

I found this piece of python code from this website here: auto-lyrics · PyPI . What it basically does is take a JSON file with a timing track, and converts it into a XTIMING file to import into xlights. To get the JSON file, it takes you to this website: AutoLyrixAlign (hltnus.org) , and has you upload a mp3 file, then all the lyrics that goes with it. It then loads for about 2 - 5 minutes, then gives you a JSON file with all the lyrics perfectly aligned. I think there was like only 5 words out of a 4 and a half minute song that weren't right. So what the python code does is converts the JSON file into a XTIMING file so you can import it into xlights to have a full lyric track. So first it says to open the command line, and run this code: 

pip install auto-lyrics

So I did and it surprisingly installed it. Then it says run this code: 

Lyrics - t "(name for output file here)" (directory to json file) (name for xtiming file).xtiming

So when I fill in the blank it looks like this for me:

lyrics -t "Christmas-wrapping-timing" C:\Users\Nicholas\Downloads\lyrix_1108627773.txt twXmasWrapping.xtiming

So I ran that and it gave me some output code (you can see it here), but then after that, it gave me this error code and did nothing. I have no idea what it means and I'm a noob when it comes to python. If someone familiar with python could help, that would be great. I'm really behind on sequencing, and I thought doing auto lyrics for my singing faces will save days or even weeks of programming. Thanks in advanced.

Here is the website with the instructions: auto-lyrics · PyPI

Here is the actual python code: 

from typing import List
import click
import json
from json import JSONEncoder
from jinja2 import Environment, FileSystemLoader
class InvalidTimingException(Exception):
    """Raised when an Lyric start time occurs before its end time."""
    pass
class Timing:
    def __init__(self, track_title, raw_timings):
        wordlist = []
        toplevel = []
        for sublist in raw_timings:
            if not sublist:
                continue
            toplevel.append(Lyric.from_raw_list(sublist))
            for item in sublist:
                wordlist.append(Lyric.from_json(item))
        self.title = track_title
        self.effect_layers = [toplevel, wordlist]
    def __repr__(self):
        return f"Timing(title={self.title}, effect_layers={self.effect_layers})"
    def build_template(self):
        file_loader = FileSystemLoader('templates')
        env = Environment(loader=file_loader)
        template = env.get_template('xtiming.jinja')
        return template.render(data=self)
    def reprJSON(self):
        return dict(ttle=self.title, effect_layers=self.effect_layers)
class Lyric:
    def __init__(self, start, end, text):
        self.word = text
        starttime = self._to_millis(start)
        endtime = self._to_millis(end)
        self.starttime = starttime
        if starttime <= endtime:
            self.endtime = endtime
        else:
            raise InvalidTimingException("Expected a start time to occur before the end time")
    def _to_millis(self, timing):
        if isinstance(timing, str):
            try:
                return round(float(timing) * 1000)
            except Exception as e:
                print("Something bad happened")
                print(type(e).__name__)
                print(e.args)
        else:
            raise TypeError(f"Expected float as a string, got {type(timing)}")
    @classmethod
    def from_json(cls, data):
        return cls(**data)
    @classmethod
    def from_raw_list(cls, data: List):
        start = data
  • ['start']
        end = data[len(data)-1]['end']
        words = " ".join(list(map(lambda w: w['text'], data)))
        return cls(start, end, words)
    def reprJSON(self):
        return dict(starttime=self.starttime, endtime=self.endtime, word=self.word)
    def __repr__(self):
        return f"Lyric(start={self.starttime}, end={self.endtime}, word={self.word})"
class TimingEncoder(JSONEncoder):
    def default(self, object):
        if hasattr(object, "reprJSON"):
            return object.reprJSON()
        else:
            return json.JSONEncoder.default(self, object)
@click.command()
@click.argument("input", type=click.File("rb"))
@click.argument("output", type=click.File("wb"))
@click.option("-t", "--title", default="Xlights Auto Lyrics", help="Name of the music track")
def cli(input, output, title):
    """This command takes in a Json file from https://autolyrixalign.hltnus.org/ & produces an xtimng file
    Example using this function:
    lyrics -t "Merry Chrstmas Everybody" slade_timing.txt slade.xtiming
    """
    while True:
        raw = input.read()
        if not raw:
            break
        tm = Timing(title, json.loads(raw))
        text = tm.build_template()
        bytes = text.encode()
        output.write(bytes)
        output.flush()
if __name__ == '__main__':
    cli()

AAH

I spotted this thread earlier and had a look at the site and posted it around a bit.
Long story short Phil Littlewood created a notepad++ macro to do the conversion and put up a video explaining the process. He has also linked to the macro from the youtube page.


Nburlarley

Thanks, that video really helped. I'm gonna go try it, hopefully it works!

Nburlarley

I did what the video said and had everything work all the way up until notepad ++. When I put in the macro code for it to create the "create lyrics" button, and save and restart the program, the button doesn't show up. So I left a comment on his video asking what I did wrong, so hopefully he'll respond and I can fix that.

TNF250

Can you attach your shortcuts.xml file or a screen shot of the file. If you missed just one of the characters it will not show up.
Zane
Springfield, TN

X-Lights - RPi3 - FPP - Falcon - DLA Lynx

Nburlarley


Support FPP

+- Recent Topics

Think I found a bug/corner case...please help by breese
Today at 06:39:36 AM

Fpp 6.2 ui password by Mat-Moo
Today at 01:31:11 AM

Controller not keeping accurate time by jnealand
December 01, 2022, 09:38:16 PM

Raspberry PI 4 won't connect to WIFI by Poporacer
December 01, 2022, 07:28:48 PM

BRP Voting Plugin - Allow others to vote for your songs! by Barkers Random Projects
December 01, 2022, 07:20:53 PM

All pixels group ON effect by tkelba
December 01, 2022, 06:48:00 PM

FPP 6.2 Playlist/FPP Command/Run Script vs. Playlist/Script by richardln2
December 01, 2022, 06:16:19 PM

Help--Can't Get Sequence to Output by Oxytousc
December 01, 2022, 05:07:12 PM

Set Time/Date by breese
December 01, 2022, 04:07:57 PM

Differential Receiver Board Ports w/ F48 corrupted data by tkelba
December 01, 2022, 02:58:25 PM

Powered by EzPortal
Powered by SMFPacks Menu Editor Mod