@adminforth/agent 1.43.11 → 1.43.12

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/build.log CHANGED
@@ -60,5 +60,5 @@ custom/speech_recognition_frontend/voiceActivityDetection.ts
60
60
  custom/speech_recognition_frontend/types/
61
61
  custom/speech_recognition_frontend/types/voice-activity-detection.d.ts
62
62
 
63
- sent 1,663,873 bytes received 883 bytes 3,329,512.00 bytes/sec
64
- total size is 1,659,858 speedup is 1.00
63
+ sent 1,664,000 bytes received 883 bytes 3,329,766.00 bytes/sec
64
+ total size is 1,659,985 speedup is 1.00
@@ -1,5 +1,6 @@
1
1
  const ctx = new AudioContext();
2
2
  let standbySource: AudioBufferSourceNode | null = null;
3
+ let isAudioUnlocked = false;
3
4
 
4
5
  const DEFAULT_PCM_SAMPLE_RATE = 24000;
5
6
  const DEFAULT_PCM_CHANNEL_COUNT = 1;
@@ -19,6 +20,10 @@ export type ChatResponseAudioPlayback = {
19
20
  };
20
21
 
21
22
  export async function unlockAudio() {
23
+ if (isAudioUnlocked) {
24
+ return;
25
+ }
26
+
22
27
  await ctx.resume();
23
28
 
24
29
  const buffer = ctx.createBuffer(1, 1, 22050);
@@ -27,11 +32,12 @@ export async function unlockAudio() {
27
32
  source.buffer = buffer;
28
33
  source.connect(ctx.destination);
29
34
  source.start(0);
35
+ isAudioUnlocked = true;
30
36
  }
31
37
 
32
38
  export async function startStandByAudio() {
33
39
  const response = await fetch(
34
- `/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`
40
+ `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH}/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`
35
41
  );
36
42
 
37
43
  const arrayBuffer = await response.arrayBuffer();
@@ -16,7 +16,6 @@ import {
16
16
  import type { ChatResponseAudioPlayback } from './agentAudio/utils';
17
17
 
18
18
  let isStandByAudioPlaying = false;
19
- let isAudioUnlocked = false;
20
19
  async function playStandByAudio() {
21
20
  isStandByAudioPlaying = true;
22
21
  await startStandByAudio();
@@ -47,10 +46,6 @@ export const useAgentAudio = defineStore('agentAudio', () => {
47
46
  }
48
47
 
49
48
  async function sendAudioToServerAndHandleResponse(blob: Blob) {
50
- if (!isAudioUnlocked) {
51
- await unlockAudio();
52
- isAudioUnlocked = true;
53
- }
54
49
  currentAbortController = new AbortController();
55
50
  wasAudioResponseReceived = false;
56
51
  const formData = new FormData();
@@ -264,7 +259,8 @@ export const useAgentAudio = defineStore('agentAudio', () => {
264
259
  stopGenerationAndAudio,
265
260
  stopCurrentAudioPlayback,
266
261
  playBeep,
267
- agentAudioMode
262
+ agentAudioMode,
263
+ unlockAudio,
268
264
  };
269
265
 
270
266
  });
@@ -55,6 +55,7 @@ const { sendAudioToServerAndHandleResponse } = agentAudio;
55
55
  const { stopGenerationAndAudio } = agentAudio;
56
56
  const { stopCurrentAudioPlayback } = agentAudio;
57
57
  const { agentAudioMode } = storeToRefs(agentAudio);
58
+ const { unlockAudio } = agentAudio;
58
59
  const microphoneButtonMode = ref<'off' | 'listen' | 'transcribing' | 'generating'>('off');
59
60
  const showAudioWavesAnimation = ref(false);
60
61
  const audioAmplitude = ref(0);
@@ -90,6 +91,7 @@ watch(agentAudioMode, async (newVal) => {
90
91
  } else if (newVal === 'readyToRespond') {
91
92
  if(isAudioChatMode.value) {
92
93
  microphoneButtonMode.value = 'listen';
94
+ await unlockAudio();
93
95
  await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
94
96
  agentAudio.playBeep(1000);
95
97
  } else {
@@ -114,6 +116,7 @@ function toggleChatMode() {
114
116
  }
115
117
 
116
118
  async function onStartRecording() {
119
+ await unlockAudio();
117
120
  await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
118
121
  microphoneButtonMode.value = 'listen';
119
122
  agentAudio.playBeep(1000);
@@ -1,5 +1,6 @@
1
1
  const ctx = new AudioContext();
2
2
  let standbySource: AudioBufferSourceNode | null = null;
3
+ let isAudioUnlocked = false;
3
4
 
4
5
  const DEFAULT_PCM_SAMPLE_RATE = 24000;
5
6
  const DEFAULT_PCM_CHANNEL_COUNT = 1;
@@ -19,6 +20,10 @@ export type ChatResponseAudioPlayback = {
19
20
  };
20
21
 
21
22
  export async function unlockAudio() {
23
+ if (isAudioUnlocked) {
24
+ return;
25
+ }
26
+
22
27
  await ctx.resume();
23
28
 
24
29
  const buffer = ctx.createBuffer(1, 1, 22050);
@@ -27,11 +32,12 @@ export async function unlockAudio() {
27
32
  source.buffer = buffer;
28
33
  source.connect(ctx.destination);
29
34
  source.start(0);
35
+ isAudioUnlocked = true;
30
36
  }
31
37
 
32
38
  export async function startStandByAudio() {
33
39
  const response = await fetch(
34
- `/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`
40
+ `${import.meta.env.VITE_ADMINFORTH_PUBLIC_PATH}/plugins/AdminForthAgentPlugin/agentAudio/agent-processing.mp3`
35
41
  );
36
42
 
37
43
  const arrayBuffer = await response.arrayBuffer();
@@ -16,7 +16,6 @@ import {
16
16
  import type { ChatResponseAudioPlayback } from './agentAudio/utils';
17
17
 
18
18
  let isStandByAudioPlaying = false;
19
- let isAudioUnlocked = false;
20
19
  async function playStandByAudio() {
21
20
  isStandByAudioPlaying = true;
22
21
  await startStandByAudio();
@@ -47,10 +46,6 @@ export const useAgentAudio = defineStore('agentAudio', () => {
47
46
  }
48
47
 
49
48
  async function sendAudioToServerAndHandleResponse(blob: Blob) {
50
- if (!isAudioUnlocked) {
51
- await unlockAudio();
52
- isAudioUnlocked = true;
53
- }
54
49
  currentAbortController = new AbortController();
55
50
  wasAudioResponseReceived = false;
56
51
  const formData = new FormData();
@@ -264,7 +259,8 @@ export const useAgentAudio = defineStore('agentAudio', () => {
264
259
  stopGenerationAndAudio,
265
260
  stopCurrentAudioPlayback,
266
261
  playBeep,
267
- agentAudioMode
262
+ agentAudioMode,
263
+ unlockAudio,
268
264
  };
269
265
 
270
266
  });
@@ -55,6 +55,7 @@ const { sendAudioToServerAndHandleResponse } = agentAudio;
55
55
  const { stopGenerationAndAudio } = agentAudio;
56
56
  const { stopCurrentAudioPlayback } = agentAudio;
57
57
  const { agentAudioMode } = storeToRefs(agentAudio);
58
+ const { unlockAudio } = agentAudio;
58
59
  const microphoneButtonMode = ref<'off' | 'listen' | 'transcribing' | 'generating'>('off');
59
60
  const showAudioWavesAnimation = ref(false);
60
61
  const audioAmplitude = ref(0);
@@ -90,6 +91,7 @@ watch(agentAudioMode, async (newVal) => {
90
91
  } else if (newVal === 'readyToRespond') {
91
92
  if(isAudioChatMode.value) {
92
93
  microphoneButtonMode.value = 'listen';
94
+ await unlockAudio();
93
95
  await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
94
96
  agentAudio.playBeep(1000);
95
97
  } else {
@@ -114,6 +116,7 @@ function toggleChatMode() {
114
116
  }
115
117
 
116
118
  async function onStartRecording() {
119
+ await unlockAudio();
117
120
  await requestMicAndStartVAD(saidSomething, stopRecording, onAnySound);
118
121
  microphoneButtonMode.value = 'listen';
119
122
  agentAudio.playBeep(1000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "1.43.11",
3
+ "version": "1.43.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",