Intermediate 12 minDaily plan

In-browser audio transcription: Transformers.js

An open laptop casts green light across a dark desk.

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.

By Mohamed Meguedmi·Update 2026-11-25·Tested on Windows, macOS, and Linux
!
Limits of this guide
The API examples come from the official Transformers.js documentation, reviewed on November 25, 2026. The Vite app uses Transformers.js 4.3.2. QuelLLM built the project and locally transcribed a synthetic French WAV file in Chrome 154. The pipeline worked, with errors at the end of the sentence. This test measures neither overall accuracy nor offline operation. The transcriptions shown in comments come from the documentation.

#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

The complete kit for building your own AI assistant.

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.
Terminal — create the Vite project and pin dependencies
mkdir transcription-navigateur
cd transcription-navigateur
npm init -y
npm install --save-exact @huggingface/transformers@4.3.2
npm install --save-dev --save-exact vite@7.3.8

#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.

  1. 01
    Load the pipeline and transcribe an English file
    The 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.
  2. 02
    Switch to French with a multilingual model
    The 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.
  3. 03
    Request timestamps
    return_timestamps: true returns timestamped segments; return_timestamps: 'word' goes down to the word level. Useful for subtitles, provided you review the boundaries.
  4. 04
    Split long audio files
    Whisper 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.
  5. 05
    Try WebGPU
    Add { 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.
Step 1: English, sample file
import { pipeline } from '@huggingface/transformers';

const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
const output = await transcriber(url);
console.log(output.text);
// Sortie indiquée par la documentation :
// { text: " And so my fellow Americans ask not what your country can do for you, ask what you can do for your country." }
Step 2: French, multilingual model
import { pipeline } from '@huggingface/transformers';

const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-small');
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/french-audio.mp3';
const output = await transcriber(url, { language: 'french', task: 'transcribe' });
console.log(output.text);
// Sortie indiquée par la documentation :
// { text: " J'adore, j'aime, je n'aime pas, je déteste." }
Steps 3 and 4 — reuse the pipeline and URL from step 2
// Segments horodatés
const segments = await transcriber(url, { return_timestamps: true });
// segments.chunks : [{ timestamp: [0, 8], text: '...' }, ...]

// Horodatage mot à mot
const mots = await transcriber(url, { return_timestamps: 'word' });

// Audio de plus de 30 secondes (exemple de la documentation)
const long = await transcriber(
  'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/ted_60.wav',
  { chunk_length_s: 30, stride_length_s: 5 },
);
console.log(segments.chunks, mots.chunks, long.text);
Step 5: WebGPU
import { pipeline } from '@huggingface/transformers';

const transcriber = await pipeline(
  'automatic-speech-recognition',
  'onnx-community/whisper-tiny.en',
  { device: 'webgpu' },
);

const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
const output = await transcriber(url);
console.log(output.text);

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.

index.html — at the project root
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Transcription audio dans le navigateur</title>
  </head>
  <body>
    <h1>Transcription audio en français</h1>
    <label for="audio">Fichier audio</label>
    <input id="audio" type="file" accept="audio/*">
    <p id="statut" role="status">Choisissez un fichier audio.</p>
    <pre id="texte"></pre>
    <script type="module" src="/app.js"></script>
  </body>
</html>
app.js — multilingual model and local 16 kHz decoding
import { pipeline } from '@huggingface/transformers';

const input = document.querySelector('#audio');
const statut = document.querySelector('#statut');
const texte = document.querySelector('#texte');
let transcriber;

async function lireAudio(fichier) {
  const tampon = await fichier.arrayBuffer();
  const contexte = new AudioContext({ sampleRate: 16000 });
  try {
    const audio = await contexte.decodeAudioData(tampon);
    if (audio.numberOfChannels === 1) return audio.getChannelData(0);

    // Pour un fichier stéréo, mélanger le canal gauche et le droit.
    const gauche = audio.getChannelData(0);
    const droite = audio.getChannelData(1);
    const mono = new Float32Array(gauche.length);
    for (let i = 0; i < mono.length; i++) {
      mono[i] = (gauche[i] + droite[i]) / 2;
    }
    return mono;
  } finally {
    await contexte.close();
  }
}

input.addEventListener('change', async () => {
  const fichier = input.files[0];
  if (!fichier) return;

  input.disabled = true;
  texte.textContent = '';
  try {
    if (!transcriber) {
      statut.textContent = 'Chargement du modèle…';
      transcriber = await pipeline(
        'automatic-speech-recognition',
        'Xenova/whisper-small',
      );
    }

    statut.textContent = 'Décodage et transcription…';
    const echantillons = await lireAudio(fichier);
    const resultat = await transcriber(echantillons, {
      language: 'french',
      task: 'transcribe',
      chunk_length_s: 30,
      stride_length_s: 5,
    });
    texte.textContent = resultat.text;
    statut.textContent = 'Transcription terminée.';
  } catch (erreur) {
    statut.textContent = 'Impossible de transcrire ce fichier : ' + erreur.message;
  } finally {
    input.disabled = false;
    input.value = '';
  }
});
Terminal — start Vite from the project folder
npx vite --host localhost

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.

i
Sample rate: needs checking
The API reference doesn't specify the expected sample rate for a Float32Array. Whisper models are trained on 16 kHz audio; the chosen model's preprocessor_config.json file states it in its sampling_rate field. Audio passed at a different sample rate won't necessarily cause an error, but it degrades the transcription. Resampling by decodeAudioData to the context's sample rate is handled by the Web Audio API, so check it on your target browsers.

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().

Documented configuration (example paths)
import { env, pipeline } from '@huggingface/transformers';

// Modèles servis par votre domaine (défaut : /models/)
env.localModelPath = '/models/';
env.allowLocalModels = true;

// Interdire tout téléchargement depuis le Hugging Face Hub
env.allowRemoteModels = false;

// Binaires .wasm d'ONNX Runtime servis localement (défaut : un CDN)
env.backends.onnx.wasm.wasmPaths = '/wasm/';

const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-small');
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.

→
The only test that counts for offline use
Load the page and the model once, close the tab, disconnect from the network, reopen the URL, and transcribe a local file. Record the browser, its version, the model, and the date. Without this test, write “runs locally after download,” not “works offline.”

#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.

Did this guide help you?

Feedback, an error, or a clarification? Let us know—it improves the guide for everyone.