跳到正文
DEV Community· Sia·· 1 小時前AI 評分61

Scissor Audio 的瀏覽器音訊工具使用 Whisper、LAME 和 FLAC,毋須上載檔案

Audio tools that never upload: Whisper, LAME and FLAC in the browser

AI 導讀

作者 Sia 開發的 Scissor Audio 在瀏覽器內提供 12 種音訊工具和一個編輯器,音訊處理在裝置本地完成。語音轉文字使用量化至 8 bits 的 Whisper base,模型下載約 80 MB,下載後可離線使用。音訊解碼後每小時立體聲約佔 1.3 GB 記憶體,較長檔案可能對手機造成負擔。

正文

I built Scissor Audio, a set of free audio tools that run entirely in the browser: https://audio.scissor.studio/
You can trim, join, mix, convert, compress, transcribe and tag audio, and the file never leaves your device.

The Scissor Audio editor

There are twelve tools and an audio editor, in 30 languages. Here is how the parts fit together, and where they stop.

A static site and plain modules

There is no framework and no backend for the audio. One Node script builds every page from a list of tools and a JSON file per language: the HTML, the head tags, the structured data and the service worker. Each tool is an ES module that the page loads when you open it. The site is served as static files from Cloudflare.

The server sends files and receives anonymous page counts and error reports. Opening, editing and saving all happen in the tab.

Decoding is the browser's job

I do not ship my own decoders. The browser already has them, and some formats are covered by patents I do not want to deal with. Every file goes through the Web Audio API and comes out as 44.1 kHz float samples:

export async function decode(file) {
  const ctx = new OfflineAudioContext(2, 1, 44100);
  const buf = await ctx.decodeAudioData(await file.arrayBuffer());
  return { rate: buf.sampleRate, ch: Array.from({ length: Math.min(2, buf.numberOfChannels) }, (_, i) => buf.getChannelData(i)) };
}

Decoding everything to the same rate means the joiner and the mixer can line tracks up sample for sample without resampling them again. The cost is memory: an hour of stereo audio is about 1.3 GB once decoded, so very long files can be too much for a phone.

Encoders: some borrowed, one written by hand

For MP3 the site uses LAME, and for Ogg it uses libvorbis, both compiled to WebAssembly by the wasm-media-encoders project. LAME is LGPL 2.1, so mp3.wasm (133 KB) stays a separate file that anyone can replace with their own build, and the licence page says where it came from. libvorbis and libogg are BSD 3-Clause; ogg.wasm is 450 KB. Both load only when you save in that format.

M4A uses the browser's own AAC encoder through WebCodecs, with a small MP4 writer around it. WAV is a header and the samples.

FLAC I wrote myself, because a lossless encoder is small when you keep it simple: 16-bit samples, fixed predictors and Rice coding, with the CRC-8 and CRC-16 each frame needs. It does not reach the compression of the reference encoder, but it is lossless and it is about 100 lines.

Speech models on the device

Audio to text runs OpenAI's Whisper base model (MIT) through transformers.js (Apache-2.0) and ONNX Runtime Web (MIT), quantized to 8 bits, in a web worker on WebAssembly, with threads where the browser allows them. The download is about 80 MB: a 23 MB encoder, a 54 MB decoder and a 2.5 MB tokenizer, all served from the same site.

Text to speech uses Kokoro 82M (Apache-2.0), about 92 MB. The bundle that turns text into phonemes contains eSpeak NG, which is GPL 3.0, so that one file is distributed under the GPL with its sources named.

Each model downloads once and stays in the browser's storage, so it then works offline. In Chrome, Edge and Firefox the Scissor tools share one copy, so the second tool that needs Whisper does not download it again.

The one request that leaves the page

The tag editor reads and writes ID3, MP4 and FLAC tags itself, and saves the same audio bytes with new tags. It can also look tags up in MusicBrainz. Apart from Google Drive, if you choose to open or save there, that is the only time the page talks to another server, and only when you press Search. What it sends is the words in the two search boxes. The cover comes from the Cover Art Archive.

The Content-Security-Policy lists exactly those hosts in connect-src, so nothing else can be fetched even by mistake.

Limits

  • Whisper base is small. It is fine for clear speech and weaker on noise, accents and names than the larger models. On an older phone a long recording takes a while, since it runs on the CPU.
  • The first transcription needs that 80 MB download.
  • Safari and browsers on iPhone keep a separate copy of the models for each site.
  • Which formats open depends on the browser, because decoding is the browser's.
  • M4A output needs the browser's AAC encoder; where it is missing, M4A is not offered.
  • The tag editor does not handle WAV or OGG tags yet.

Try it: https://audio.scissor.studio/

It is free, with no account and no sign-up. One question I would like answered: if you try audio to text on a phone, how long does one minute of speech take on your device, and which phone is it?

來源:DEV Community · dev.to