@eka-care/ekascribe-ts-sdk 1.4.39

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.
Files changed (71) hide show
  1. package/README.md +437 -0
  2. package/dist/api/get-transaction-history.d.ts +5 -0
  3. package/dist/api/get-transaction-history.js +28 -0
  4. package/dist/api/get-voice-api-v2-config.d.ts +2 -0
  5. package/dist/api/get-voice-api-v2-config.js +26 -0
  6. package/dist/api/get-voice-api-v2-status.d.ts +51 -0
  7. package/dist/api/get-voice-api-v2-status.js +25 -0
  8. package/dist/api/get-voice-api-v3-status.d.ts +51 -0
  9. package/dist/api/get-voice-api-v3-status.js +26 -0
  10. package/dist/api/patch-transaction-status.d.ts +4 -0
  11. package/dist/api/patch-transaction-status.js +43 -0
  12. package/dist/api/post-cog-init.d.ts +3 -0
  13. package/dist/api/post-cog-init.js +15 -0
  14. package/dist/api/post-transaction-commit.d.ts +3 -0
  15. package/dist/api/post-transaction-commit.js +32 -0
  16. package/dist/api/post-transaction-init.d.ts +3 -0
  17. package/dist/api/post-transaction-init.js +40 -0
  18. package/dist/api/post-transaction-stop.d.ts +3 -0
  19. package/dist/api/post-transaction-stop.js +32 -0
  20. package/dist/audio-chunker/__tests__/audio-file-manager.test.d.ts +1 -0
  21. package/dist/audio-chunker/__tests__/audio-file-manager.test.js +5 -0
  22. package/dist/audio-chunker/audio-buffer-manager.d.ts +53 -0
  23. package/dist/audio-chunker/audio-buffer-manager.js +136 -0
  24. package/dist/audio-chunker/audio-file-manager.d.ts +96 -0
  25. package/dist/audio-chunker/audio-file-manager.js +579 -0
  26. package/dist/audio-chunker/vad-web.d.ts +90 -0
  27. package/dist/audio-chunker/vad-web.js +389 -0
  28. package/dist/aws-services/configure-aws.d.ts +5 -0
  29. package/dist/aws-services/configure-aws.js +13 -0
  30. package/dist/aws-services/get-files-s3.d.ts +10 -0
  31. package/dist/aws-services/get-files-s3.js +30 -0
  32. package/dist/aws-services/s3-retry-wrapper.d.ts +2 -0
  33. package/dist/aws-services/s3-retry-wrapper.js +38 -0
  34. package/dist/aws-services/translate-text-to-target-language.d.ts +6 -0
  35. package/dist/aws-services/translate-text-to-target-language.js +18 -0
  36. package/dist/aws-services/upload-file-to-s3.d.ts +13 -0
  37. package/dist/aws-services/upload-file-to-s3.js +48 -0
  38. package/dist/constants/constant.d.ts +27 -0
  39. package/dist/constants/constant.js +33 -0
  40. package/dist/constants/enums.d.ts +46 -0
  41. package/dist/constants/enums.js +51 -0
  42. package/dist/constants/setup-config.d.ts +14 -0
  43. package/dist/constants/setup-config.js +31 -0
  44. package/dist/constants/types.d.ts +224 -0
  45. package/dist/constants/types.js +1 -0
  46. package/dist/fetch-client/helper.d.ts +11 -0
  47. package/dist/fetch-client/helper.js +28 -0
  48. package/dist/fetch-client/index.d.ts +1 -0
  49. package/dist/fetch-client/index.js +36 -0
  50. package/dist/index.d.ts +60 -0
  51. package/dist/index.js +267 -0
  52. package/dist/main/end-recording.d.ts +3 -0
  53. package/dist/main/end-recording.js +141 -0
  54. package/dist/main/init-transaction.d.ts +3 -0
  55. package/dist/main/init-transaction.js +86 -0
  56. package/dist/main/pause-recording.d.ts +3 -0
  57. package/dist/main/pause-recording.js +59 -0
  58. package/dist/main/resume-recording.d.ts +3 -0
  59. package/dist/main/resume-recording.js +33 -0
  60. package/dist/main/retry-upload-recording.d.ts +5 -0
  61. package/dist/main/retry-upload-recording.js +69 -0
  62. package/dist/main/start-recording.d.ts +3 -0
  63. package/dist/main/start-recording.js +55 -0
  64. package/dist/shared-worker/s3-file-upload.d.ts +1 -0
  65. package/dist/shared-worker/s3-file-upload.js +109 -0
  66. package/dist/shared-worker/s3-file-upload.ts +126 -0
  67. package/dist/store/store.d.ts +35 -0
  68. package/dist/store/store.js +121 -0
  69. package/dist/utils/compress-mp3-audio.d.ts +2 -0
  70. package/dist/utils/compress-mp3-audio.js +24 -0
  71. package/package.json +53 -0
