@adminforth/agent 3.1.1 → 3.1.3

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.
@@ -1,5 +1,5 @@
1
- import { MicVAD, utils } from "@ricky0123/vad-web";
2
-
1
+ // @ricky0123/vad-web brings onnxruntime-web (about 170 KB gzip): it loads when the microphone starts, not with the chat
2
+ let vad: typeof import("@ricky0123/vad-web") | null = null;
3
3
  let VADInstance: any = null;
4
4
  let recordedAudioChunks: Float32Array[] = [];
5
5
  let onVoiceStopCallback: () => void = () => {};
@@ -7,7 +7,8 @@ let onVoiceStartCallback: () => void = () => {};
7
7
  let onUpdateCallback: (amplitude: number) => void = () => {};
8
8
 
9
9
  async function createVADInstance(){
10
- VADInstance = await MicVAD.new({
10
+ vad = await import("@ricky0123/vad-web");
11
+ VADInstance = await vad.MicVAD.new({
11
12
  onFrameProcessed: ({ isSpeech }) => {
12
13
  onUpdateCallback(isSpeech);
13
14
  },
@@ -55,7 +56,8 @@ export async function getRecord() {
55
56
  offset += chunk.length;
56
57
  }
57
58
 
58
- const wavBuffer = utils.encodeWAV(mergedAudio, 1, 16000, 1, 16);
59
+ // chunks are recorded only by a started VAD, so the module is loaded here
60
+ const wavBuffer = vad!.utils.encodeWAV(mergedAudio, 1, 16000, 1, 16);
59
61
  const recordToReturn = new Blob([wavBuffer], { type: 'audio/wav' });
60
62
  recordedAudioChunks = [];
61
63
  return recordToReturn;
package/dist/index.js CHANGED
@@ -112,20 +112,6 @@ export default class AdminForthAgentPlugin extends AdminForthPlugin {
112
112
  editingEnabled: Boolean(this.options.checkpointResource && this.options.turnResource.checkpointIdField),
113
113
  }
114
114
  });
115
- if (!this.adminforth.config.customization.customHeadItems) {
116
- this.adminforth.config.customization.customHeadItems = [];
117
- }
118
- this.adminforth.config.customization.customHeadItems.push({
119
- tagName: 'script',
120
- attributes: {
121
- src: 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/ort.wasm.min.js'
122
- }
123
- }, {
124
- tagName: 'script',
125
- attributes: {
126
- src: 'https://cdn.jsdelivr.net/npm/@ricky0123/vad-web@0.0.29/dist/bundle.min.js'
127
- },
128
- });
129
115
  if (!this.options.sessionResource) {
130
116
  throw new Error("sessionResource is required for AdminForthAgentPlugin");
131
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "3.1.1",
3
+ "version": "3.1.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -80,6 +80,6 @@
80
80
  }
81
81
  ],
82
82
  "peerDependencies": {
83
- "adminforth": "^4.1.0"
83
+ "adminforth": "^4.7.3"
84
84
  }
85
85
  }