@vocalstack/js-sdk 1.0.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/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/RestApi.d.ts +21 -0
- package/dist/RestApi.js +93 -0
- package/dist/VocalStackApi.d.ts +19 -0
- package/dist/VocalStackApi.js +50 -0
- package/dist/WebsocketApi.d.ts +38 -0
- package/dist/WebsocketApi.js +156 -0
- package/dist/apis/Billing.d.ts +59 -0
- package/dist/apis/Billing.js +21 -0
- package/dist/apis/LiveTranscription.d.ts +58 -0
- package/dist/apis/LiveTranscription.js +55 -0
- package/dist/apis/Polyglot.d.ts +113 -0
- package/dist/apis/Polyglot.js +68 -0
- package/dist/apis/Security.d.ts +25 -0
- package/dist/apis/Security.js +35 -0
- package/dist/apis/Transcriptions.d.ts +61 -0
- package/dist/apis/Transcriptions.js +43 -0
- package/dist/apis/UrlTranscription.d.ts +59 -0
- package/dist/apis/UrlTranscription.js +53 -0
- package/dist/apis/index.d.ts +6 -0
- package/dist/apis/index.js +22 -0
- package/dist/esm/RestApi.d.ts +21 -0
- package/dist/esm/RestApi.js +89 -0
- package/dist/esm/VocalStackApi.d.ts +19 -0
- package/dist/esm/VocalStackApi.js +46 -0
- package/dist/esm/WebsocketApi.d.ts +38 -0
- package/dist/esm/WebsocketApi.js +146 -0
- package/dist/esm/apis/Billing.d.ts +59 -0
- package/dist/esm/apis/Billing.js +17 -0
- package/dist/esm/apis/LiveTranscription.d.ts +58 -0
- package/dist/esm/apis/LiveTranscription.js +51 -0
- package/dist/esm/apis/Polyglot.d.ts +113 -0
- package/dist/esm/apis/Polyglot.js +64 -0
- package/dist/esm/apis/Security.d.ts +25 -0
- package/dist/esm/apis/Security.js +31 -0
- package/dist/esm/apis/Transcriptions.d.ts +61 -0
- package/dist/esm/apis/Transcriptions.js +39 -0
- package/dist/esm/apis/UrlTranscription.d.ts +59 -0
- package/dist/esm/apis/UrlTranscription.js +49 -0
- package/dist/esm/apis/index.d.ts +6 -0
- package/dist/esm/apis/index.js +6 -0
- package/dist/esm/generics.zod.d.ts +77 -0
- package/dist/esm/generics.zod.js +45 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/generics.zod.d.ts +77 -0
- package/dist/generics.zod.js +48 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
VocalStack Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2024 VocalStack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use the Software solely in connection with the VocalStack service, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
## Usage Limitations
|
|
8
|
+
|
|
9
|
+
1. **Compliance with Terms of Service**: The Software must be used in a manner that does not violate the VocalStack terms of service ([https://www.vocalstack.com/terms-of-service](https://www.vocalstack.com/terms-of-service)).
|
|
10
|
+
|
|
11
|
+
2. **Commercial Use Allowed**: The Licensed Work may be used for commercial purposes, provided the user has a valid API key and an active subscription to the VocalStack service. Unauthorized use is strictly prohibited.
|
|
12
|
+
|
|
13
|
+
3. **Modification and Contributions**: You may view and modify the Licensed Work for internal use only. Contributions to the Licensed Work may be made through pull requests. By submitting a contribution, you agree to assign the rights of the contribution to VocalStack.
|
|
14
|
+
|
|
15
|
+
4. **Redistribution Allowed**: Redistribution of the Software, in whole or in part, whether modified or unmodified, is permitted, provided that it does not violate the company's terms of service.
|
|
16
|
+
|
|
17
|
+
5. **Termination**: VocalStack reserves the right to terminate your access to and use of the Software at any time if you fail to comply with these terms.
|
|
18
|
+
|
|
19
|
+
## Disclaimer
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[](https://vocalstack.com)
|
|
2
|
+
|
|
3
|
+
> VocalStack is a platform that can be used for building voice applications. See more at [https://vocalstack.com](vocalstack.com).
|
|
4
|
+
|
|
5
|
+
This repository contains the official VocalStack SDK for JavaScript. It provides a simple way
|
|
6
|
+
to interact with the [VocalStack API](https://vocalstack.com/api).
|
|
7
|
+
Most notably, it helps implement asynchronous bidirectional communication
|
|
8
|
+
such as live stream transcriptions in just a few lines of code.
|
|
9
|
+
This SDK will work in both Node.js and the browser.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Installation
|
|
13
|
+
|
|
14
|
+
Before you start, install the VocalStack JavaScript SDK using your preferred Node package manager, such as npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @vocalstack/js-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Also make sure to have a [VocalStack account](https://vocalstack.com) and an API key, which you can generate
|
|
21
|
+
at https://vocalstack.com/dashboard/api-keys.
|
|
22
|
+
There is a free tier available, so you can start experimenting right away.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Quick Example
|
|
26
|
+
|
|
27
|
+
Here is a quick example of how to use the SDK to transcribe a file from a URL:
|
|
28
|
+
```javascript
|
|
29
|
+
import { UrlTranscription } from '@vocalstack/js-sdk';
|
|
30
|
+
|
|
31
|
+
const sdk = new UrlTranscription({ apiKey: 'YOUR-API-KEY' });
|
|
32
|
+
const transcription = await sdk.connect({
|
|
33
|
+
url: 'http://example.com/files/meaningless.mp3',
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
transcription.start();
|
|
37
|
+
|
|
38
|
+
// This will print the transcription data as it comes in
|
|
39
|
+
transcription.onData(console.log);
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
{
|
|
43
|
+
status: 'processing',
|
|
44
|
+
data: {
|
|
45
|
+
id: 'd1e7b3b0-7b3b-4b3b-8b3b-0b3b7b3b3b3b',
|
|
46
|
+
operation: 'transcription-prerecorded',
|
|
47
|
+
progress: 0.1,
|
|
48
|
+
timeline: [
|
|
49
|
+
{
|
|
50
|
+
start: 0,
|
|
51
|
+
end: 7.52,
|
|
52
|
+
text: 'Meaningless, meaningless, says the teacher, utterly meaningless, everything is meaningless.',
|
|
53
|
+
language: 'en',
|
|
54
|
+
translations: { ... },
|
|
55
|
+
},
|
|
56
|
+
...
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# Documentation Index
|
|
65
|
+
|
|
66
|
+
- [Transcribe Audio from URL](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcribe-audio-from-url-to-text.md):
|
|
67
|
+
Transcribe speech from pre-recorded audio in a URL to plain text. Major file formats are supported, including MP3, WAV, FLAC, and OGG.
|
|
68
|
+
|
|
69
|
+
- [Transcribe from a Microphone or LiveStream](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcribe-from-a-microphone-or-live-stream.md):
|
|
70
|
+
Transcribe live speech from a microphone or live stream. Integrate with Polyglot to create a public shareable link for the transcription which users can read in any language.
|
|
71
|
+
|
|
72
|
+
- [Transcribe and Present a Polyglot Session](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcribe-and-present-a-polyglot-session.md):
|
|
73
|
+
Create a session that can be used to broadcast a live transcription via a public shareable link. Users can read live transcriptions in their preferred language, and even past transcriptions when your session is inactive.
|
|
74
|
+
|
|
75
|
+
- [Translate a Transcription](https://github.com/vocalstack/js-sdk/blob/main/documentation/translate-transcription-to-another-language.md):
|
|
76
|
+
Translate transcribed text to another language. This can be done for any transcription, including prerecorded transcriptions, live transcriptions or Polyglot session transcriptions.
|
|
77
|
+
|
|
78
|
+
- [Get Transcription Data](https://github.com/vocalstack/js-sdk/blob/main/documentation/get-transcription-data.md):
|
|
79
|
+
Get data from pending or completed transcriptions. This includes the transcription timeline, key words, summary, and paragraph segments.
|
|
80
|
+
|
|
81
|
+
- [Client Side Authentication Tokens](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcribe-on-the-front-end-with-auth-tokens.md):
|
|
82
|
+
Create a temporary authentication token for client side requests. Safely implement API requests in web browsers without exposing your API keys.
|
|
83
|
+
|
|
84
|
+
- [Transcription Sessions](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcription-sessions.md):
|
|
85
|
+
Monitor and manage transcription state with sessions. Using sessions you can reconnect to a previously created asynchronous connection.
|
|
86
|
+
|
|
87
|
+
- [Transcription Request and Response](https://github.com/vocalstack/js-sdk/blob/main/documentation/transcription-request-and-response.md):
|
|
88
|
+
Common request options and responses for all transcription operations. Use options to configure the transcription settings.
|
|
89
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type ApiResponse<T> = {
|
|
2
|
+
status: 'waiting' | 'processing' | 'done' | 'error';
|
|
3
|
+
data?: null | T;
|
|
4
|
+
success: boolean;
|
|
5
|
+
error?: string;
|
|
6
|
+
};
|
|
7
|
+
export type RequestOptions = RequestInit & {
|
|
8
|
+
json?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare class RestApi {
|
|
11
|
+
private apiServer;
|
|
12
|
+
private headers;
|
|
13
|
+
constructor(apiServer: string, headers: Record<string, string>);
|
|
14
|
+
get<T>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
15
|
+
post<T>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
16
|
+
put<T>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
17
|
+
patch<T>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
18
|
+
delete<T>(path: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
19
|
+
private apiCall;
|
|
20
|
+
private respond;
|
|
21
|
+
}
|
package/dist/RestApi.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.RestApi = void 0;
|
|
24
|
+
class RestApi {
|
|
25
|
+
constructor(apiServer, headers) {
|
|
26
|
+
this.apiServer = apiServer;
|
|
27
|
+
this.headers = headers;
|
|
28
|
+
}
|
|
29
|
+
get(path, options) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return this.apiCall('GET', path, options);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
post(path, options) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return this.apiCall('POST', path, options);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
put(path, options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return this.apiCall('PUT', path, options);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
patch(path, options) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
return this.apiCall('PATCH', path, options);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
delete(path, options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
return this.apiCall('DELETE', path, options);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
apiCall(method, path, options) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
const fixedPath = path.startsWith('/') ? path.slice(1) : path;
|
|
58
|
+
const _a = options || {}, { json } = _a, fetchOptions = __rest(_a, ["json"]);
|
|
59
|
+
const body = json ? JSON.stringify(json) : undefined;
|
|
60
|
+
const headers = Object.assign({}, this.headers);
|
|
61
|
+
if (body) {
|
|
62
|
+
headers['Content-Type'] = 'application/json';
|
|
63
|
+
}
|
|
64
|
+
const response = yield fetch(`${this.apiServer}/${fixedPath}`, Object.assign({ method,
|
|
65
|
+
headers,
|
|
66
|
+
body }, fetchOptions));
|
|
67
|
+
return this.respond(response);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
console.log(e);
|
|
71
|
+
return {
|
|
72
|
+
success: false,
|
|
73
|
+
error: String(e),
|
|
74
|
+
status: 'error',
|
|
75
|
+
data: undefined,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
respond(response) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const success = response.ok;
|
|
83
|
+
const json = success ? yield response.json() : undefined;
|
|
84
|
+
const data = Object.assign({ success, error: !success ? response.statusText : undefined }, json);
|
|
85
|
+
if ((data === null || data === void 0 ? void 0 : data.status) === 'error') {
|
|
86
|
+
data.error = 'An error occurred while processing the request.';
|
|
87
|
+
data.success = false;
|
|
88
|
+
}
|
|
89
|
+
return data;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.RestApi = RestApi;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ApiResponse, RestApi } from './RestApi';
|
|
3
|
+
import { WebSocketsApi } from './WebsocketApi';
|
|
4
|
+
import { Configuration } from './generics.zod';
|
|
5
|
+
export declare const VOCALSTACK_API_SERVER = "https://api.vocalstack.com";
|
|
6
|
+
export declare class VocalStackApi {
|
|
7
|
+
protected headers: Record<string, string>;
|
|
8
|
+
protected apiServer: string;
|
|
9
|
+
constructor(config: Configuration);
|
|
10
|
+
protected _rest(): RestApi;
|
|
11
|
+
protected _ws(): WebSocketsApi;
|
|
12
|
+
private buildConfiguration;
|
|
13
|
+
protected withValidation(zodType: z.ZodType, data: unknown): {
|
|
14
|
+
success: boolean;
|
|
15
|
+
badResponse: ApiResponse<null> | undefined;
|
|
16
|
+
data: any;
|
|
17
|
+
};
|
|
18
|
+
protected buildQueryString(params: Record<string, undefined | string | number | boolean>): string;
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VocalStackApi = exports.VOCALSTACK_API_SERVER = void 0;
|
|
4
|
+
const RestApi_1 = require("./RestApi");
|
|
5
|
+
const WebsocketApi_1 = require("./WebsocketApi");
|
|
6
|
+
const generics_zod_1 = require("./generics.zod");
|
|
7
|
+
exports.VOCALSTACK_API_SERVER = 'https://api.vocalstack.com';
|
|
8
|
+
class VocalStackApi {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
const { apiServer, headers } = this.buildConfiguration(config);
|
|
11
|
+
this.apiServer = apiServer;
|
|
12
|
+
this.headers = headers;
|
|
13
|
+
}
|
|
14
|
+
_rest() {
|
|
15
|
+
return new RestApi_1.RestApi(this.apiServer, this.headers);
|
|
16
|
+
}
|
|
17
|
+
_ws() {
|
|
18
|
+
return new WebsocketApi_1.WebSocketsApi(this.apiServer, this.headers);
|
|
19
|
+
}
|
|
20
|
+
buildConfiguration(config) {
|
|
21
|
+
const parsedConfiguration = generics_zod_1.zConfiguration.safeParse(config);
|
|
22
|
+
if (!parsedConfiguration.success) {
|
|
23
|
+
throw new Error(parsedConfiguration.error.errors.map((err) => err.message).join(', '));
|
|
24
|
+
}
|
|
25
|
+
const data = parsedConfiguration.data;
|
|
26
|
+
return Object.assign(Object.assign({}, data), { apiServer: data.apiServer || exports.VOCALSTACK_API_SERVER, headers: Object.assign(Object.assign({}, data.headers), { authorization: data.authToken ? `Bearer ${data.authToken}` : data.apiKey || '' }) });
|
|
27
|
+
}
|
|
28
|
+
withValidation(zodType, data) {
|
|
29
|
+
const parsedRequest = zodType.safeParse(data);
|
|
30
|
+
return {
|
|
31
|
+
success: parsedRequest.success,
|
|
32
|
+
badResponse: parsedRequest.success
|
|
33
|
+
? undefined
|
|
34
|
+
: {
|
|
35
|
+
status: 'error',
|
|
36
|
+
data: null,
|
|
37
|
+
success: false,
|
|
38
|
+
error: parsedRequest.error.errors.map((err) => err.message).join(', '),
|
|
39
|
+
},
|
|
40
|
+
data: parsedRequest.success ? parsedRequest.data : null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
buildQueryString(params) {
|
|
44
|
+
return Object.entries(params)
|
|
45
|
+
.filter(([, value]) => value !== undefined && value !== null && value !== '')
|
|
46
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
47
|
+
.join('&');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.VocalStackApi = VocalStackApi;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface WebsocketRequestOptions {
|
|
2
|
+
path: string;
|
|
3
|
+
mustStart?: boolean;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export type WebsocketConnection<ResponseType> = {
|
|
7
|
+
start: () => void;
|
|
8
|
+
close: () => void;
|
|
9
|
+
onClose: (callback: () => void) => void;
|
|
10
|
+
onData: (callback: (ev: ResponseType) => void) => void;
|
|
11
|
+
};
|
|
12
|
+
export type DuplexWebsocketConnection<RequestType, ResponseType> = WebsocketConnection<ResponseType> & {
|
|
13
|
+
stop: () => void;
|
|
14
|
+
sendBuffer: (message: RequestType) => void;
|
|
15
|
+
};
|
|
16
|
+
export declare class WebSocketsApi {
|
|
17
|
+
private apiServer;
|
|
18
|
+
private headers;
|
|
19
|
+
private socket;
|
|
20
|
+
private WebSocketClass;
|
|
21
|
+
private started;
|
|
22
|
+
private session;
|
|
23
|
+
constructor(apiServer: string, headers: Record<string, string>);
|
|
24
|
+
private makeSocketConnection;
|
|
25
|
+
connect<ResponseType>(options: WebsocketRequestOptions): Promise<{
|
|
26
|
+
start: () => void;
|
|
27
|
+
close: () => void;
|
|
28
|
+
onClose: (callback: () => void) => void;
|
|
29
|
+
onData: (callback: (ev: ResponseType) => void) => void;
|
|
30
|
+
}>;
|
|
31
|
+
connectDuplex<RequestType, ResponseType>(options: WebsocketRequestOptions): Promise<DuplexWebsocketConnection<RequestType, ResponseType>>;
|
|
32
|
+
private returnConnection;
|
|
33
|
+
private returnDuplexConnection;
|
|
34
|
+
private sendBuffer;
|
|
35
|
+
private onMessage;
|
|
36
|
+
private onClose;
|
|
37
|
+
private close;
|
|
38
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.WebSocketsApi = void 0;
|
|
13
|
+
class WebSocketsApi {
|
|
14
|
+
constructor(apiServer, headers) {
|
|
15
|
+
this.apiServer = apiServer;
|
|
16
|
+
this.headers = headers;
|
|
17
|
+
this.socket = undefined;
|
|
18
|
+
this.WebSocketClass = undefined;
|
|
19
|
+
this.started = false;
|
|
20
|
+
if (typeof window !== 'undefined') {
|
|
21
|
+
// Browser environment: use native WebSocket
|
|
22
|
+
this.WebSocketClass = window.WebSocket;
|
|
23
|
+
}
|
|
24
|
+
else if (typeof globalThis.WebSocket !== 'undefined') {
|
|
25
|
+
// Node.js environment: use global WebSocket if available (e.g., Node 22+)
|
|
26
|
+
this.WebSocketClass = globalThis.WebSocket;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Node.js environment: use "ws" package where WebSocket is not available
|
|
30
|
+
console.log('!!!!!!!');
|
|
31
|
+
console.log('!!!!!!!');
|
|
32
|
+
console.log('!!!!!!!');
|
|
33
|
+
console.log('!!!!!!!');
|
|
34
|
+
console.log('!!!!!!!');
|
|
35
|
+
console.log('!!!!!!!');
|
|
36
|
+
this.WebSocketClass = require('ws').WebSocket;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
makeSocketConnection(options) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
yield new Promise((resolve, reject) => {
|
|
42
|
+
const base = this.apiServer.replace('https://', 'wss://').replace('http://', 'ws://');
|
|
43
|
+
const url = `${base}${options.path}`;
|
|
44
|
+
const headers = Object.assign(Object.assign(Object.assign({}, this.headers), options.headers), { path: options.path });
|
|
45
|
+
if (!this.WebSocketClass) {
|
|
46
|
+
throw Error('WebSocket class was not loaded.');
|
|
47
|
+
}
|
|
48
|
+
const socket = new this.WebSocketClass(url);
|
|
49
|
+
this.socket = socket;
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
throw Error('Failed to create WebSocket connection');
|
|
52
|
+
}
|
|
53
|
+
socket.onopen = () => {
|
|
54
|
+
socket.send(JSON.stringify({ headers, session: this.session }));
|
|
55
|
+
if (!options.mustStart) {
|
|
56
|
+
resolve();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
socket.addEventListener('message', (event) => {
|
|
60
|
+
const data = JSON.parse(event.data.toString());
|
|
61
|
+
if (data === null || data === void 0 ? void 0 : data.session) {
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
socket.onerror = (error) => {
|
|
67
|
+
console.error('WebSocket error:', error);
|
|
68
|
+
reject('A websocket error occurred connecting to the VocalStack API');
|
|
69
|
+
};
|
|
70
|
+
socket.addEventListener('message', (event) => {
|
|
71
|
+
var _a;
|
|
72
|
+
const data = JSON.parse(event.data.toString());
|
|
73
|
+
if (data === null || data === void 0 ? void 0 : data.session) {
|
|
74
|
+
this.session = data.session;
|
|
75
|
+
}
|
|
76
|
+
if ((data === null || data === void 0 ? void 0 : data.status) === 'done') {
|
|
77
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
connect(options) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
yield this.makeSocketConnection(options);
|
|
86
|
+
return this.returnConnection();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
connectDuplex(options) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
yield this.makeSocketConnection(Object.assign(Object.assign({}, options), { mustStart: true }));
|
|
92
|
+
return this.returnDuplexConnection();
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
returnConnection() {
|
|
96
|
+
return {
|
|
97
|
+
start: () => {
|
|
98
|
+
if (!this.socket) {
|
|
99
|
+
console.error('Socket not connected');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (this.started) {
|
|
103
|
+
console.error('Already started');
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.started = true;
|
|
107
|
+
this.socket.send(JSON.stringify({ start: true, session: this.session }));
|
|
108
|
+
},
|
|
109
|
+
close: () => this.close(),
|
|
110
|
+
onClose: (callback) => this.onClose(callback),
|
|
111
|
+
onData: (callback) => this.onMessage(callback),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
returnDuplexConnection() {
|
|
115
|
+
return Object.assign(Object.assign({}, this.returnConnection()), { stop: () => !this.socket
|
|
116
|
+
? console.error('Socket not connected')
|
|
117
|
+
: this.socket.send(JSON.stringify({ stop: true, session: this.session })), sendBuffer: (message) => this.sendBuffer(message) });
|
|
118
|
+
}
|
|
119
|
+
sendBuffer(buffer) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
var _a;
|
|
122
|
+
if (!this.socket || this.socket.readyState !== ((_a = this.WebSocketClass) === null || _a === void 0 ? void 0 : _a.OPEN)) {
|
|
123
|
+
throw Error('WebSocket is not connected.');
|
|
124
|
+
}
|
|
125
|
+
if (!(buffer instanceof ArrayBuffer) && !ArrayBuffer.isView(buffer)) {
|
|
126
|
+
throw Error('Unexpected data type being sent. Expected: ArrayBuffer or ArrayBufferView');
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.socket.send(buffer);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
onMessage(callback) {
|
|
134
|
+
if (!this.socket) {
|
|
135
|
+
throw Error('WebSocket is not connected.');
|
|
136
|
+
}
|
|
137
|
+
this.socket.addEventListener('message', (event) => {
|
|
138
|
+
const data = JSON.parse(event.data.toString());
|
|
139
|
+
callback(data);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
onClose(callback) {
|
|
143
|
+
if (!this.socket) {
|
|
144
|
+
throw Error('WebSocket is not connected.');
|
|
145
|
+
}
|
|
146
|
+
this.socket.addEventListener('close', callback);
|
|
147
|
+
}
|
|
148
|
+
close() {
|
|
149
|
+
if (!this.socket) {
|
|
150
|
+
console.error('WebSocket is not connected.');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.socket.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.WebSocketsApi = WebSocketsApi;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { VocalStackApi } from '../VocalStackApi';
|
|
2
|
+
import { SummaryTranscription } from './Transcriptions';
|
|
3
|
+
export type BillingDetailsPlan = {
|
|
4
|
+
uuid: string;
|
|
5
|
+
start_date: string;
|
|
6
|
+
stop_date: string;
|
|
7
|
+
price: number;
|
|
8
|
+
billing_frequency: string;
|
|
9
|
+
free_hours: number;
|
|
10
|
+
overage_rate_prerecorded: number;
|
|
11
|
+
overage_rate_live: number;
|
|
12
|
+
meta_name: string;
|
|
13
|
+
};
|
|
14
|
+
export type BillingDetails = {
|
|
15
|
+
balance: number;
|
|
16
|
+
prerecorded_hours_available: number;
|
|
17
|
+
live_hours_available: number;
|
|
18
|
+
free_hours_used: number;
|
|
19
|
+
free_hours_left: number;
|
|
20
|
+
total_per_month: Record<string, number>;
|
|
21
|
+
savings_per_month: Record<string, number>;
|
|
22
|
+
paid_per_month: Record<string, number>;
|
|
23
|
+
owed_per_month: Record<string, number>;
|
|
24
|
+
plans: BillingDetailsPlan[];
|
|
25
|
+
active_plan: BillingDetailsPlan;
|
|
26
|
+
hobby_plan: BillingDetailsPlan;
|
|
27
|
+
month_plans: Record<string, string[]>;
|
|
28
|
+
billing: Record<string, Array<Partial<SummaryTranscription> & {
|
|
29
|
+
plan: string;
|
|
30
|
+
length_in_adjusted_seconds: number;
|
|
31
|
+
free_seconds_available_before?: number;
|
|
32
|
+
free_seconds_available_after?: number;
|
|
33
|
+
cost: number;
|
|
34
|
+
notes: string[];
|
|
35
|
+
}>>;
|
|
36
|
+
invoices: Array<{
|
|
37
|
+
invoice_id: string;
|
|
38
|
+
plan_id?: string;
|
|
39
|
+
plan_uuid?: string;
|
|
40
|
+
interval?: 'year' | 'month';
|
|
41
|
+
status: 'open' | 'paid' | 'void';
|
|
42
|
+
status_transitions: {
|
|
43
|
+
paid_at: number;
|
|
44
|
+
finalized_at: number;
|
|
45
|
+
marked_uncollectible_at: number;
|
|
46
|
+
voided_at: number;
|
|
47
|
+
};
|
|
48
|
+
paid: boolean;
|
|
49
|
+
amount: number;
|
|
50
|
+
amount_paid: number;
|
|
51
|
+
amount_remaining: number;
|
|
52
|
+
view_link: string;
|
|
53
|
+
download_link: string;
|
|
54
|
+
metadata?: Record<string, string>;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
export declare class Billing extends VocalStackApi {
|
|
58
|
+
getBillingDetails(): Promise<import("../RestApi").ApiResponse<BillingDetails>>;
|
|
59
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Billing = void 0;
|
|
13
|
+
const VocalStackApi_1 = require("../VocalStackApi");
|
|
14
|
+
class Billing extends VocalStackApi_1.VocalStackApi {
|
|
15
|
+
getBillingDetails() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
return this._rest().get('/billing/details');
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Billing = Billing;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { Timeline, Uuid } from '../generics.zod';
|
|
3
|
+
import { VocalStackApi } from '../VocalStackApi';
|
|
4
|
+
import { DuplexWebsocketConnection } from '../WebsocketApi';
|
|
5
|
+
import { Status } from './Transcriptions';
|
|
6
|
+
declare const zLiveTranscriptionStartRequest: z.ZodObject<{
|
|
7
|
+
livestream_url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
language: z.ZodOptional<z.ZodEnum<["af", "am", "an", "ar", "as", "az", "be", "bg", "bn", "br", "bs", "ca", "cs", "cy", "da", "de", "dz", "el", "en", "eo", "es", "et", "eu", "fa", "fi", "fo", "fr", "ga", "gl", "gu", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "jv", "ka", "kk", "km", "kn", "ko", "ku", "ky", "la", "lb", "lo", "lt", "lv", "mg", "mk", "ml", "mn", "mr", "ms", "mt", "nb", "ne", "nl", "nn", "no", "oc", "or", "pa", "pl", "ps", "pt", "qu", "ro", "ru", "rw", "se", "si", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "ug", "uk", "ur", "vi", "vo", "wa", "xh", "zh", "zu"]>>;
|
|
9
|
+
translations: z.ZodOptional<z.ZodArray<z.ZodEnum<["af", "am", "an", "ar", "as", "az", "be", "bg", "bn", "br", "bs", "ca", "cs", "cy", "da", "de", "dz", "el", "en", "eo", "es", "et", "eu", "fa", "fi", "fo", "fr", "ga", "gl", "gu", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "jv", "ka", "kk", "km", "kn", "ko", "ku", "ky", "la", "lb", "lo", "lt", "lv", "mg", "mk", "ml", "mn", "mr", "ms", "mt", "nb", "ne", "nl", "nn", "no", "oc", "or", "pa", "pl", "ps", "pt", "qu", "ro", "ru", "rw", "se", "si", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "ug", "uk", "ur", "vi", "vo", "wa", "xh", "zh", "zu"]>, "many">>;
|
|
10
|
+
polyglot_id: z.ZodOptional<z.ZodString>;
|
|
11
|
+
timeout_period_s: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
max_duration_s: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
language?: "id" | "cy" | "br" | "hr" | "th" | "tr" | "mn" | "ms" | "or" | "af" | "am" | "an" | "ar" | "as" | "az" | "be" | "bg" | "bn" | "bs" | "ca" | "cs" | "da" | "de" | "dz" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "fi" | "fo" | "fr" | "ga" | "gl" | "gu" | "he" | "hi" | "ht" | "hu" | "hy" | "is" | "it" | "ja" | "jv" | "ka" | "kk" | "km" | "kn" | "ko" | "ku" | "ky" | "la" | "lb" | "lo" | "lt" | "lv" | "mg" | "mk" | "ml" | "mr" | "mt" | "nb" | "ne" | "nl" | "nn" | "no" | "oc" | "pa" | "pl" | "ps" | "pt" | "qu" | "ro" | "ru" | "rw" | "se" | "si" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "tl" | "ug" | "uk" | "ur" | "vi" | "vo" | "wa" | "xh" | "zh" | "zu" | undefined;
|
|
15
|
+
translations?: ("id" | "cy" | "br" | "hr" | "th" | "tr" | "mn" | "ms" | "or" | "af" | "am" | "an" | "ar" | "as" | "az" | "be" | "bg" | "bn" | "bs" | "ca" | "cs" | "da" | "de" | "dz" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "fi" | "fo" | "fr" | "ga" | "gl" | "gu" | "he" | "hi" | "ht" | "hu" | "hy" | "is" | "it" | "ja" | "jv" | "ka" | "kk" | "km" | "kn" | "ko" | "ku" | "ky" | "la" | "lb" | "lo" | "lt" | "lv" | "mg" | "mk" | "ml" | "mr" | "mt" | "nb" | "ne" | "nl" | "nn" | "no" | "oc" | "pa" | "pl" | "ps" | "pt" | "qu" | "ro" | "ru" | "rw" | "se" | "si" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "tl" | "ug" | "uk" | "ur" | "vi" | "vo" | "wa" | "xh" | "zh" | "zu")[] | undefined;
|
|
16
|
+
livestream_url?: string | undefined;
|
|
17
|
+
polyglot_id?: string | undefined;
|
|
18
|
+
timeout_period_s?: number | undefined;
|
|
19
|
+
max_duration_s?: number | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
language?: "id" | "cy" | "br" | "hr" | "th" | "tr" | "mn" | "ms" | "or" | "af" | "am" | "an" | "ar" | "as" | "az" | "be" | "bg" | "bn" | "bs" | "ca" | "cs" | "da" | "de" | "dz" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "fi" | "fo" | "fr" | "ga" | "gl" | "gu" | "he" | "hi" | "ht" | "hu" | "hy" | "is" | "it" | "ja" | "jv" | "ka" | "kk" | "km" | "kn" | "ko" | "ku" | "ky" | "la" | "lb" | "lo" | "lt" | "lv" | "mg" | "mk" | "ml" | "mr" | "mt" | "nb" | "ne" | "nl" | "nn" | "no" | "oc" | "pa" | "pl" | "ps" | "pt" | "qu" | "ro" | "ru" | "rw" | "se" | "si" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "tl" | "ug" | "uk" | "ur" | "vi" | "vo" | "wa" | "xh" | "zh" | "zu" | undefined;
|
|
22
|
+
translations?: ("id" | "cy" | "br" | "hr" | "th" | "tr" | "mn" | "ms" | "or" | "af" | "am" | "an" | "ar" | "as" | "az" | "be" | "bg" | "bn" | "bs" | "ca" | "cs" | "da" | "de" | "dz" | "el" | "en" | "eo" | "es" | "et" | "eu" | "fa" | "fi" | "fo" | "fr" | "ga" | "gl" | "gu" | "he" | "hi" | "ht" | "hu" | "hy" | "is" | "it" | "ja" | "jv" | "ka" | "kk" | "km" | "kn" | "ko" | "ku" | "ky" | "la" | "lb" | "lo" | "lt" | "lv" | "mg" | "mk" | "ml" | "mr" | "mt" | "nb" | "ne" | "nl" | "nn" | "no" | "oc" | "pa" | "pl" | "ps" | "pt" | "qu" | "ro" | "ru" | "rw" | "se" | "si" | "sk" | "sl" | "sq" | "sr" | "sv" | "sw" | "ta" | "te" | "tl" | "ug" | "uk" | "ur" | "vi" | "vo" | "wa" | "xh" | "zh" | "zu")[] | undefined;
|
|
23
|
+
livestream_url?: string | undefined;
|
|
24
|
+
polyglot_id?: string | undefined;
|
|
25
|
+
timeout_period_s?: number | undefined;
|
|
26
|
+
max_duration_s?: number | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export type LiveTranscriptionStartRequest = z.infer<typeof zLiveTranscriptionStartRequest>;
|
|
29
|
+
export type LiveTranscriptionStreamData = ArrayBufferLike;
|
|
30
|
+
export type LiveTranscriptionResponse = {
|
|
31
|
+
status: Status;
|
|
32
|
+
data: LiveTranscriptionResponseData | null;
|
|
33
|
+
http_code?: number;
|
|
34
|
+
};
|
|
35
|
+
export type LiveTranscriptionResponseData = {
|
|
36
|
+
id: Uuid;
|
|
37
|
+
polyglot_id: Uuid | null;
|
|
38
|
+
start: string;
|
|
39
|
+
end: string | null;
|
|
40
|
+
status: Status;
|
|
41
|
+
operation: 'transcription-live';
|
|
42
|
+
flags?: {
|
|
43
|
+
started: boolean;
|
|
44
|
+
} | null;
|
|
45
|
+
keywords?: string | null;
|
|
46
|
+
timeline?: Timeline;
|
|
47
|
+
paragraphs?: string[] | null;
|
|
48
|
+
summary?: string | null;
|
|
49
|
+
};
|
|
50
|
+
export type LiveTranscriptionStopRequest = {
|
|
51
|
+
id: string;
|
|
52
|
+
};
|
|
53
|
+
export type LiveTranscriptionConnection = DuplexWebsocketConnection<LiveTranscriptionStreamData, LiveTranscriptionResponse>;
|
|
54
|
+
export declare class LiveTranscription extends VocalStackApi {
|
|
55
|
+
connect(request?: LiveTranscriptionStartRequest): Promise<LiveTranscriptionConnection>;
|
|
56
|
+
stopTranscribing({ id }: LiveTranscriptionStopRequest): Promise<import("../RestApi").ApiResponse<unknown>>;
|
|
57
|
+
}
|
|
58
|
+
export {};
|