.metajson lyrics extract missing syllables

• May 25, 2021 - 00:51

The lyrics extract in the .metajson files generated by MuseScore 3 is missing syllables (usually when they fall on the second note of a tie, or possibly (not tested) on a rest).

I wrote this small XSLT transform (plus tiny sed cleanup script for some special characters) as shell oneliner for better lyrics extract (e.g. for uploading to free-scores.com):

fn='/path/to/filename.mscx' # must be mscx, not mscz
 
xmlstarlet <"$fn" sel -T -t \
  -m '//*/Score' \
    -i name \
      -o '‣ Lyrics for part: ' -v name \
    --else \
      -o '‣ Lyrics:' \
    -b \
    -n \
    -m Staff \
      --var staffId=@id \
      -o 'Staff ' -v '$staffId' \
      -o ' (' -v '../Part[./Staff/@id=$staffId]/trackName' -o '):' \
      -m './/Lyrics' -s A:N:- 'concat("0", no)' \
        -i 'not(syllabic="middle" or syllabic="end")' \
          -o ' ' \
        -b \
        -c text \
      -b \
      -n \
    -b \
  -b | sed \
    -e $'s/\u00A0/ /g' \
    -e $'s/\uE550/ /g' \
    -e 's/ \{2,\}/ /g'

Hope this helps anyone!

PS: This does not handle repeats!


Comments

And here’s an XSLT 1.0 file (latest version on http://www.mirbsd.org/music/resources/xlyrics.xsl always) that extracts the lyrics in an orderly fashion into XML (per part, stave and verse): lyric-xslt.zip (PKZIP archive)

Use it as follows:

fn='/path/to/filename.mscx' # must be mscx, not mscz
 
xmlstarlet <"$fn" tr /path/to/xlyrics.xsl | sed \
    -e $'/<verse/s/\u00A0/ /g' \
    -e $'/<verse/s/\uE550/ /g' \
    -e '/<verse/s/ \{2,\}/ /g' | \
    xmlstarlet fo -e UTF-8 - >extracted-lyrics.xml

Note: both versions do not handle repeats!

In reply to by mirabilos

Apparently, some old MuseScore 2 files can miss the «syllabic»end«/syllabic» if a «syllabic»middle«/syllabic» is present; the lyrics text with the missing syllabic tag is then automatically an “end” syllabic.

The XSLT shown here does not, cannot properly, handle that. I’m fixing up those files with a different script instead.

Do you still have an unanswered question? Please log in first to post your question.