@eka-care/ekascribe-ts-sdk 2.0.13 → 2.0.14
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/README.md +102 -26
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1047,53 +1047,129 @@ Use this method to completely destroy the VAD instance and free up resources.
|
|
|
1047
1047
|
ekaScribe.destroyVad();
|
|
1048
1048
|
```
|
|
1049
1049
|
|
|
1050
|
+
### 8. Update Authentication Tokens
|
|
1051
|
+
|
|
1052
|
+
Use this method to update the access token when it expires (e.g., when you receive a 401 error).
|
|
1053
|
+
|
|
1054
|
+
```ts
|
|
1055
|
+
ekascribe.updateAuthTokens({ access_token: 'new_access_token' });
|
|
1056
|
+
```
|
|
1057
|
+
|
|
1058
|
+
**When to use:**
|
|
1059
|
+
|
|
1060
|
+
- When any API method returns `status_code: 401`
|
|
1061
|
+
- When `eventCallback` returns `error.code: 401` in `file_upload_status`
|
|
1062
|
+
- Before token expiration to prevent upload failures
|
|
1063
|
+
|
|
1050
1064
|
## Generic Callbacks
|
|
1051
1065
|
|
|
1052
1066
|
### 1. Event callback
|
|
1053
1067
|
|
|
1054
|
-
This
|
|
1055
|
-
|
|
1056
|
-
```ts
|
|
1057
|
-
|
|
1058
|
-
console.log('Event callback
|
|
1068
|
+
This callback provides information about SDK operations. Use it to monitor file uploads, transaction status, AWS configuration, and authentication errors.
|
|
1069
|
+
|
|
1070
|
+
```ts
|
|
1071
|
+
ekascribe.onEventCallback((eventData) => {
|
|
1072
|
+
console.log('Event callback:', eventData);
|
|
1073
|
+
|
|
1074
|
+
// Handle different callback types
|
|
1075
|
+
switch (eventData.callback_type) {
|
|
1076
|
+
case 'file_upload_status':
|
|
1077
|
+
// Track audio chunk upload progress
|
|
1078
|
+
console.log(`Uploaded ${eventData.data?.success}/${eventData.data?.total} chunks`);
|
|
1079
|
+
break;
|
|
1080
|
+
case 'transaction_status':
|
|
1081
|
+
// Monitor transaction lifecycle (init, stop, commit, cancel)
|
|
1082
|
+
console.log('Transaction update:', eventData.message);
|
|
1083
|
+
break;
|
|
1084
|
+
case 'aws_configure_status':
|
|
1085
|
+
// AWS S3 configuration status
|
|
1086
|
+
console.log('AWS config:', eventData.status);
|
|
1087
|
+
break;
|
|
1088
|
+
case 'authentication_status':
|
|
1089
|
+
// API authentication errors
|
|
1090
|
+
console.error('Auth error:', eventData.message);
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1059
1093
|
});
|
|
1060
1094
|
```
|
|
1061
1095
|
|
|
1062
|
-
- ####
|
|
1096
|
+
- #### Callback Structure:
|
|
1063
1097
|
|
|
1064
1098
|
```ts
|
|
1065
1099
|
{
|
|
1066
|
-
callback_type: '
|
|
1067
|
-
status: 'success' | 'error' | '
|
|
1068
|
-
message:
|
|
1100
|
+
callback_type: 'file_upload_status' | 'transaction_status' | 'aws_configure_status' | 'authentication_status',
|
|
1101
|
+
status: 'success' | 'error' | 'info',
|
|
1102
|
+
message: string,
|
|
1103
|
+
timestamp: string, // ISO timestamp
|
|
1069
1104
|
error?: {
|
|
1070
|
-
code:
|
|
1071
|
-
msg:
|
|
1072
|
-
details:
|
|
1105
|
+
code: number,
|
|
1106
|
+
msg: string,
|
|
1107
|
+
details: any
|
|
1073
1108
|
},
|
|
1074
1109
|
data?: {
|
|
1075
|
-
success
|
|
1076
|
-
total
|
|
1077
|
-
is_uploaded
|
|
1078
|
-
fileName
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
timestamp: '2024-01-15T10:30:45.123Z',
|
|
1083
|
-
metadata?: {
|
|
1084
|
-
txn_id: 'abc-123',
|
|
1085
|
-
chunk_index: 1
|
|
1110
|
+
success?: number, // Number of successfully uploaded chunks
|
|
1111
|
+
total?: number, // Total number of chunks
|
|
1112
|
+
is_uploaded?: boolean, // Whether current chunk uploaded successfully
|
|
1113
|
+
fileName?: string, // Current file name
|
|
1114
|
+
chunkData?: Uint8Array[], // Audio chunk data for current audiofile
|
|
1115
|
+
request?: any, // API request details
|
|
1116
|
+
response?: any // API response details
|
|
1086
1117
|
}
|
|
1087
1118
|
}
|
|
1088
1119
|
```
|
|
1089
1120
|
|
|
1121
|
+
- #### Callback Types Explained:
|
|
1122
|
+
|
|
1123
|
+
**`file_upload_status`** - Track audio chunk upload progress
|
|
1124
|
+
|
|
1125
|
+
Use this to monitor upload progress of audio chunks:
|
|
1126
|
+
|
|
1127
|
+
- `status: 'info'` - Audio chunk info
|
|
1128
|
+
|
|
1129
|
+
- `data.success`: Count of successfully uploaded chunks
|
|
1130
|
+
- `data.total`: Total chunks generated
|
|
1131
|
+
- `data.fileName`: Current chunk file name
|
|
1132
|
+
- `data.chunkData`: Audio data for current chunk
|
|
1133
|
+
|
|
1134
|
+
- `status: 'success'` - Chunk uploaded successfully
|
|
1135
|
+
|
|
1136
|
+
- `data.success`: Updated successful upload count
|
|
1137
|
+
- `data.total`: Total chunks
|
|
1138
|
+
- `data.is_uploaded`: true
|
|
1139
|
+
|
|
1140
|
+
- `status: 'error'` - Chunk upload failed
|
|
1141
|
+
|
|
1142
|
+
- `error.code`: HTTP error code
|
|
1143
|
+
- `error.msg`: Error message
|
|
1144
|
+
- `error.details`: Additional error details
|
|
1145
|
+
|
|
1146
|
+
- Status codes to handle:
|
|
1147
|
+
|
|
1148
|
+
If `error.code === 401`, it means your access token has expired. Update tokens immediately:
|
|
1149
|
+
|
|
1150
|
+
```ts
|
|
1151
|
+
ekascribe.onEventCallback((eventData) => {
|
|
1152
|
+
if (eventData.callback_type === 'file_upload_status' && eventData.status === 'error') {
|
|
1153
|
+
if (eventData.error?.code === 401) {
|
|
1154
|
+
// Token expired - update it
|
|
1155
|
+
sdkConfig.access_token = '<new_access_token>';
|
|
1156
|
+
ekascribe.updateAuthTokens({ access_token: sdkConfig.access_token });
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1090
1162
|
### 2. User speech callback
|
|
1091
1163
|
|
|
1092
|
-
|
|
1164
|
+
Triggered by Voice Activity Detection (VAD) when user starts or stops speaking.
|
|
1093
1165
|
|
|
1094
1166
|
```ts
|
|
1095
|
-
|
|
1096
|
-
|
|
1167
|
+
ekascribe.onUserSpeechCallback((isSpeech) => {
|
|
1168
|
+
if (isSpeech) {
|
|
1169
|
+
console.log('User started speaking');
|
|
1170
|
+
} else {
|
|
1171
|
+
console.log('User stopped speaking');
|
|
1172
|
+
}
|
|
1097
1173
|
});
|
|
1098
1174
|
```
|
|
1099
1175
|
|