@eka-care/ekascribe-ts-sdk 1.4.56 → 1.4.58

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.
@@ -14,7 +14,6 @@ async function uploadSingleFile(uploadData, folderPath, file, fileName) {
14
14
  method: 'POST',
15
15
  body: formData,
16
16
  });
17
- console.log('upload single audio file response ', response);
18
17
  if (response.status === 204) {
19
18
  // S3 returns 204 No Content on successful upload
20
19
  return {
@@ -13,7 +13,6 @@ class AudioFileManager {
13
13
  this.totalInsertedSamples = 0;
14
14
  this.totalRawSamples = 0;
15
15
  this.totalRawFrames = 0;
16
- console.log(this.audioChunks, '35');
17
16
  }
18
17
  constructor() {
19
18
  /**
@@ -139,7 +138,6 @@ class AudioFileManager {
139
138
  * (+ the latest chunk , affects the length of chunks data struct)
140
139
  */
141
140
  updateAudioInfo(audioChunks) {
142
- console.log(audioChunks, 'update audio info');
143
141
  this.audioChunks.push(audioChunks);
144
142
  return this.audioChunks.length;
145
143
  }
@@ -152,15 +150,15 @@ class AudioFileManager {
152
150
  const workerResponse = event.data;
153
151
  switch (workerResponse.action) {
154
152
  case SHARED_WORKER_ACTION.CONFIGURE_AWS_SUCCESS: {
155
- console.log('AWS configured successfully in worker');
153
+ // Callback
156
154
  return;
157
155
  }
158
156
  case SHARED_WORKER_ACTION.CONFIGURE_AWS_ERROR: {
159
- console.error('Error configuring AWS in worker:', workerResponse.error);
157
+ // Callback
160
158
  return;
161
159
  }
162
160
  case SHARED_WORKER_ACTION.UPLOAD_FILE_WITH_WORKER_SUCCESS: {
163
- console.log('File uploaded successfully in worker:', workerResponse.response);
161
+ // Callback
164
162
  const { fileCount: fileName, chunkIndex, fileBlob, compressedAudioBuffer, } = workerResponse.requestBody;
165
163
  if (this.onProgressCallback && compressedAudioBuffer) {
166
164
  this.onProgressCallback({
@@ -291,6 +289,7 @@ class AudioFileManager {
291
289
  businessID: this.businessID,
292
290
  is_shared_worker: false,
293
291
  }).then((response) => {
292
+ // callback
294
293
  if (response.success) {
295
294
  this.successfulUploads.push(fileName);
296
295
  // update file status if file uploaded successfully
@@ -500,6 +499,7 @@ class AudioFileManager {
500
499
  this.audioChunks.forEach((chunk, index) => {
501
500
  const { fileName, fileBlob, status, audioFrames } = chunk;
502
501
  if (status != 'success') {
502
+ // callback
503
503
  this.sharedWorkerInstance?.port.postMessage({
504
504
  action: SHARED_WORKER_ACTION.UPLOAD_FILE_WITH_WORKER,
505
505
  payload: {
@@ -526,6 +526,7 @@ class AudioFileManager {
526
526
  this.audioChunks.forEach((chunk, index) => {
527
527
  const { fileName, fileBlob, status, audioFrames } = chunk;
528
528
  if (status != 'success') {
529
+ // callback
529
530
  let failedFileBlob;
530
531
  if (status === 'failure') {
531
532
  failedFileBlob = fileBlob;
@@ -575,7 +576,24 @@ class AudioFileManager {
575
576
  * Reset the upload state
576
577
  */
577
578
  resetFileManagerInstance() {
579
+ // Cancel all pending uploads
580
+ this.uploadPromises.forEach((promise) => {
581
+ // Note: Promises can't be cancelled, but we can ignore their results
582
+ promise.catch(() => { }); // Prevent unhandled rejections
583
+ });
584
+ // Terminate SharedWorker
585
+ if (this.sharedWorkerInstance) {
586
+ this.sharedWorkerInstance.port.close();
587
+ this.sharedWorkerInstance = null;
588
+ }
589
+ // Clear all state
578
590
  this.initialiseClassInstance();
591
+ // Reset additional properties not covered by initialiseClassInstance
592
+ this.txnID = '';
593
+ this.filePath = '';
594
+ this.businessID = '';
595
+ this.isAWSConfigured = false;
596
+ this.onProgressCallback = undefined;
579
597
  }
580
598
  }
581
599
  export default AudioFileManager;
@@ -340,6 +340,11 @@ class VadWebClient {
340
340
  * reset vadWeb instance
341
341
  */
342
342
  resetVadWebInstance() {
343
+ // Properly destroy MicVAD instance
344
+ if (this.micVad && typeof this.micVad.destroy === 'function') {
345
+ this.micVad.destroy();
346
+ }
347
+ // Reset VAD state
343
348
  this.vad_past = [];
344
349
  this.last_clip_index = 0;
345
350
  this.clip_points = [0];
@@ -347,7 +352,8 @@ class VadWebClient {
347
352
  this.noSpeechStartTime = null;
348
353
  this.lastWarningTime = null;
349
354
  this.recording_started = false;
350
- // TODO: will handle this - dont pass this callback - handle it properly - clear the error callback on client side on resetEkascribe
355
+ this.is_vad_loading = true; // Reset to initial state
356
+ this.micVad = {}; // Clear the instance
351
357
  if (EkaScribeStore.errorCallback) {
352
358
  EkaScribeStore.errorCallback({
353
359
  error_code: ERROR_CODE.SPEECH_DETECTED,
@@ -8,7 +8,6 @@ async function awsTranslateText({ source_language, target_language, content, })
8
8
  });
9
9
  try {
10
10
  const result = await translateClient.send(command);
11
- console.log(result, 'result');
12
11
  console.log('Translated text:', result.TranslatedText);
13
12
  }
14
13
  catch (error) {
@@ -10,7 +10,6 @@ export default async function fetchWrapper(url, options = {}, timeoutMs = API_TI
10
10
  try {
11
11
  // Set up timeout
12
12
  timeoutId = setTimeout(() => {
13
- console.log('request aborted due to timeout');
14
13
  controller.abort();
15
14
  }, timeoutMs);
16
15
  const newHeaders = new Headers(options.headers);
@@ -34,9 +33,6 @@ export default async function fetchWrapper(url, options = {}, timeoutMs = API_TI
34
33
  request: 'Request body: ' + JSON.stringify(options.body),
35
34
  });
36
35
  }
37
- if (response.status === 401 || response.status === 403) {
38
- console.log('unauthorized - fetch wrapper - SDK', response.status);
39
- }
40
36
  return response;
41
37
  }
42
38
  catch (error) {
package/dist/index.js CHANGED
@@ -52,14 +52,12 @@ class EkaScribe {
52
52
  value: void 0
53
53
  });
54
54
  this.audioFileManagerInstance = new AudioFileManager();
55
- console.log('%c Line:48 🥕 this.audioFileManagerInstance', 'color:#b03734', this.audioFileManagerInstance);
56
55
  EkaScribeStore.audioFileManagerInstance = this.audioFileManagerInstance;
57
56
  this.audioBufferInstance = new AudioBufferManager(SAMPLING_RATE, AUDIO_BUFFER_SIZE_IN_S);
58
- console.log('%c Line:50 🍇 this.audioBufferInstance', 'color:#fca650', this.audioBufferInstance);
59
57
  EkaScribeStore.audioBufferInstance = this.audioBufferInstance;
60
58
  this.vadInstance = new VadWebClient(PREF_CHUNK_LENGTH, DESP_CHUNK_LENGTH, MAX_CHUNK_LENGTH, FRAME_RATE);
61
59
  EkaScribeStore.vadInstance = this.vadInstance;
62
- console.log('%c Line:62 🍖 this.vadInstance', 'color:#2eafb0', this.vadInstance);
60
+ console.log('Initialising SDK: ', this.audioFileManagerInstance, this.audioBufferInstance, this.vadInstance);
63
61
  }
64
62
  // Static method to get the singleton instance with optional initialization
65
63
  static getInstance({ access_token, env, clientId, }) {
@@ -70,9 +68,8 @@ class EkaScribe {
70
68
  });
71
69
  if (!EkaScribe.instance) {
72
70
  EkaScribe.instance = new EkaScribe();
73
- console.log('EkaScribe.instance', EkaScribe.instance);
74
- // Initialize if params are provided
75
71
  }
72
+ console.log('EkaScribe.instance', EkaScribe.instance);
76
73
  return EkaScribe.instance;
77
74
  }
78
75
  // Method to reset the singleton instance (useful for testing)
@@ -80,7 +77,6 @@ class EkaScribe {
80
77
  EkaScribe.instance = null;
81
78
  }
82
79
  async getEkascribeConfig() {
83
- console.log('Fetching EkaScribe configuration...');
84
80
  const response = await getConfigV2();
85
81
  return response;
86
82
  }
@@ -90,13 +86,11 @@ class EkaScribe {
90
86
  });
91
87
  }
92
88
  async initTransaction(request) {
93
- console.log('Initializing transaction...');
94
89
  const initTransactionResponse = await initialiseTransaction(request);
95
90
  console.log(initTransactionResponse, 'initTransactionResponse');
96
91
  return initTransactionResponse;
97
92
  }
98
93
  async startRecording() {
99
- console.log('Starting recording...');
100
94
  const startResponse = await startVoiceRecording();
101
95
  console.log('%c Line:110 🍓 startResponse', 'color:#465975', startResponse);
102
96
  return startResponse;
@@ -108,25 +102,21 @@ class EkaScribe {
108
102
  this.vadInstance.destroyVad();
109
103
  }
110
104
  pauseRecording() {
111
- console.log('Pausing recording...');
112
105
  const pauseRecordingResponse = pauseVoiceRecording();
113
106
  console.log('%c Line:117 🍌 pauseRecordingResponse', 'color:#6ec1c2', pauseRecordingResponse);
114
107
  return pauseRecordingResponse;
115
108
  }
116
109
  resumeRecording() {
117
- console.log('Resuming recording...');
118
110
  const resumeRecordingResponse = resumeVoiceRecording();
119
111
  console.log('%c Line:124 🌶 resumeRecordingResponse', 'color:#33a5ff', resumeRecordingResponse);
120
112
  return resumeRecordingResponse;
121
113
  }
122
114
  async endRecording() {
123
- console.log('Ending recording...');
124
115
  const endRecordingResponse = await endVoiceRecording();
125
116
  console.log('%c Line:131 🍅 endRecordingResponse', 'color:#e41a6a', endRecordingResponse);
126
117
  return endRecordingResponse;
127
118
  }
128
119
  async retryUploadRecording({ force_commit }) {
129
- console.log('Retrying upload for failed files...');
130
120
  const retryUploadResponse = await retryUploadFailedFiles({ force_commit });
131
121
  console.log('%c Line:138 🍖 retryUploadResponse', 'color:#3f7cff', retryUploadResponse);
132
122
  return retryUploadResponse;
@@ -142,7 +132,6 @@ class EkaScribe {
142
132
  return patchTransactionResponse;
143
133
  }
144
134
  catch (error) {
145
- console.error('Error cancelling recording session:', error);
146
135
  return {
147
136
  code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
148
137
  message: `Failed to cancel recording session, ${error}`,
@@ -192,7 +181,6 @@ class EkaScribe {
192
181
  };
193
182
  }
194
183
  catch (error) {
195
- console.error('Error in transaction commit: ', error);
196
184
  return {
197
185
  error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
198
186
  status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
@@ -213,7 +201,6 @@ class EkaScribe {
213
201
  return getStatusResponse;
214
202
  }
215
203
  catch (error) {
216
- console.error('Error in fetching templates response: ', error);
217
204
  return {
218
205
  status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
219
206
  message: `Failed to fetch output templates, ${error}`,
@@ -228,7 +215,6 @@ class EkaScribe {
228
215
  return transactionsResponse;
229
216
  }
230
217
  catch (error) {
231
- console.error('Error cancelling recording session:', error);
232
218
  return {
233
219
  status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
234
220
  message: `Failed to fetch previous transactions, ${error}`,
@@ -246,6 +232,10 @@ class EkaScribe {
246
232
  }
247
233
  resetEkaScribe() {
248
234
  console.log(this.audioFileManagerInstance, this.audioBufferInstance, this.vadInstance, EkaScribeStore, 'before reset ekascribe');
235
+ // First, stop any ongoing operations
236
+ if (this.vadInstance) {
237
+ this.vadInstance.pauseVad(); // Stop recording first
238
+ }
249
239
  this.audioFileManagerInstance.resetFileManagerInstance();
250
240
  this.audioBufferInstance.resetBufferManagerInstance();
251
241
  this.vadInstance.resetVadWebInstance();
@@ -94,7 +94,6 @@ const endVoiceRecording = async () => {
94
94
  total_audio_files: audioFiles,
95
95
  };
96
96
  }
97
- console.log(audioFiles, 'audio files in commit api call, end recording - SDK');
98
97
  // call commit transaction api
99
98
  if (EkaScribeStore.sessionStatus[txnID].api?.status === 'stop' ||
100
99
  EkaScribeStore.sessionStatus[txnID].api?.status === 'commit') {
@@ -68,7 +68,7 @@ const initialiseTransaction = async (request) => {
68
68
  };
69
69
  }
70
70
  catch (err) {
71
- console.log('%c Line:102 🍇 initialiseTransaction err', 'color:#b03734', err);
71
+ console.error('%c Line:102 🍇 initialiseTransaction err', 'color:#b03734', err);
72
72
  return {
73
73
  error_code: ERROR_CODE.INTERNAL_SERVER_ERROR,
74
74
  status_code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
@@ -9,7 +9,6 @@ const pauseVoiceRecording = () => {
9
9
  if (!fileManagerInstance || !audioBufferInstance || !vadInstance) {
10
10
  throw new Error('Class instances are not initialized');
11
11
  }
12
- console.log(vadInstance, 'vad in pause recording');
13
12
  vadInstance.pauseVad();
14
13
  const txn_id = EkaScribeStore.txnID;
15
14
  EkaScribeStore.sessionStatus[txn_id] = {
@@ -7,7 +7,6 @@ const resumeVoiceRecording = () => {
7
7
  if (!vadInstance) {
8
8
  throw new Error('VAD instance is not initialized');
9
9
  }
10
- console.log(vadInstance, 'vad in resume recording');
11
10
  vadInstance.startVad();
12
11
  const txn_id = EkaScribeStore.txnID;
13
12
  EkaScribeStore.sessionStatus[txn_id] = {
@@ -11,7 +11,6 @@ const retryUploadFailedFiles = async ({ force_commit, }) => {
11
11
  const failedFiles = (await fileManagerInstance.retryFailedUploads()) || [];
12
12
  const audioInfo = fileManagerInstance?.audioChunks;
13
13
  const audioFiles = audioInfo.map((audio) => audio.fileName);
14
- console.log(failedFiles, 'failed files in retry upload recording - SDK');
15
14
  if (failedFiles.length > 0 && !force_commit) {
16
15
  return {
17
16
  error_code: ERROR_CODE.AUDIO_UPLOAD_FAILED,
@@ -15,15 +15,11 @@ const startVoiceRecording = async () => {
15
15
  };
16
16
  }
17
17
  await vadInstance?.initVad();
18
- console.log(vadInstance, 'vad in start recording');
19
18
  const micVad = vadInstance?.getMicVad();
20
- console.log(micVad, 'mic vad in start recording');
21
19
  const isVadLoading = vadInstance?.isVadLoading();
22
- console.log(isVadLoading, 'is vad loading in start recording');
23
20
  if (isVadLoading || !micVad || Object.keys(micVad).length === 0) {
24
21
  // retry initiating vad once and if still is in loading return error
25
22
  const reinitializeVadResponse = await vadInstance?.reinitializeVad();
26
- console.log(reinitializeVadResponse, 'reinitialize vad response');
27
23
  if (reinitializeVadResponse) {
28
24
  return {
29
25
  error_code: ERROR_CODE.VAD_NOT_INITIALIZED,
@@ -7,7 +7,6 @@ export async function postV1UploadAudioFiles({ audioFiles, audioFileNames, txn_i
7
7
  try {
8
8
  // Step 1: Get presigned URL
9
9
  const presignedUrlResponse = await postV1FileUpload({ txn_id, action });
10
- console.log('upload full audio -> presignedUrlResponse ', presignedUrlResponse);
11
10
  if (presignedUrlResponse.code !== 200) {
12
11
  return {
13
12
  error_code: ERROR_CODE.GET_PRESIGNED_URL_FAILED,
@@ -21,7 +20,6 @@ export async function postV1UploadAudioFiles({ audioFiles, audioFileNames, txn_i
21
20
  audioFileNames,
22
21
  presignedUrlResponse,
23
22
  });
24
- console.log('upload full audio -> uploadResponse ', uploadResponse);
25
23
  if (uploadResponse.code !== 200) {
26
24
  return {
27
25
  error_code: ERROR_CODE.AUDIO_UPLOAD_FAILED,
@@ -46,7 +44,6 @@ export async function postV1UploadAudioFiles({ audioFiles, audioFileNames, txn_i
46
44
  batch_s3_url,
47
45
  audio_file_names: audioFileNames,
48
46
  });
49
- console.log('upload full audio -> initTransactionResponse ', initTransactionResponse);
50
47
  if (initTransactionResponse.code >= 400) {
51
48
  return {
52
49
  error_code: ERROR_CODE.TXN_INIT_FAILED,
@@ -116,6 +116,9 @@ class EkaScribeStore {
116
116
  this._txnID = '';
117
117
  this._sessionBucketPath = '';
118
118
  this._sessionStatus = {};
119
+ // Clear callbacks
120
+ this._errorCallback = null;
121
+ this._userSpeechCallback = null;
119
122
  }
120
123
  }
121
124
  export default EkaScribeStore.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eka-care/ekascribe-ts-sdk",
3
- "version": "1.4.56",
3
+ "version": "1.4.58",
4
4
  "main": "dist/index.js",
5
5
  "repository": "git@github.com:eka-care/eka-js-sdk.git",
6
6
  "author": "Sanikagoyal28 <sanikagoyal9@gmail.com>",