diff --git a/docs/docs/browser/api-reference.html b/docs/docs/browser/api-reference.html new file mode 100644 index 0000000..539dfc9 --- /dev/null +++ b/docs/docs/browser/api-reference.html @@ -0,0 +1,347 @@ + + + + + + + + + API Reference | decibri docs + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + +

API Reference

+

Complete reference for the decibri-web browser API. For installation and basic usage, see Getting Started.

+ +

Constructor

+

new Decibri(options?)

+

Creates a new capture instance. Does not start capture. Call start() to begin.

+
import { Decibri } from 'decibri-web';
+const mic = new Decibri(options?);
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionTypeDefaultDescription
sampleRatenumber16000Target sample rate in Hz (1,000 to 384,000)
channelsnumber1Number of channels (browsers reliably support 1)
framesPerBuffernumber1600Frames per chunk. 1,600 at 16 kHz = 100 ms chunks (64 to 65,536)
devicestringsystem defaultdeviceId string from Decibri.devices()
format'int16' | 'float32''int16'Sample encoding format
vadbooleanfalseEnable voice activity detection
vadThresholdnumber0.01RMS energy threshold for speech detection (0 to 1)
vadHoldoffnumber300Milliseconds of sub-threshold audio before 'silence' is emitted
echoCancellationbooleantrueBrowser echo cancellation. Set false for music/tuner apps
noiseSuppressionbooleantrueBrowser noise suppression. Set false for raw signal
workletUrlstring(inline Blob URL)URL for AudioWorklet processor file. Override if CSP blocks blob: URLs
+
+ +

Methods

+ +

mic.start()

+

Returns Promise<void>. Requests microphone permission and begins capture. Must be called from a user gesture in Safari. No-op if already started. Rejects with a clear error on permission denial.

+ +

mic.stop()

+

Stops capture and releases all resources (tracks, context, nodes). Safe to call anytime, including before start() or multiple times. Emits 'end' then 'close'.

+ +

Properties

+ +

mic.isOpen

+

boolean (read-only). Returns true while actively capturing audio.

+ +

Static methods

+ +

Decibri.devices()

+

Returns Promise<DeviceInfo[]>. Lists available audio input devices. Labels may be empty before microphone permission is granted.

+
const devices = await Decibri.devices();
+console.log(devices);
+// [
+//   { deviceId: 'abc123', label: 'Built-in Microphone', groupId: 'g1' },
+//   ...
+// ]
+ +

Decibri.version()

+

Returns version information for decibri-web.

+
Decibri.version();
+// { decibriWeb: '0.1.0' }
+ +

Events

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
EventPayloadDescription
'data'Int16Array or Float32ArrayAudio chunk. Format depends on format option. Emitted ~10 times/sec at default settings.
'error'ErrorPermission denied, worklet load failure, AudioContext creation failure.
'end'(none)Emitted after stop().
'close'(none)Emitted after stop(), after 'end'.
'speech'(none)VAD: RMS energy crossed threshold. Requires vad: true.
'silence'(none)VAD: sub-threshold audio for vadHoldoff ms. Requires vad: true.
+
+ +

Types

+
// DeviceInfo
+{
+  deviceId: string,
+  label: string,
+  groupId: string,
+}
+
+// VersionInfo
+{
+  decibriWeb: string,
+}
+ +

Differences from decibri (Node.js)

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureNode.js decibridecibri-webNotes
Class nameDecibriDecibriIdentical
ConstructorSync, capture starts on readSync, requires await start()Browser needs async permission
'data' payloadBufferInt16Array / Float32ArrayDifferent types, same PCM data
devices()SyncAsync (returns Promise)Browser API is async
device optionNumber index or name substringString deviceId onlyBrowser uses opaque device IDs
version(){ decibri, portaudio }{ decibriWeb }Different runtime info
echoCancellationN/Aboolean (default true)Browser-only option
noiseSuppressionN/Aboolean (default true)Browser-only option
'backpressure' eventAvailableNot availableNo browser equivalent
pipe() / streamsFull Readable streamNot availableBrowser has no Node streams
sampleRateAny (PortAudio resamples)Any (AudioWorklet resamples)Same behavior
format'int16' or 'float32''int16' or 'float32'Identical
VAD (speech/silence)RMS-basedRMS-based (same algorithm)Identical
+
+ + + +
+
+ + + + + + + diff --git a/docs/docs/browser/index.html b/docs/docs/browser/index.html new file mode 100644 index 0000000..76525da --- /dev/null +++ b/docs/docs/browser/index.html @@ -0,0 +1,243 @@ + + + + + + + + + Getting Started | decibri docs + + + + + + + + + + + + + + + + + +
+
+ + + +
+
+ + + +