@@ -0,0 +1,3 @@
1
+ import { TPostCogResponse } from '../constants/types';
2
+ declare function postCogInit(): Promise<TPostCogResponse>;
3
+ export default postCogInit;
@@ -0,0 +1,15 @@
1
+ import fetchWrapper from '../fetch-client';
2
+ async function postCogInit() {
3
+ try {
4
+ const options = {
5
+ method: 'GET',
6
+ };
7
+ const respJson = await fetchWrapper(`https://cog.eka.care/credentials`, options);
8
+ const resp = await respJson.json();
9
+ return resp;
10
+ }
11
+ catch (error) {
12
+ throw error;
13
+ }
14
+ }
15
+ export default postCogInit;
@@ -0,0 +1,3 @@
1
+ import { TPostTransactionCommitRequest, TPostTransactionResponse } from '../constants/types';
2
+ declare function postTransactionCommit({ audioFiles, txnId, }: TPostTransactionCommitRequest): Promise<TPostTransactionResponse>;
3
+ export default postTransactionCommit;
@@ -0,0 +1,32 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ async function postTransactionCommit({ audioFiles, txnId, }) {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const raw = {
9
+ audio_files: audioFiles,
10
+ };
11
+ const options = {
12
+ method: 'POST',
13
+ headers,
14
+ body: JSON.stringify(raw),
15
+ };
16
+ const response = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/transaction/commit/${txnId}`, options);
17
+ let res = await response.json();
18
+ res = {
19
+ ...res,
20
+ code: response.status,
21
+ };
22
+ return res;
23
+ }
24
+ catch (error) {
25
+ console.log('%c Line:52 🥖 postTransactionInit -> error', 'color:#f5ce50', error);
26
+ return {
27
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
28
+ message: `Something went wrong! ${error}`,
29
+ };
30
+ }
31
+ }
32
+ export default postTransactionCommit;
@@ -0,0 +1,3 @@
1
+ import { TPostTransactionInitRequest, TPostTransactionResponse } from '../constants/types';
2
+ declare function postTransactionInit({ mode, txnId, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, }: TPostTransactionInitRequest): Promise<TPostTransactionResponse>;
3
+ export default postTransactionInit;
@@ -0,0 +1,40 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ async function postTransactionInit({ mode, txnId, s3Url, input_language, output_format_template, model_training_consent, auto_download, transfer, system_info, patient_details, }) {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const raw = {
9
+ mode,
10
+ s3_url: s3Url,
11
+ input_language,
12
+ output_format_template,
13
+ model_training_consent,
14
+ auto_download,
15
+ transfer,
16
+ system_info,
17
+ patient_details,
18
+ };
19
+ const options = {
20
+ method: 'POST',
21
+ headers,
22
+ body: JSON.stringify(raw),
23
+ };
24
+ const response = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/transaction/init/${txnId}`, options);
25
+ let res = await response.json();
26
+ res = {
27
+ ...res,
28
+ code: response.status,
29
+ };
30
+ return res;
31
+ }
32
+ catch (error) {
33
+ console.log('%c Line:52 🥖 postTransactionInit -> error', 'color:#f5ce50', error);
34
+ return {
35
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
36
+ message: `Something went wrong! ${error}`,
37
+ };
38
+ }
39
+ }
40
+ export default postTransactionInit;
@@ -0,0 +1,3 @@
1
+ import { TPostTransactionCommitRequest, TPostTransactionResponse } from '../constants/types';
2
+ declare function postTransactionStop({ txnId, audioFiles, }: TPostTransactionCommitRequest): Promise<TPostTransactionResponse>;
3
+ export default postTransactionStop;
@@ -0,0 +1,32 @@
1
+ import { SDK_STATUS_CODE } from '../constants/constant';
2
+ import fetchWrapper from '../fetch-client';
3
+ import { GET_EKA_V2RX_HOST_V2 } from '../fetch-client/helper';
4
+ async function postTransactionStop({ txnId, audioFiles, }) {
5
+ try {
6
+ const headers = new Headers();
7
+ headers.append('Content-Type', 'application/json');
8
+ const raw = {
9
+ audio_files: audioFiles,
10
+ };
11
+ const options = {
12
+ method: 'POST',
13
+ headers,
14
+ body: JSON.stringify(raw),
15
+ };
16
+ const response = await fetchWrapper(`${GET_EKA_V2RX_HOST_V2()}/transaction/stop/${txnId}`, options);
17
+ let res = await response.json();
18
+ res = {
19
+ ...res,
20
+ code: response.status,
21
+ };
22
+ return res;
23
+ }
24
+ catch (error) {
25
+ console.log('%c Line:52 🥖 postTransactionInit -> error', 'color:#f5ce50', error);
26
+ return {
27
+ code: SDK_STATUS_CODE.INTERNAL_SERVER_ERROR,
28
+ message: `Something went wrong! ${error}`,
29
+ };
30
+ }
31
+ }
32
+ export default postTransactionStop;
@@ -0,0 +1,5 @@
1
+ describe('AudioFileManager', () => {
2
+ let audioFileManager;
3
+ test('', () => { });
4
+ });
5
+ export {};
@@ -0,0 +1,53 @@
1
+ declare class AudioBufferManager {
2
+ private buffer;
3
+ private currentSampleLength;
4
+ private currentFrameLength;
5
+ private samplingRate;
6
+ private incrementalAllocationSize;
7
+ /**
8
+ * Class that creates an audio buffer to store frame data
9
+ * @param samplingRate - The sampling rate of the audio in Hz
10
+ * @param allocationTimeInSeconds - The size of each incremental allocation in seconds
11
+ */
12
+ constructor(samplingRate: number, allocationTimeInSeconds: number);
13
+ /**
14
+ * Append audio frame to the buffer
15
+ * @param audioFrame - Float32Array containing audio samples to append
16
+ * @returns The current position in the buffer after appending
17
+ */
18
+ append(audioFrame: Float32Array): number;
19
+ /**
20
+ * Get the current audio data as a Float32Array
21
+ */
22
+ getAudioData(): Float32Array;
23
+ /**
24
+ * Get the current length of audio data in samples
25
+ * @returns The number of samples currently in the buffer
26
+ */
27
+ getCurrentSampleLength(): number;
28
+ /**
29
+ * Get the current length of audio data in samples
30
+ * @returns The number of samples currently in the buffer
31
+ */
32
+ getCurrentFrameLength(): number;
33
+ /**
34
+ * Get the current length of audio data in seconds
35
+ * @returns The duration of audio currently in the buffer in seconds
36
+ */
37
+ getDurationInSeconds(): number;
38
+ /**
39
+ * Expand the buffer by allocating a new block of memory
40
+ * @private
41
+ */
42
+ private expandBuffer;
43
+ /**
44
+ * Calculate timestamps for an audio chunk
45
+ */
46
+ calculateChunkTimestamps(rawSamplesLength: number): {
47
+ start: string;
48
+ end: string;
49
+ };
50
+ resetBufferState(): void;
51
+ resetBufferManagerInstance(): void;
52
+ }
53
+ export default AudioBufferManager;
@@ -0,0 +1,136 @@
1
+ import { SAMPLING_RATE } from '../constants/constant';
2
+ class AudioBufferManager {
3
+ /**
4
+ * Class that creates an audio buffer to store frame data
5
+ * @param samplingRate - The sampling rate of the audio in Hz
6
+ * @param allocationTimeInSeconds - The size of each incremental allocation in seconds
7
+ */
8
+ constructor(samplingRate, allocationTimeInSeconds) {
9
+ Object.defineProperty(this, "buffer", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "currentSampleLength", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: 0
20
+ });
21
+ Object.defineProperty(this, "currentFrameLength", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: 0
26
+ });
27
+ Object.defineProperty(this, "samplingRate", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: 0
32
+ });
33
+ Object.defineProperty(this, "incrementalAllocationSize", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: 0
38
+ });
39
+ this.samplingRate = samplingRate;
40
+ // Calculate the size of each incremental allocation in samples
41
+ this.incrementalAllocationSize = Math.floor(samplingRate * allocationTimeInSeconds);
42
+ // Initialize buffer with the first allocation block
43
+ this.buffer = new Float32Array(this.incrementalAllocationSize);
44
+ this.currentSampleLength = 0;
45
+ }
46
+ /**
47
+ * Append audio frame to the buffer
48
+ * @param audioFrame - Float32Array containing audio samples to append
49
+ * @returns The current position in the buffer after appending
50
+ */
51
+ append(audioFrame) {
52
+ // Check if we need to allocate more memory
53
+ if (this.currentSampleLength + audioFrame.length > this.buffer.length) {
54
+ this.expandBuffer();
55
+ }
56
+ // Copy the new frame into the buffer
57
+ this.buffer.set(audioFrame, this.currentSampleLength);
58
+ this.currentSampleLength += audioFrame.length; // for 1 frame increase by 1024
59
+ this.currentFrameLength += 1; // for 1 frame increase by 1
60
+ return this.currentSampleLength;
61
+ }
62
+ /**
63
+ * Get the current audio data as a Float32Array
64
+ */
65
+ getAudioData() {
66
+ return this.buffer.slice(0, this.currentSampleLength);
67
+ }
68
+ /**
69
+ * Get the current length of audio data in samples
70
+ * @returns The number of samples currently in the buffer
71
+ */
72
+ getCurrentSampleLength() {
73
+ return this.currentSampleLength;
74
+ }
75
+ /**
76
+ * Get the current length of audio data in samples
77
+ * @returns The number of samples currently in the buffer
78
+ */
79
+ getCurrentFrameLength() {
80
+ return this.currentFrameLength;
81
+ }
82
+ /**
83
+ * Get the current length of audio data in seconds
84
+ * @returns The duration of audio currently in the buffer in seconds
85
+ */
86
+ getDurationInSeconds() {
87
+ return this.currentSampleLength / this.samplingRate;
88
+ }
89
+ /**
90
+ * Expand the buffer by allocating a new block of memory
91
+ * @private
92
+ */
93
+ expandBuffer() {
94
+ const newSize = this.buffer.length + this.incrementalAllocationSize;
95
+ const newBuffer = new Float32Array(newSize);
96
+ // Copy existing data to the new buffer
97
+ newBuffer.set(this.buffer, 0);
98
+ // Replace old buffer with new one
99
+ this.buffer = newBuffer;
100
+ }
101
+ /**
102
+ * Calculate timestamps for an audio chunk
103
+ */
104
+ calculateChunkTimestamps(rawSamplesLength) {
105
+ const start = rawSamplesLength / SAMPLING_RATE - this.getDurationInSeconds();
106
+ const end = start + this.getDurationInSeconds();
107
+ // Format start time as MM:SS.ffffff
108
+ const startMinutes = Math.floor(start / 60)
109
+ .toString()
110
+ .padStart(2, '0');
111
+ const startSeconds = (start % 60).toFixed(6).toString().padStart(2, '0');
112
+ const formattedStartTime = `${startMinutes}:${startSeconds}`;
113
+ // Format end time as MM:SS.ffffff
114
+ const endMinutes = Math.floor(end / 60)
115
+ .toString()
116
+ .padStart(2, '0');
117
+ const endSeconds = (end % 60).toFixed(6).toString().padStart(2, '0');
118
+ const formattedEndTime = `${endMinutes}:${endSeconds}`;
119
+ // Return timestamp object
120
+ return {
121
+ start: formattedStartTime,
122
+ end: formattedEndTime,
123
+ };
124
+ }
125
+ resetBufferState() {
126
+ // Zero out the existing buffer instead of allocating new memory
127
+ this.currentSampleLength = 0;
128
+ this.currentFrameLength = 0;
129
+ }
130
+ resetBufferManagerInstance() {
131
+ this.buffer = new Float32Array(this.incrementalAllocationSize);
132
+ this.currentSampleLength = 0;
133
+ this.currentFrameLength = 0;
134
+ }
135
+ }
136
+ export default AudioBufferManager;
@@ -0,0 +1,96 @@
1
+ import { TAudioChunksInfo, TFileUploadProgressCallback } from '../constants/types';
2
+ type TUploadAudioChunkParams = {
3
+ audioFrames: Float32Array;
4
+ fileName: string;
5
+ chunkIndex: number;
6
+ };
7
+ declare class AudioFileManager {
8
+ /**
9
+ * Class that handles uploading audio files to S3
10
+ * and downloading audio files for debugging
11
+ */
12
+ private txnID;
13
+ private filePath;
14
+ audioChunks: TAudioChunksInfo[];
15
+ private uploadPromises;
16
+ private successfulUploads;
17
+ private onProgressCallback?;
18
+ private totalRawSamples;
19
+ private totalRawFrames;
20
+ private totalInsertedSamples;
21
+ private totalInsertedFrames;
22
+ private businessID;
23
+ private isAWSConfigured;
24
+ private sharedWorkerInstance;
25
+ initialiseClassInstance(): void;
26
+ constructor();
27
+ /**
28
+ * Set basic file information
29
+ */
30
+ setSessionInfo({ sessionId, filePath, businessID, }: {
31
+ filePath: string;
32
+ businessID: string;
33
+ sessionId: string;
34
+ }): void;
35
+ getRawSampleDetails(): {
36
+ totalRawSamples: number;
37
+ totalRawFrames: number;
38
+ };
39
+ incrementTotalRawSamples(frames: Float32Array): void;
40
+ incrementInsertedSamples(samples: number, frames: number): void;
41
+ getInsertedSampleDetails(): {
42
+ totalInsertedSamples: number;
43
+ totalInsertedFrames: number;
44
+ };
45
+ /**
46
+ * Set callback for upload progress updates
47
+ */
48
+ setProgressCallback(callback: TFileUploadProgressCallback): void;
49
+ /**
50
+ * Update audio information array, this will update the audio chunks info
51
+ * (+ the latest chunk , affects the length of chunks data struct)
52
+ */
53
+ updateAudioInfo(audioChunks: TAudioChunksInfo): number;
54
+ createSharedWorkerInstance(): boolean;
55
+ private setupAWSConfiguration;
56
+ /**
57
+ * Upload a chunk of audio data to S3 in main thread
58
+ */
59
+ private uploadAudioChunkInMain;
60
+ /**
61
+ * Upload audio chunks to S3 in shared worker
62
+ */
63
+ private uploadAudioChunkInWorker;
64
+ uploadAudioToS3({ audioFrames, fileName, chunkIndex }: TUploadAudioChunkParams): Promise<void>;
65
+ private uploadAudioToS3WithWorker;
66
+ private uploadAudioToS3WithoutWorker;
67
+ /**
68
+ * Download audio as a file to the user's device (for debugging)
69
+ */
70
+ downloadAudio(audioBlob: Blob, fileName: string): void;
71
+ /**
72
+ * Wait for all upload promises to complete
73
+ */
74
+ waitForAllUploads(): Promise<void>;
75
+ /**
76
+ * Get list of successfully uploaded files
77
+ */
78
+ getSuccessfulUploads(): string[];
79
+ /**
80
+ * Get list of all failed files
81
+ */
82
+ getFailedUploads(): string[];
83
+ /**
84
+ * Get list of all audio chunks
85
+ */
86
+ getTotalAudioChunks(): TAudioChunksInfo[];
87
+ /**
88
+ * Retry uploading failed files
89
+ */
90
+ retryFailedUploads(): Promise<string[]>;
91
+ /**
92
+ * Reset the upload state
93
+ */
94
+ resetFileManagerInstance(): void;
95
+ }
96
+ export default AudioFileManager;