@eka-care/ekascribe-ts-sdk 1.5.13 → 1.5.15
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/dist/audio-chunker/audio-file-manager.js +10 -0
- package/dist/audio-chunker/vad-web.js +33 -25
- package/dist/aws-services/upload-file-to-s3.js +1 -1
- package/dist/constants/enums.d.ts +2 -1
- package/dist/constants/enums.js +1 -0
- package/dist/constants/types.d.ts +2 -0
- package/dist/fetch-client/index.js +22 -15
- package/dist/index.d.ts +1 -2
- package/dist/index.js +0 -3
- package/dist/store/store.d.ts +1 -4
- package/dist/store/store.js +0 -14
- package/package.json +1 -1
|
@@ -170,6 +170,8 @@ class AudioFileManager {
|
|
|
170
170
|
message: 'Audioframes of chunk to store in IDB',
|
|
171
171
|
timestamp: new Date().toISOString(),
|
|
172
172
|
data: {
|
|
173
|
+
success: this.successfulUploads.length,
|
|
174
|
+
total: this.audioChunks.length,
|
|
173
175
|
fileName,
|
|
174
176
|
chunkData: compressedAudioBuffer,
|
|
175
177
|
},
|
|
@@ -213,6 +215,10 @@ class AudioFileManager {
|
|
|
213
215
|
msg: workerResponse.response.error,
|
|
214
216
|
details: workerResponse.response.errorCode,
|
|
215
217
|
},
|
|
218
|
+
data: {
|
|
219
|
+
fileName,
|
|
220
|
+
is_uploaded: false,
|
|
221
|
+
},
|
|
216
222
|
});
|
|
217
223
|
}
|
|
218
224
|
// store that audioFrames in audioChunks
|
|
@@ -358,6 +364,10 @@ class AudioFileManager {
|
|
|
358
364
|
msg: response.error || 'Upload failed',
|
|
359
365
|
details: response.errorCode,
|
|
360
366
|
},
|
|
367
|
+
data: {
|
|
368
|
+
fileName,
|
|
369
|
+
is_uploaded: false,
|
|
370
|
+
},
|
|
361
371
|
});
|
|
362
372
|
}
|
|
363
373
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MicVAD } from '@ricky0123/vad-web';
|
|
2
2
|
import { FRAME_SIZE, LONG_SILENCE_THRESHOLD, OUTPUT_FORMAT, PRE_SPEECH_PAD_FRAMES, SDK_STATUS_CODE, SHORT_SILENCE_THRESHOLD, } from '../constants/constant';
|
|
3
3
|
import EkaScribeStore from '../store/store';
|
|
4
|
-
import { ERROR_CODE } from '../constants/enums';
|
|
4
|
+
import { CALLBACK_TYPE, ERROR_CODE } from '../constants/enums';
|
|
5
5
|
class VadWebClient {
|
|
6
6
|
/**
|
|
7
7
|
* Class that handle Vad functions and manages audio chunk
|
|
@@ -134,7 +134,7 @@ class VadWebClient {
|
|
|
134
134
|
if (!this.recording_started)
|
|
135
135
|
return;
|
|
136
136
|
const now = Date.now();
|
|
137
|
-
const
|
|
137
|
+
const onEventCallback = EkaScribeStore.eventCallback;
|
|
138
138
|
const silenceThreshold = 10000; // 10 seconds
|
|
139
139
|
if (isSpeech === 0) {
|
|
140
140
|
if (this.noSpeechStartTime === null) {
|
|
@@ -147,11 +147,16 @@ class VadWebClient {
|
|
|
147
147
|
// Check if enough time has passed since the last warning (cooldown period)
|
|
148
148
|
if (this.lastWarningTime === null ||
|
|
149
149
|
now - this.lastWarningTime >= this.warningCooldownPeriod) {
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
if (onEventCallback) {
|
|
151
|
+
onEventCallback({
|
|
152
|
+
callback_type: CALLBACK_TYPE.VAD_AUDIO_STATUS,
|
|
153
|
+
status: 'info',
|
|
154
|
+
message: 'No audio detected for a while. Please talk or stop the recording if done.',
|
|
155
|
+
timestamp: new Date().toISOString(),
|
|
156
|
+
data: {
|
|
157
|
+
error_code: ERROR_CODE.NO_AUDIO_CAPTURE,
|
|
158
|
+
status_code: SDK_STATUS_CODE.AUDIO_ERROR,
|
|
159
|
+
},
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
162
|
this.lastWarningTime = now;
|
|
@@ -165,11 +170,16 @@ class VadWebClient {
|
|
|
165
170
|
// Reset timers when speech is detected
|
|
166
171
|
this.noSpeechStartTime = null;
|
|
167
172
|
this.lastWarningTime = null;
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
if (onEventCallback) {
|
|
174
|
+
onEventCallback({
|
|
175
|
+
callback_type: CALLBACK_TYPE.VAD_AUDIO_STATUS,
|
|
176
|
+
status: 'info',
|
|
177
|
+
message: 'Audio captured. Recording continues.',
|
|
178
|
+
timestamp: new Date().toISOString(),
|
|
179
|
+
data: {
|
|
180
|
+
error_code: ERROR_CODE.SPEECH_DETECTED,
|
|
181
|
+
status_code: SDK_STATUS_CODE.SUCCESS,
|
|
182
|
+
},
|
|
173
183
|
});
|
|
174
184
|
}
|
|
175
185
|
}
|
|
@@ -361,28 +371,26 @@ class VadWebClient {
|
|
|
361
371
|
this.recording_started = false;
|
|
362
372
|
this.is_vad_loading = true; // Reset to initial state
|
|
363
373
|
// this.micVad = {} as MicVAD; // Clear the instance
|
|
364
|
-
if (EkaScribeStore.errorCallback) {
|
|
365
|
-
EkaScribeStore.errorCallback({
|
|
366
|
-
error_code: ERROR_CODE.SPEECH_DETECTED,
|
|
367
|
-
status_code: SDK_STATUS_CODE.SUCCESS,
|
|
368
|
-
success_message: 'Audio captured. Recording continues.',
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
374
|
}
|
|
372
375
|
/**
|
|
373
376
|
* monitor initial audio capture within starting 4 seconds
|
|
374
377
|
*/
|
|
375
378
|
monitorAudioCapture() {
|
|
376
379
|
const audioBuffer = EkaScribeStore.audioBufferInstance;
|
|
377
|
-
const
|
|
380
|
+
const onEventCallback = EkaScribeStore.eventCallback;
|
|
378
381
|
setTimeout(() => {
|
|
379
382
|
if (audioBuffer && audioBuffer.getCurrentSampleLength() <= 0) {
|
|
380
383
|
this.micVad.pause();
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
384
|
+
if (onEventCallback) {
|
|
385
|
+
onEventCallback({
|
|
386
|
+
callback_type: CALLBACK_TYPE.VAD_AUDIO_STATUS,
|
|
387
|
+
status: 'info',
|
|
388
|
+
message: 'No audio is being captured. Please check your microphone.',
|
|
389
|
+
timestamp: new Date().toISOString(),
|
|
390
|
+
data: {
|
|
391
|
+
error_code: ERROR_CODE.NO_AUDIO_CAPTURE,
|
|
392
|
+
status_code: SDK_STATUS_CODE.AUDIO_ERROR,
|
|
393
|
+
},
|
|
386
394
|
});
|
|
387
395
|
}
|
|
388
396
|
return false;
|
|
@@ -34,7 +34,7 @@ const pushFileToS3 = async ({ fileBlob, fileName, txnID, businessID, is_shared_w
|
|
|
34
34
|
console.error('pushFilesToS3V2 error =>', err);
|
|
35
35
|
if (error.statusCode && error.statusCode >= 400) {
|
|
36
36
|
return {
|
|
37
|
-
error: `Expired token
|
|
37
|
+
error: `Expired token! ${err}`,
|
|
38
38
|
errorCode: 'ExpiredToken',
|
|
39
39
|
code: error.statusCode,
|
|
40
40
|
};
|
|
@@ -55,5 +55,6 @@ export declare enum CALLBACK_TYPE {
|
|
|
55
55
|
TEMPLATE_OPERATION_STATUS = "template_operation_status",
|
|
56
56
|
AUTHENTICATION_STATUS = "authentication_status",
|
|
57
57
|
NETWORK_STATUS = "network_status",
|
|
58
|
-
STORAGE_STATUS = "storage_status"
|
|
58
|
+
STORAGE_STATUS = "storage_status",
|
|
59
|
+
VAD_AUDIO_STATUS = "vad_audio_status"
|
|
59
60
|
}
|
package/dist/constants/enums.js
CHANGED
|
@@ -62,4 +62,5 @@ export var CALLBACK_TYPE;
|
|
|
62
62
|
CALLBACK_TYPE["AUTHENTICATION_STATUS"] = "authentication_status";
|
|
63
63
|
CALLBACK_TYPE["NETWORK_STATUS"] = "network_status";
|
|
64
64
|
CALLBACK_TYPE["STORAGE_STATUS"] = "storage_status";
|
|
65
|
+
CALLBACK_TYPE["VAD_AUDIO_STATUS"] = "vad_audio_status";
|
|
65
66
|
})(CALLBACK_TYPE || (CALLBACK_TYPE = {}));
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { GET_CLIENT_ID, GET_AUTH_TOKEN } from './helper';
|
|
2
2
|
import EkaScribeStore from '../store/store';
|
|
3
|
-
import {
|
|
4
|
-
import { SDK_STATUS_CODE } from '../constants/constant';
|
|
3
|
+
import { CALLBACK_TYPE } from '../constants/enums';
|
|
5
4
|
const API_TIMEOUT_MS = 10000;
|
|
6
5
|
export default async function fetchWrapper(url, options = {}, timeoutMs = API_TIMEOUT_MS) {
|
|
7
|
-
const
|
|
6
|
+
const onEventCallback = EkaScribeStore.eventCallback;
|
|
8
7
|
const controller = new AbortController();
|
|
9
8
|
let timeoutId = null;
|
|
10
9
|
try {
|
|
@@ -25,24 +24,32 @@ export default async function fetchWrapper(url, options = {}, timeoutMs = API_TI
|
|
|
25
24
|
signal: controller.signal,
|
|
26
25
|
credentials: 'include',
|
|
27
26
|
});
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
if (onEventCallback) {
|
|
28
|
+
onEventCallback({
|
|
29
|
+
callback_type: CALLBACK_TYPE.AUTHENTICATION_STATUS,
|
|
30
|
+
status: 'success',
|
|
31
|
+
message: 'Fetch wrapper response: ' + response.status,
|
|
32
|
+
timestamp: new Date().toISOString(),
|
|
33
|
+
data: {
|
|
34
|
+
request: 'Request body: ' + JSON.stringify(options.body),
|
|
35
|
+
response: 'Response body: ' + JSON.stringify(response),
|
|
36
|
+
},
|
|
34
37
|
});
|
|
35
38
|
}
|
|
36
39
|
return response;
|
|
37
40
|
}
|
|
38
41
|
catch (error) {
|
|
39
42
|
console.error(error, 'error in fetch wrapper - SDK');
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (onEventCallback) {
|
|
44
|
+
onEventCallback({
|
|
45
|
+
callback_type: CALLBACK_TYPE.AUTHENTICATION_STATUS,
|
|
46
|
+
status: 'error',
|
|
47
|
+
message: 'Fetch wrapper response: ' + error,
|
|
48
|
+
timestamp: new Date().toISOString(),
|
|
49
|
+
data: {
|
|
50
|
+
request: 'Request body: ' + JSON.stringify(options.body),
|
|
51
|
+
response: 'Error body: ' + JSON.stringify(error),
|
|
52
|
+
},
|
|
46
53
|
});
|
|
47
54
|
}
|
|
48
55
|
throw error;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TGetStatusResponse } from './api/transaction/get-voice-api-v3-status';
|
|
2
|
-
import { TEndRecordingResponse,
|
|
2
|
+
import { TEndRecordingResponse, TEventCallback, TGetTransactionHistoryResponse, TPatchTransactionRequest, TPatchVoiceApiV2ConfigRequest, TPatchVoiceApiV3StatusRequest, TPostTransactionResponse, TPostV1ConvertToTemplateRequest, TPostV1TemplateRequest, TPostV1TemplateSectionRequest, TPostV1UploadAudioFilesRequest, TStartRecordingRequest } from './constants/types';
|
|
3
3
|
import { TSearchSessionsByPatientRequest } from './utils/search-sessions-by-patient-name';
|
|
4
4
|
declare class EkaScribe {
|
|
5
5
|
private static instance;
|
|
@@ -41,7 +41,6 @@ declare class EkaScribe {
|
|
|
41
41
|
getFailedFiles(): string[];
|
|
42
42
|
getTotalAudioFiles(): import("./constants/types").TAudioChunksInfo[];
|
|
43
43
|
resetEkaScribe(): void;
|
|
44
|
-
onError(callback: TErrorCallback): void;
|
|
45
44
|
onUserSpeechCallback(callback: (isSpeech: boolean) => void): void;
|
|
46
45
|
onEventCallback(callback: TEventCallback): void;
|
|
47
46
|
configureVadConstants({ pref_length, desp_length, max_length, sr, frame_size, pre_speech_pad_frames, short_thsld, long_thsld, }: {
|
package/dist/index.js
CHANGED
|
@@ -263,9 +263,6 @@ class EkaScribe {
|
|
|
263
263
|
EkaScribeStore.resetStore();
|
|
264
264
|
console.log(this.audioFileManagerInstance, this.audioBufferInstance, this.vadInstance, EkaScribeStore, 'after reset ekascribe');
|
|
265
265
|
}
|
|
266
|
-
onError(callback) {
|
|
267
|
-
EkaScribeStore.errorCallback = callback;
|
|
268
|
-
}
|
|
269
266
|
onUserSpeechCallback(callback) {
|
|
270
267
|
EkaScribeStore.userSpeechCallback = callback;
|
|
271
268
|
}
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import AudioBufferManager from '../audio-chunker/audio-buffer-manager';
|
|
2
2
|
import AudioFileManager from '../audio-chunker/audio-file-manager';
|
|
3
3
|
import VadWebClient from '../audio-chunker/vad-web';
|
|
4
|
-
import {
|
|
4
|
+
import { TEventCallback, TSessionStatus } from '../constants/types';
|
|
5
5
|
declare class EkaScribeStore {
|
|
6
6
|
private static instance;
|
|
7
7
|
private _txnID;
|
|
@@ -10,7 +10,6 @@ declare class EkaScribeStore {
|
|
|
10
10
|
private _audioFileManagerInstance;
|
|
11
11
|
private _audioBufferInstance;
|
|
12
12
|
private _sessionStatus;
|
|
13
|
-
private _errorCallback;
|
|
14
13
|
private _userSpeechCallback;
|
|
15
14
|
private _eventCallback;
|
|
16
15
|
static getInstance(): EkaScribeStore;
|
|
@@ -26,8 +25,6 @@ declare class EkaScribeStore {
|
|
|
26
25
|
set sessionBucketPath(value: string);
|
|
27
26
|
get sessionStatus(): TSessionStatus;
|
|
28
27
|
set sessionStatus(value: TSessionStatus);
|
|
29
|
-
get errorCallback(): TErrorCallback | null;
|
|
30
|
-
set errorCallback(callback: TErrorCallback | null);
|
|
31
28
|
get userSpeechCallback(): ((isSpeech: boolean) => void) | null;
|
|
32
29
|
set userSpeechCallback(callback: ((isSpeech: boolean) => void) | null);
|
|
33
30
|
get eventCallback(): TEventCallback | null;
|
package/dist/store/store.js
CHANGED
|
@@ -36,12 +36,6 @@ class EkaScribeStore {
|
|
|
36
36
|
writable: true,
|
|
37
37
|
value: {}
|
|
38
38
|
});
|
|
39
|
-
Object.defineProperty(this, "_errorCallback", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: null
|
|
44
|
-
});
|
|
45
39
|
Object.defineProperty(this, "_userSpeechCallback", {
|
|
46
40
|
enumerable: true,
|
|
47
41
|
configurable: true,
|
|
@@ -103,13 +97,6 @@ class EkaScribeStore {
|
|
|
103
97
|
set sessionStatus(value) {
|
|
104
98
|
this._sessionStatus = value;
|
|
105
99
|
}
|
|
106
|
-
// Error Callback
|
|
107
|
-
get errorCallback() {
|
|
108
|
-
return this._errorCallback;
|
|
109
|
-
}
|
|
110
|
-
set errorCallback(callback) {
|
|
111
|
-
this._errorCallback = callback;
|
|
112
|
-
}
|
|
113
100
|
// User Speech Callback
|
|
114
101
|
get userSpeechCallback() {
|
|
115
102
|
return this._userSpeechCallback;
|
|
@@ -130,7 +117,6 @@ class EkaScribeStore {
|
|
|
130
117
|
this._sessionBucketPath = '';
|
|
131
118
|
this._sessionStatus = {};
|
|
132
119
|
// Clear callbacks
|
|
133
|
-
this._errorCallback = null;
|
|
134
120
|
this._userSpeechCallback = null;
|
|
135
121
|
this._eventCallback = null;
|
|
136
122
|
}
|