Getting Started

+

decibri-web is a browser-based microphone capture library. It uses the Web Audio API and AudioWorklet to capture raw PCM audio chunks in real-time. Same API as decibri for Node.js, different runtime. Zero dependencies, 6.4KB ESM bundle.

+ +
+ + + + + + + + + + + + + + + + + + + + +
PackageEnvironmentBackend
decibriNode.jsNative C++ (PortAudio)
decibri-webBrowserWeb Audio API
+
+ +

Install

+
+ $ + npm install decibri-web + +
+ +

Or via CDN:

+
<script src="https://unpkg.com/decibri-web/dist/index.global.js"></script>
+ +

Quick start

+

Capture microphone audio and log the chunk size:

+
import { Decibri } from 'decibri-web';
+
+const mic = new Decibri({ sampleRate: 16000 });
+
+mic.on('data', (chunk) => {
+  console.log(`Received ${chunk.length} samples`);
+});
+
+await mic.start();
+

start() must be called from a user gesture (click/tap) in Safari. Each chunk contains 100 ms of audio by default (1,600 frames at 16 kHz).

+ +

Permission handling

+

Microphone access requires HTTPS (or localhost). The browser will show a permission prompt when start() is called.

+ + +

Stopping and cleanup

+
mic.stop();
+

stop() releases all resources: MediaStream tracks are stopped, AudioContext is closed, all nodes are disconnected, references are nulled. Safe for React/Vue component unmount cycles. Safe to call multiple times or before start().

+

To restart after stopping:

+
await mic.start(); // creates a fresh audio pipeline
+ +

Device selection

+
// Start first to trigger permission, then enumerate with labels
+await mic.start();
+const devices = await Decibri.devices();
+console.log(devices);
+// [{ deviceId: 'abc123', label: 'Built-in Microphone', groupId: 'g1' }, ...]
+
+// Use a specific device
+const usbMic = new Decibri({ device: devices[1].deviceId });
+await usbMic.start();
+ +

Output formats

+
// Int16 PCM (default) - ready for most STT engines
+const mic = new Decibri({ format: 'int16' });
+mic.on('data', (chunk) => {
+  // chunk is an Int16Array
+});
+
+// Float32 - native browser format, no conversion
+const mic2 = new Decibri({ format: 'float32' });
+mic2.on('data', (chunk) => {
+  // chunk is a Float32Array
+});
+ +

Voice activity detection

+

Enable the built-in VAD to receive 'speech' and 'silence' events based on RMS energy thresholding:

+
const mic = new Decibri({
+  sampleRate: 16000,
+  vad: true,
+  vadThreshold: 0.01,
+  vadHoldoff: 300,
+});
+
+mic.on('speech', () => console.log('Speaking...'));
+mic.on('silence', () => console.log('Silence'));
+
+await mic.start();
+ +

WebSocket streaming

+
const ws = new WebSocket('wss://your-server.com/audio');
+const mic = new Decibri({ sampleRate: 16000, format: 'int16' });
+
+mic.on('data', (chunk) => {
+  if (ws.readyState === WebSocket.OPEN) {
+    ws.send(chunk.buffer);
+  }
+});
+
+document.getElementById('start').onclick = () => mic.start();
+document.getElementById('stop').onclick = () => mic.stop();
+ +

Browser support

+

Requires HTTPS (or localhost) for microphone access.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
BrowserMinimum Version
Chrome66+
Firefox76+
Safari14.1+ (requires user gesture)
Edge79+
iOS Safari14.5+
Android Chrome66+
+
+ +

CSP-restricted environments

+

By default, decibri-web loads its AudioWorklet processor via an inline Blob URL. If your Content Security Policy blocks blob: URLs:

+
const mic = new Decibri({
+  workletUrl: '/static/decibri-worklet.js',
+});
+

Copy node_modules/decibri-web/dist/worklet.js to your static assets directory and pass the URL.

+ +

Next steps

