展示HN:TagLib-WASM – 在所有JavaScript运行时中读取/写入音频元数据

1作者: CharlesW3 个月前原帖
TagLib-Wasm 是一个将 C++ TagLib 库的 WebAssembly 版本封装为 TypeScript/JavaScript API 的工具,使您能够使用 Deno、Node.js、Bun、Electron、Cloudflare Workers 或浏览器读取和写入 MP3、FLAC、M4A、OGG、WAV 及其他音频文件格式的元数据。 ```javascript import { readTags, updateTags } from "taglib-wasm/simple"; const tags = await readTags("song.flac"); console.log(tags.title, tags.artist, tags.album); await updateTags("song.flac", { title: "New Title", artist: "New Artist" }); ``` 我开发 TagLib-Wasm 是因为 JavaScript 生态系统中缺乏一个完整的跨格式音乐元数据库。现有的选项要么仅支持 MP3,要么需要本地二进制文件,或者无法写入标签。TagLib 本身经过严格测试(它为 VLC、Kodi、Strawberry 等提供支持),但没有 Wasm 构建版本。 在服务器运行时(Deno、Node.js、Bun)中,它会自动选择一个支持快速高效基于查找的 I/O 的 WASI 后端。在浏览器中,它使用 Emscripten 进行全缓冲 I/O。无需任何配置。 这是第一个 1.0 版本的测试版。我非常欢迎您对 API 设计/开发体验、缺失的格式/功能以及我未考虑到的使用案例提供反馈。 [https://charleswiltgen.github.io/taglib-wasm/](https://charleswiltgen.github.io/taglib-wasm/)
查看原文
TagLib-Wasm wraps a WebAssembly version of the C++ TagLib library in a TypeScript&#x2F;JavaScript API so you can read and write metadata for MP3, FLAC, M4A, OGG, WAV, and other audio file formats using Deno, Node.js, Bun, Electron, Cloudflare Workers, or browsers.<p><pre><code> import { readTags, updateTags } from &quot;taglib-wasm&#x2F;simple&quot;; const tags = await readTags(&quot;song.flac&quot;); console.log(tags.title, tags.artist, tags.album); await updateTags(&quot;song.flac&quot;, { title: &quot;New Title&quot;, artist: &quot;New Artist&quot; }); </code></pre> I built TagLib-Wasm because the JS ecosystem had no complete, cross-format music metadata library. Existing options either only supported MP3, required native binaries, or couldn&#x27;t write tags. TagLib itself is battle-tested (it powers VLC, Kodi, Strawberry, and others), but had no Wasm build.<p>On server runtimes (Deno, Node.js, Bun), it auto-selects a WASI backend that does fast and efficient seek-based I&#x2F;O. In browsers, it uses Emscripten with full-buffer I&#x2F;O. No configuration is needed.<p>This is the first 1.0 beta. I&#x27;d appreciate any feedback on the API design&#x2F;DX, missing formats&#x2F;features, and use cases I haven&#x27;t thought of.<p><a href="https:&#x2F;&#x2F;charleswiltgen.github.io&#x2F;taglib-wasm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;charleswiltgen.github.io&#x2F;taglib-wasm&#x2F;</a>