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://orhttp://localhost - A modern browser with
AudioContextandMediaDevices.getUserMedia - Access to the ephemeral key flow provided by SORI
- Microphone permission granted by the user
Integration Flow
- Create an
AudioRecognizerwith yourappId. - Provide an ephemeral key through
ephemeralKeyas a string or your own async callback. - Subscribe to the events you need, such as
campaign,match, anderror. - Call
start()to begin recognition. - Call
stop()ordestroy()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.