+ + + + +
+
+ + + + + + + + diff --git a/docs/docs/index.html b/docs/docs/index.html index 1ccb84d..dda31d9 100644 --- a/docs/docs/index.html +++ b/docs/docs/index.html @@ -13,10 +13,10 @@ })(); Documentation | decibri - + - + @@ -30,19 +30,21 @@ "@type": "ItemList", "name": "decibri Integrations", "description": "Speech-to-text and audio processing integrations for decibri, a cross-platform Node.js microphone streaming library.", - "numberOfItems": 11, + "numberOfItems": 13, "itemListElement": [ - {"@type": "ListItem", "position": 1, "name": "Sherpa-ONNX Speech-to-Text", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-stt.html"}, - {"@type": "ListItem", "position": 2, "name": "Sherpa-ONNX Keyword Spotting", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-kws.html"}, - {"@type": "ListItem", "position": 3, "name": "Sherpa-ONNX Voice Activity Detection", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-vad.html"}, - {"@type": "ListItem", "position": 4, "name": "Whisper.cpp Speech-to-Text", "url": "https://decibri.dev/docs/node/integrations/whisper-cpp.html"}, - {"@type": "ListItem", "position": 5, "name": "Deepgram Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/deepgram.html"}, - {"@type": "ListItem", "position": 6, "name": "AssemblyAI Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/assemblyai.html"}, - {"@type": "ListItem", "position": 7, "name": "OpenAI Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/openai-realtime.html"}, - {"@type": "ListItem", "position": 8, "name": "Mistral Voxtral Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/mistral-voxtral.html"}, - {"@type": "ListItem", "position": 9, "name": "AWS Transcribe Streaming", "url": "https://decibri.dev/docs/node/integrations/aws-transcribe.html"}, - {"@type": "ListItem", "position": 10, "name": "Google Cloud Speech-to-Text Streaming", "url": "https://decibri.dev/docs/node/integrations/google-speech.html"}, - {"@type": "ListItem", "position": 11, "name": "Azure Speech-to-Text Streaming", "url": "https://decibri.dev/docs/node/integrations/azure-speech.html"} + {"@type": "ListItem", "position": 1, "name": "Browser Getting Started", "url": "https://decibri.dev/docs/browser/"}, + {"@type": "ListItem", "position": 2, "name": "Browser API Reference", "url": "https://decibri.dev/docs/browser/api-reference.html"}, + {"@type": "ListItem", "position": 3, "name": "Sherpa-ONNX Speech-to-Text", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-stt.html"}, + {"@type": "ListItem", "position": 4, "name": "Sherpa-ONNX Keyword Spotting", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-kws.html"}, + {"@type": "ListItem", "position": 5, "name": "Sherpa-ONNX Voice Activity Detection", "url": "https://decibri.dev/docs/node/integrations/sherpa-onnx-vad.html"}, + {"@type": "ListItem", "position": 6, "name": "Whisper.cpp Speech-to-Text", "url": "https://decibri.dev/docs/node/integrations/whisper-cpp.html"}, + {"@type": "ListItem", "position": 7, "name": "Deepgram Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/deepgram.html"}, + {"@type": "ListItem", "position": 8, "name": "AssemblyAI Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/assemblyai.html"}, + {"@type": "ListItem", "position": 9, "name": "OpenAI Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/openai-realtime.html"}, + {"@type": "ListItem", "position": 10, "name": "Mistral Voxtral Real-Time Transcription", "url": "https://decibri.dev/docs/node/integrations/mistral-voxtral.html"}, + {"@type": "ListItem", "position": 11, "name": "AWS Transcribe Streaming", "url": "https://decibri.dev/docs/node/integrations/aws-transcribe.html"}, + {"@type": "ListItem", "position": 12, "name": "Google Cloud Speech-to-Text Streaming", "url": "https://decibri.dev/docs/node/integrations/google-speech.html"}, + {"@type": "ListItem", "position": 13, "name": "Azure Speech-to-Text Streaming", "url": "https://decibri.dev/docs/node/integrations/azure-speech.html"} ] } @@ -78,7 +80,7 @@

Welcome to the decibri documentation

-

This documentation is here to help you get up and running with decibri and integrate it into your voice and audio applications. decibri is a cross-platform Node.js package for real-time microphone audio capture, built on PortAudio with pre-built native binaries. No ffmpeg, no SoX, and no build tools required.

+

This documentation is here to help you get up and running with decibri and integrate it into your voice and audio applications. decibri is a cross-platform audio capture library for JavaScript. The Node.js package uses a native PortAudio addon with pre-built binaries. The browser package uses the Web Audio API with zero dependencies. Same API, different runtimes.

Node.js

@@ -92,6 +94,18 @@

API Reference

+

Browser

+
+ +

Getting Started

+

Install, capture audio in the browser, and stream to your backend

+
+ +

API Reference

+

Constructor options, methods, events, and browser compatibility

+
+
+

Integrations

Step-by-step guides for using decibri with speech and audio processing tools.

diff --git a/docs/docs/nav.js b/docs/docs/nav.js index 6cfaeaf..3b2c11e 100644 --- a/docs/docs/nav.js +++ b/docs/docs/nav.js @@ -87,6 +87,11 @@ + '' + '' + '' + + '' + '' + '