3

I want to add synced lyrics from vtt on my mp3 file using python. I tried using the mutagen module but it didn't work as intended.

from mutagen.id3 import ID3, USLT, SLT
import sys
import webvtt

lyrics = webvtt.read(sys.argv[2])
lyri = []
lyr = []
for lyric in lyrics:
    times = [int(x) for x in lyric.start.replace(".", ":").split(":")]
    ms = times[-1]+1000*times[-2]+1000*60*times[-3]+1000*60*60*times[-4]
    lyri.append((lyric.text,ms))
    lyr.append(lyric.text)
fil = ID3(sys.argv[1])
tag = USLT(encoding=3, lang='kor', text="\n".join(lyr)) # this is unsynced lyrics
#tag = SLT(encoding=3, lang='kor', format=2, type=1, text=lyri) --- not working
print(tag)
fil.add(tag)
fil.save(v1=0)

How can I solve this problem?

doohee
  • 33
  • 3
  • Have you reached a solution since? I would be happy if you share. – Adiel Jul 20 '22 at 12:56
  • Interested in that application too. Please keep me posted if this is offered as a user application (CLI or GUI). – porg Nov 24 '22 at 15:15

2 Answers2

3

I use mutagen to parse an mp3 file that already has SYLT data, and found the usage of SYLT:

from mutagen.id3 import ID3, SYLT, Encoding

tag = ID3(mp3path)
sync_lrc = [("Do you know what's worth fighting for", 17640), 
            ("When it's not worth dying for?", 23640), ...]  # [(lrc, millisecond), ]
tag.setall("SYLT", [SYLT(encoding=Encoding.UTF8, lang='eng', format=2, type=1, text=sync_lrc)])
tag.save(v2_version=3)

But I can't figure out format=2, type=1 means.

WangWeimin
  • 116
  • 5
2

check https://id3.org/id3v2.3.0#Synchronised_lyrics.2Ftext

  • format 1: Absolute time, 32 bit sized, using MPEG frames as unit

  • format 2: Absolute time, 32 bit sized, using milliseconds as unit

  • type 0: is other

  • type 1: is lyrics

  • type 2 : is text transcription

  • type 3 : is movement/part name (e.g. "Adagio")

  • type 4 : is events (e.g. "Don Quijote enters the stage")

  • type 5 : is chord (e.g. "Bb F Fsus")

  • type 6 : is trivia/'pop up' information

The247
  • 59
  • 3