Skip to content

Web SDK

@sorisdk/web-audio is the browser SDK for adding SORI audio recognition to a web service or browser-based product.

Beta

The Web SDK is currently in Beta. Because the implementation is still evolving, parts of the API and integration flow may change.

Prerequisites

  • A secure context such as https:// or http://localhost
  • A modern browser with AudioContext and MediaDevices.getUserMedia
  • Access to the ephemeral key flow provided by SORI
  • Microphone permission granted by the user

Integration Flow

  1. Create an AudioRecognizer with your appId.
  2. Provide an ephemeral key through ephemeralKey as a string or your own async callback.
  3. Subscribe to the events you need, such as campaign, match, and error.
  4. Call start() to begin recognition.
  5. Call stop() or destroy() when recognition should pause or the page is being torn down.

Main API

AudioRecognizer is the main API for Web partner integrations. It handles the authentication bootstrap, session management, pack caching, and microphone recognition flow for you.

Minimal Example

ts
import { AudioRecognizer } from "@sorisdk/web-audio";

const recognizer = new AudioRecognizer({
  appId: "YOUR_APP_ID",
  ephemeralKey: async () => {
    const response = await fetch("/api/ephemeral-key", {
      method: "POST"
    });

    if (!response.ok) {
      throw new Error(`Ephemeral key request failed: HTTP ${response.status}`);
    }

    const { ephemeral_key } = await response.json();
    return ephemeral_key;
  }
});

recognizer.on("campaign", (event) => {
  console.log(event.campaign);
});

await recognizer.start();

For key issuance and relay patterns, see Ephemeral Key.

Next Steps