music-lyric-model
v4.0.0
Published
Music Lyric Model
Downloads
482
Readme
music-lyric-model-node
music lyric model 的 Node 綁定.
使用
從 npm 安裝:
npm install music-lyric-modelimport { Runtime, Storage, Common } from 'music-lyric-model'
// Runtime —— 解析產物.
const info = Runtime.makeInfo({ timing: Common.Proto.Timing.WORD }) // 會蓋上當前的 SCHEMA_VERSION
const bytes = Runtime.encodeInfo(info) // Uint8Array
const json = Runtime.infoToJson(info) // JSON
const back = Runtime.decodeInfo(bytes)
// 安全解包 oneof 變體, 無需手寫 guard.
const normal = Runtime.asLineNormal(back.lines[0]) // LineNormal | undefined
// getWord* 同時接受 Word 容器或裸 WordNormal.
const word = Runtime.getLineWords(back.lines[0])[0]
Runtime.getWordDuration(word) // Word
Runtime.getWordDuration(Runtime.asWordNormal(word)!) // WordNormal
// Storage —— 儲存模型.
const lyric = Storage.makeLyric()
const stored = Storage.encodeLyric(lyric)建置
環境需求
- Node.js ≥ 22
npm
安裝依賴並建置:
npm install
npm run buildnpm test 執行測試.
產生
從 proto submodule 重新產生 gen/ (需要 buf):
git submodule update --init --recursive # 拉取 proto/
npm run generatenpm run generate 串聯 generate:proto 與 generate:version.
授權
基於 MIT License 發布.
