@sorisdk/web-audio 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -71
- package/dist/generated/window_bg.wasm +0 -0
- package/package.json +5 -13
package/README.md
CHANGED
|
@@ -1,98 +1,83 @@
|
|
|
1
1
|
# @sorisdk/web-audio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web SDK for integrating SORI audio recognition into browser-based services.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package provides the browser-side flow needed for web recognition, including authentication bootstrap, pack caching, microphone input, audio fingerprint generation, matching, and campaign events.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Public integration guide: https://docs.soriapi.com/ko/integration/web
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- Web Audio graph setup
|
|
11
|
-
- PCM chunk capture
|
|
12
|
-
- rolling fingerprint generation with `@sorisdk/afpgen`
|
|
13
|
-
- rolling query matching with `@sorisdk/matcher`
|
|
9
|
+
## Requirements
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
- A secure context such as `https://` or `http://localhost`
|
|
12
|
+
- A modern browser with `AudioContext` and `MediaDevices.getUserMedia()`
|
|
13
|
+
- An ephemeral key issued by your server
|
|
14
|
+
- Microphone permission granted by the user
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
import { AudioRecognizer } from "@sorisdk/web-audio";
|
|
19
|
-
|
|
20
|
-
const recognizer = new AudioRecognizer({
|
|
21
|
-
appId: "app-1",
|
|
22
|
-
ephemeralKeyEndpoint: "https://site.example.com/api/ephemeral-key"
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
recognizer.on("campaign", (event) => {
|
|
26
|
-
console.log(event.campaign);
|
|
27
|
-
});
|
|
16
|
+
## Installation
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await recognizer.destroy();
|
|
18
|
+
```bash
|
|
19
|
+
npm install @sorisdk/web-audio
|
|
32
20
|
```
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
and derives:
|
|
36
|
-
|
|
37
|
-
- auth: `/auth`
|
|
38
|
-
- activity: `/activity/`
|
|
39
|
-
|
|
40
|
-
So direct ephemeral key usage can be as small as:
|
|
22
|
+
Vite-based apps need `vite-plugin-wasm`.
|
|
41
23
|
|
|
42
24
|
```ts
|
|
43
|
-
|
|
44
|
-
appId: "app-1",
|
|
45
|
-
ephemeralKey: "ek-..."
|
|
46
|
-
});
|
|
47
|
-
```
|
|
25
|
+
import wasm from "vite-plugin-wasm";
|
|
48
26
|
|
|
49
|
-
|
|
27
|
+
export default {
|
|
28
|
+
plugins: [wasm()]
|
|
29
|
+
};
|
|
30
|
+
```
|
|
50
31
|
|
|
51
|
-
|
|
52
|
-
- It uses `AudioWorkletNode` when available and falls back to `ScriptProcessorNode`.
|
|
53
|
-
- Matching window size and matching-quality-sensitive runtime tuning stay internal to the SDK.
|
|
32
|
+
## Minimal example
|
|
54
33
|
|
|
55
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import { AudioRecognizer } from "@sorisdk/web-audio";
|
|
56
36
|
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
const recognizer = new AudioRecognizer({
|
|
38
|
+
appId: "YOUR_APP_ID",
|
|
39
|
+
ephemeralKey: async () => {
|
|
40
|
+
const response = await fetch("/api/ephemeral-key", {
|
|
41
|
+
method: "POST"
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw new Error(`Ephemeral key request failed: HTTP ${response.status}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { ephemeral_key } = await response.json();
|
|
49
|
+
return ephemeral_key;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
59
52
|
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
recognizer.on("campaign", (event) => {
|
|
54
|
+
console.log(event.campaign);
|
|
55
|
+
});
|
|
62
56
|
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
recognizer.on("error", ({ error }) => {
|
|
58
|
+
console.error(error);
|
|
65
59
|
});
|
|
66
60
|
|
|
67
|
-
|
|
61
|
+
await recognizer.start();
|
|
68
62
|
```
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
When `/api/auth` requires a `v` value, the browser package can keep the last successful
|
|
73
|
-
`version + packUrl` metadata in `localStorage` while leaving the actual audiopack bytes to
|
|
74
|
-
the browser HTTP cache:
|
|
64
|
+
Call `stop()` or `destroy()` when recognition should end or when the page is being cleaned up.
|
|
75
65
|
|
|
76
66
|
```ts
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
} from "@sorisdk/web-audio";
|
|
67
|
+
await recognizer.stop();
|
|
68
|
+
await recognizer.destroy();
|
|
69
|
+
```
|
|
81
70
|
|
|
82
|
-
|
|
83
|
-
key: "sorisdk:matcher:app-1"
|
|
84
|
-
});
|
|
71
|
+
## Integration flow
|
|
85
72
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
ephemeralKey: "ek-...",
|
|
92
|
-
sessionId: "browser-device-1"
|
|
93
|
-
},
|
|
94
|
-
store
|
|
95
|
-
});
|
|
73
|
+
1. Prepare your `appId` and ephemeral key flow.
|
|
74
|
+
2. Create an `AudioRecognizer`.
|
|
75
|
+
3. Subscribe to the events you need, such as `campaign`, `match`, and `error`.
|
|
76
|
+
4. Call `start()` to begin recognition.
|
|
77
|
+
5. Call `stop()` or `destroy()` when leaving the page or stopping capture.
|
|
96
78
|
|
|
97
|
-
|
|
98
|
-
|
|
79
|
+
## Recommendations
|
|
80
|
+
|
|
81
|
+
- Do not hardcode ephemeral keys in the browser. Issue them from your server.
|
|
82
|
+
- Show clear UI while the microphone is active.
|
|
83
|
+
- Use the public documentation for full setup details and caveats.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sorisdk/web-audio",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Web SDK for browser-based audio recognition with SORI API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -32,18 +32,10 @@
|
|
|
32
32
|
],
|
|
33
33
|
"author": "comfuture",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"
|
|
36
|
-
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/iplateia/nada.git",
|
|
38
|
-
"directory": "packages/web-audio"
|
|
39
|
-
},
|
|
40
|
-
"homepage": "https://github.com/iplateia/nada/tree/main/packages/web-audio",
|
|
41
|
-
"bugs": {
|
|
42
|
-
"url": "https://github.com/iplateia/nada/issues"
|
|
43
|
-
},
|
|
35
|
+
"homepage": "https://docs.soriapi.com/ko/integration/web",
|
|
44
36
|
"dependencies": {
|
|
45
|
-
"@sorisdk/afpgen": "0.1.
|
|
46
|
-
"@sorisdk/matcher": "0.1.
|
|
37
|
+
"@sorisdk/afpgen": "0.1.1",
|
|
38
|
+
"@sorisdk/matcher": "0.1.1"
|
|
47
39
|
},
|
|
48
40
|
"devDependencies": {
|
|
49
41
|
"tsup": "^8.5.1",
|