User guide7 min read

KMID & KLyr XML Specification: Embedded MIDI Karaoke Lyrics

Comprehensive technical guide for KMID / KLyr format, Meta Event 0x01 extraction, Base64/zlib decompression, and XML schema (, , , ).

1. What is KMID / KLyr Format?

KMID (KAR / KLyr Embedded Format) is an advanced karaoke file specification that embeds song metadata, key signatures, and word-level XML lyric timing directly inside a standard MIDI (.mid) binary file. Unlike legacy 3-file NCN systems (.mid + .lyr + .cur), KMID packages everything into a single self-contained binary file, preventing missing lyric or sync errors during distribution.

2. Binary Extraction & Decompression Pipeline

Inside the MIDI track stream, KLyr data is stored within a Meta Text Event (Meta Type 0x01). The extraction and decoding pipeline follows four strict steps:

Extraction Steps

  1. 1
    1. Header Matching: Search Meta Type 0x01 text events for the header identifier prefix KLyrHdr1 (or K1LyrHdr).
  2. 2
    2. Base64 Decoding: Extract the encoded string payload following the header and decode it into a binary Uint8Array buffer.
  3. 3
    3. zlib/pako Inflation: Decompress the binary payload using zlib inflation algorithm (pako.inflate) to obtain raw XML bytes.
  4. 4
    4. Charset Decoding (Windows-874): Decode XML bytes using Windows-874 / TIS-620 encoding to accurately preserve Thai vowels and tone marks.

3. Decompressed KLyr XML Schema Structure

The decompressed XML document contains two primary parent blocks: <INFO> for global song metadata and <LYRIC> for the line/word timing stream:

Decompressed KLyr XML Document Template

Decompressed KLyr XML Document Template

terminal
<?xml version="1.0" encoding="TIS-620"?>
<SONG>
  <INFO>
    <VERSION>1.1</VERSION>
    <TITLE>ชื่อเพลง</TITLE>
    <ARTIST>ชื่อศิลปิน</ARTIST>
    <ARTIST_TYPE>M</ARTIST_TYPE> <!-- M: ชาย, F: หญิง, MF: ร้องคู่ -->
    <KEY>Cm</KEY>
    <TEMPO>120</TEMPO>
    <ALBUM>ชื่ออัลบั้ม</ALBUM>
    <AUTHOR>ผู้แต่งคำร้อง/ทำนอง</AUTHOR>
    <GENRE>Pop</GENRE>
    <RHYTHM>Disco</RHYTHM>
    <CREATOR>NEXT_SYSTEM</CREATOR>
    <COMPANY>ค่ายเพลง</COMPANY>
    <LANGUAGE>THAI</LANGUAGE>
    <YEAR>2026</YEAR>
    <VOCAL_CHANNEL>9</VOCAL_CHANNEL>
  </INFO>
  <LYRIC>
    <LINE>
      <WORD>
        <TIME>1920</TIME>
        <TEXT>เนื้อ</TEXT>
        <VOCAL>M</VOCAL>
      </WORD>
      <WORD>
        <TIME>2160</TIME>
        <TEXT>ร้อง</TEXT>
        <VOCAL>M</VOCAL>
      </WORD>
    </LINE>
  </LYRIC>
</SONG>

4. Detailed Element Reference: <INFO> & <LYRIC>

Below is the technical specification of each XML element inside <INFO> and <LYRIC>:

<INFO> Node Element Reference

Identification
<TITLE> & <ARTIST>

Stores song title and lead artist name. Supports full Thai/English Unicode characters.

Music Theory
<KEY> & <TEMPO>

Defines default musical key (e.g. C, Cm, Dm, F#m) and tempo BPM. Allows player to display key and calculate transpositions.

Vocal Assignment
<ARTIST_TYPE> & <VOCAL_CHANNEL>

ARTISTTYPE defines M (Male), F (Female), or MF (Duet). VOCALCHANNEL specifies the guide vocal track (e.g., 9 for Drum/Guide channel).

<LYRIC>, <LINE>, and <WORD> Node Specification

  1. 1
    <LINE>: Groups words belonging to a single song verse line on screen.
  2. 2
    <WORD> -> <TIME>: Syllable start time stored in 24 PPQ reference ticks. Converted to real MIDI ticks using formula: realTick = Math.round((time * ticksPerBeat) / 24).
  3. 3
    <WORD> -> <TEXT>: Syllable character string (e.g. 'รัก', 'เธอ', ' Heart').
  4. 4
    <WORD> -> <VOCAL>: Optional vocal gender per word (M/F). Enables duet karaoke players to dynamically change font highlight colors (e.g. Blue for Male, Pink for Female) word-by-word!