In-browser audio transcription: Transformers.js

In-browser audio transcription here relies on Transformers.js, Hugging Face's JavaScript library: it loads a Whisper model in ONNX format and runs speech recognition in the tab, with no transcription server to install. The computation runs on your machine, but unless configured otherwise, the page first downloads the model and the runtime from third-party services. This guide shows the documented code, the official sample files, and how to tell what stays local from what goes over the network. It contains no speed or accuracy measurements.
#Audio transcription in the browser: what Transformers.js does
Transformers.js follows the approach of the Python transformers library: a pipeline() function takes a task name and, optionally, a model ID, then handles preprocessing, inference, and postprocessing. For speech recognition, the task is called automatic-speech-recognition. The documentation illustrates it with Whisper variants converted to ONNX format, published on the Hugging Face Hub under the Xenova and onnx-community accounts.
Inference runs through ONNX Runtime Web. By default, it runs in WebAssembly on the CPU; the device: 'webgpu' option moves it to the GPU when the browser exposes WebGPU. The documentation also states that, in the browser, a quantized version of the model is used by default: smaller and faster, but generally less accurate. The dtype option lets you request a different precision, for example fp32.
- npm package
- @huggingface/transformers. Older examples online sometimes use a different package name: follow the one in the current documentation.
- Models
- Any Hub model with ONNX weights, stored in an onnx subfolder, according to the pipelines page. A GGUF file or a Faster-Whisper model in CTranslate2 format won't load as is.
- Accepted inputs
- A URL, or raw samples as a Float32Array or Float64Array, according to the API reference.
- Outputs
- An object with a text field and, if requested, a chunks array timestamped by segment or by word.
#Initial downloads, local execution, third-party services
Benefit from our experience and a guided path to build your local assistant and use your AI every day.
- Lifetime online access
- PDF + files
- Refunded within 30 days
An in-browser audio transcription page mixes three data flows that you need to separate before making any claims to your users.
- 1. Initial downloads
- On the first call, pipeline() downloads the model from the Hugging Face Hub and stores it in the browser cache (Cache API, key transformers-cache by default). The ONNX Runtime WebAssembly binaries, however, come from a CDN: as of November 25, 2026, the documentation pointed to cdn.jsdelivr.net. If you import the library itself from a CDN, that adds one more host.
- 2. Local execution
- Once the files are in place, audio decoding and inference run in the tab, on the machine's CPU or GPU. The library doesn't need to send the audio to a server to transcribe it.
- 3. Any third-party services
- Everything else depends on the page: analytics, fonts, widgets, and save or share features. Any script on the page can read the displayed transcript. The documentation's sample files are also hosted on huggingface.co, so transcribing them by URL triggers a download.
Practical consequence: the Hub and the CDN see at least your IP address and the requested files, even if no audio leaves the machine. To find out what a page actually does with the audio and text, you need to observe it in the Network tab; the protocol detailed in our WebLLM guide applies as is, with an audio file instead of the message.
#Prerequisites
- A JavaScript project
- Node.js 22.12 or later for this Vite example. The package is installed in the project and served by Vite, without importing the library from a CDN.
- A recent browser
- WebAssembly mode is enough to get started. For WebGPU, the documentation estimated global coverage in March 2026 at about 85% based on caniuse.com, with flags you need to enable in some browsers. It also describes WebGPU as experimental, especially outside Chromium.
- A page served over HTTPS or from localhost
- WebGPU is only available in a secure context. Vite's development server on localhost works.
- Disk space and an internet connection
- For the model's first download. Its size depends on the variant and quantization: check it in the Network tab or on the model page. We don't give unverified figures.
#Transcribing a sample audio file step by step
The following steps reuse the examples from the API reference. They use the audio files published by Hugging Face in the Xenova/transformers.js-docs dataset: jfk.wav (English, short), french-audio.mp3 (French, short), and ted_60.wav (English, about one minute judging by its name). These examples are independent. To try them in Vite, put one block at a time in app.js. If something fails, first check that the library, the model, and the remote file load correctly.
- 01Load the pipeline and transcribe an English fileThe first call downloads Xenova/whisper-tiny.en, the smallest variant in the documentation. The .en suffix indicates a model trained for English only: don't use it for French.
- 02Switch to French with a multilingual modelThe documentation uses Xenova/whisper-small with language: 'french' and task: 'transcribe'. Without these options, the language is detected automatically. With task: 'translate', Whisper translates into English instead of transcribing.
- 03Request timestampsreturn_timestamps: true returns timestamped segments; return_timestamps: 'word' goes down to the word level. Useful for subtitles, provided you review the boundaries.
- 04Split long audio filesWhisper processes audio in 30-second windows. For a longer file, the documentation passes chunk_length_s: 30 and stride_length_s: 5; without chunk_length_s, the audio isn't split into chunks. If stride_length_s is omitted, it defaults to chunk_length_s / 6.
- 05Try WebGPUAdd { device: 'webgpu' } as the third argument to pipeline(). The official example uses onnx-community/whisper-tiny.en. Keep a WebAssembly fallback for browsers without WebGPU.
Loading can take a while on the first run. The pipeline() signature accepts loading options (PretrainedModelOptions); the reference page we reviewed didn't document the progress callback, so check the reference's hub page for your installed version before displaying a progress bar. To keep the UI responsive, run the pipeline in a Web Worker and send only the text back to the main thread.
#Transcribe a file chosen by the user
In the folder you created earlier, save index.html and app.js. This app explicitly loads Xenova/whisper-small, a multilingual model, to transcribe a French audio file. The selected file is decoded in the browser. The model and runtime may be downloaded on first access, but this code does not upload the audio file.
Open the localhost address shown in the terminal and choose a short French audio file. The server keeps running during the test. The first selection triggers loading the model. If it fails, the status message and the Network tab help you tell an incomplete download apart from a decoding problem.
This code loads the entire file into memory before splitting it. For a recording several hours long, the tab's memory becomes the constraint: split the file beforehand or use an installed tool such as Faster-Whisper instead.
#In-browser audio transcription without the Hub or a CDN
For an internal tool, or to reduce the number of domains contacted, serve the model and the WebAssembly binaries from your own domain. For this, Transformers.js exposes an env object, which you modify before the first call to pipeline().
- allowLocalModels
- Defaults to false in the browser, according to the env reference: unless you set it to true, the library doesn't look for files under localModelPath.
- allowRemoteModels
- Setting it to false is equivalent to local_files_only=true: a missing file raises an error instead of triggering a silent download. This is the setting that makes the absence of Hub calls verifiable.
- Model directory tree
- Replicate under /models/Xenova/whisper-small/ the Hub repository files that the library requests. The easiest way: load the model online once, note the exact paths in the Network tab, then copy them.
- WebAssembly binaries
- Copy the ONNX Runtime files into /wasm/ from the installed version of Transformers.js, and not from any other: a different version may fail to load.
The env reference also states that useWasmCache, enabled by default when a cache is available, caches the ONNX Runtime binaries and “enables offline use by avoiding repeated downloads.” That's a claim from the documentation, not something we verified. As with WebLLM, the cache doesn't cover your page's HTML and JavaScript: without a service worker, the URL won't reopen with the network disconnected.
#Limitations to know before you rely on it
- Accuracy
- According to the documentation, the default quantized models are generally less accurate. Small variants such as tiny make more errors than large ones. Evaluate on your own recordings, with a reference transcript, before any professional use.
- Speed
- It depends on the CPU or GPU, the browser, WASM or WebGPU mode, and the model variant. We don't publish any figures because no documented measurements are available: measure on your target machines.
- Cache
- The browser cache can be cleared by the user or evicted by the browser when disk space runs low. Plan for a model to be downloaded again.
- Memory
- A browser tab has fewer resources than an installed program. Larger Whisper variants and long files hit these limits sooner.
- Hallucinations
- Whisper can produce text that was never spoken, especially on silence or music. Proofread any transcription intended to be quoted or archived.
- Licenses
- The package license and the model license are separate. Check both on npm and on the model's Hub page before integrating it into a product.
- Sensitive data
- Local processing doesn't mean the page can't leak data. For medical consultations or interviews, audit the page and its scripts, or use an installed pipeline you control instead.
#Troubleshooting
- The text is in English even though the audio is in French
- You're using a .en model, or task is set to translate. Use a multilingual model and pass language: 'french', task: 'transcribe'.
- Only the first 30 seconds are transcribed
- chunk_length_s isn't set: its default value is 0, so no chunking.
- Incoherent transcription of a local file
- Check the sample rate (16 kHz) and the conversion to mono before you suspect the model.
- Loading error after allowRemoteModels = false
- A file is missing under localModelPath, or allowLocalModels was left set to false. The error message and the Network tab show the expected path.
- The .wasm files fail with a 404
- wasmPaths points to an incomplete folder or to a different ONNX Runtime version than the one expected.
- device: 'webgpu' fails
- Test navigator.gpu and requestAdapter() in the console, on a page served over HTTPS or localhost. Failing that, remove the option to fall back to WebAssembly. The documentation encourages reporting WebGPU errors on GitHub.
- The model is re-downloaded on every visit
- Private browsing, site data cleared, domain change, or useBrowserCache disabled.
#Go further
If you regularly transcribe long recordings on your own machine, Faster-Whisper remains easier to control than a web page: no cache to monitor and no third-party scripts. The free guide to audio-to-text transcription compares installable tools. To audit a page that claims in-browser AI, the WebLLM guide explains how to verify network traffic and offline behavior.
Feedback, an error, or a clarification? Let us know—it improves the guide for everyone.