
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
whisper-web-transcriber
Advanced tools
Real-time audio transcription in the browser using OpenAI's Whisper model via WebAssembly
Real-time audio transcription in the browser using OpenAI's Whisper model via WebAssembly. This package provides an easy-to-use API for integrating speech-to-text capabilities into web applications without any server-side processing.
Live Demo 🎙️ | Live Usage on Real Site 🚀
npm install whisper-web-transcriber
Or using yarn:
yarn add whisper-web-transcriber
<!-- Single file with all dependencies included -->
<script src="https://unpkg.com/whisper-web-transcriber/dist/index.bundled.min.js"></script>
import { WhisperTranscriber } from 'whisper-web-transcriber';
const transcriber = new WhisperTranscriber({
modelSize: 'base-en-q5_1',
onTranscription: (text) => {
console.log('Transcribed:', text);
}
});
await transcriber.loadModel();
await transcriber.startRecording();
<script src="https://unpkg.com/whisper-web-transcriber/dist/index.bundled.min.js"></script>
<script>
const transcriber = new WhisperTranscriber.WhisperTranscriber({
modelSize: 'base-en-q5_1',
onTranscription: (text) => {
console.log('Transcribed:', text);
}
});
transcriber.loadModel().then(() => {
transcriber.startRecording();
});
</script>
interface WhisperConfig {
modelUrl?: string; // Custom model URL (optional)
modelSize?: 'tiny.en' | 'base.en' | 'tiny-en-q5_1' | 'base-en-q5_1';
sampleRate?: number; // Audio sample rate (default: 16000)
audioIntervalMs?: number; // Audio processing interval (default: 5000ms)
onTranscription?: (text: string) => void;
onProgress?: (progress: number) => void;
onStatus?: (status: string) => void;
debug?: boolean; // Enable debug logging (default: false)
}
loadModel(): Promise<void>
- Downloads and initializes the Whisper modelstartRecording(): Promise<void>
- Starts microphone recording and transcriptionstopRecording(): void
- Stops recordingdestroy(): void
- Cleanup resourcesgetServiceWorkerCode(): string | null
- Returns the COI service worker code (bundled version only)getCrossOriginIsolationInstructions(): string
- Returns setup instructions for Cross-Origin IsolationModel | Size | Description |
---|---|---|
tiny.en | 75 MB | Fastest, lower accuracy |
base.en | 142 MB | Better accuracy, slower |
tiny-en-q5_1 | 31 MB | Quantized tiny model, smaller size |
base-en-q5_1 | 57 MB | Quantized base model, good balance |
WhisperTranscriber requires SharedArrayBuffer, which needs Cross-Origin Isolation. You have two options:
Configure your server to send these headers:
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin
If you can't modify server headers, use the included service worker:
For NPM users:
<!-- Include at the top of your HTML -->
<script src="node_modules/whisper-web-transcriber/dist/coi-serviceworker.js"></script>
For CDN users:
// Get the service worker code
const transcriber = new WhisperTranscriber.WhisperTranscriber();
const swCode = transcriber.getServiceWorkerCode();
// Save swCode as 'coi-serviceworker.js' on YOUR domain
// Then include it in your HTML:
// <script src="/coi-serviceworker.js"></script>
Important: Service workers must be served from the same origin as your page. CDN users cannot directly use the service worker from unpkg.
For local development:
npm run demo
For production (examples):
Vercel (vercel.json
):
{
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "Cross-Origin-Embedder-Policy",
"value": "require-corp"
},
{
"key": "Cross-Origin-Opener-Policy",
"value": "same-origin"
}
]
}
]
}
Nginx:
add_header Cross-Origin-Embedder-Policy "require-corp" always;
add_header Cross-Origin-Opener-Policy "same-origin" always;
<!DOCTYPE html>
<html>
<head>
<title>Whisper Transcriber - NPM Version</title>
<!-- Include service worker for Cross-Origin Isolation -->
<script src="node_modules/whisper-web-transcriber/dist/coi-serviceworker.js"></script>
</head>
<body>
<button id="start">Start Recording</button>
<button id="stop">Stop Recording</button>
<div id="transcription"></div>
<script type="module">
import { WhisperTranscriber } from './node_modules/whisper-web-transcriber/dist/index.esm.js';
const transcriber = new WhisperTranscriber({
modelSize: 'tiny-en-q5_1',
onTranscription: (text) => {
document.getElementById('transcription').textContent += text + ' ';
}
});
document.getElementById('start').onclick = async () => {
await transcriber.loadModel();
await transcriber.startRecording();
};
document.getElementById('stop').onclick = () => {
transcriber.stopRecording();
};
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Whisper Transcriber - CDN Version</title>
<!-- Note: You still need to handle Cross-Origin Isolation -->
<!-- Either configure server headers OR save and include the service worker -->
</head>
<body>
<button id="start">Start Recording</button>
<button id="stop">Stop Recording</button>
<div id="transcription"></div>
<!-- Single script include -->
<script src="https://unpkg.com/whisper-web-transcriber/dist/index.bundled.min.js"></script>
<script>
const transcriber = new WhisperTranscriber.WhisperTranscriber({
modelSize: 'tiny-en-q5_1',
onTranscription: (text) => {
document.getElementById('transcription').textContent += text + ' ';
}
});
// Check if Cross-Origin Isolation is enabled
if (!window.crossOriginIsolated) {
console.log(transcriber.getCrossOriginIsolationInstructions());
}
document.getElementById('start').onclick = async () => {
await transcriber.loadModel();
await transcriber.startRecording();
};
document.getElementById('stop').onclick = () => {
transcriber.stopRecording();
};
</script>
</body>
</html>
index.bundled.js
)index.js
)You need to enable Cross-Origin Isolation. See the Cross-Origin Isolation Setup section.
Use the bundled version (index.bundled.min.js
) instead of the standard version.
Ensure your site is served over HTTPS (or localhost) and the user has granted microphone permissions.
Built using:
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Real-time audio transcription in the browser using OpenAI's Whisper model via WebAssembly
The npm package whisper-web-transcriber receives a total of 107 weekly downloads. As such, whisper-web-transcriber popularity was classified as not popular.
We found that whisper-web-transcriber demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.