@novax-ai/sdk 0.1.0 → 0.2.0
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/index.d.ts +11 -2
- package/dist/index.js +29 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
export declare class NovaxClient {
|
|
2
2
|
private apiKey;
|
|
3
|
-
private baseUrl;
|
|
4
3
|
constructor({ apiKey }: {
|
|
5
4
|
apiKey: string;
|
|
6
5
|
});
|
|
7
6
|
textToSpeech: {
|
|
8
|
-
synthesize: ({ text, language }: {
|
|
7
|
+
synthesize: ({ text, language, }: {
|
|
9
8
|
text: string;
|
|
10
9
|
language?: string;
|
|
11
10
|
}) => Promise<{
|
|
12
11
|
blob: Blob;
|
|
13
12
|
}>;
|
|
14
13
|
};
|
|
14
|
+
speechToText: {
|
|
15
|
+
transcribe: ({ file, language, }: {
|
|
16
|
+
file: Blob | File;
|
|
17
|
+
language?: string;
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
text: string;
|
|
20
|
+
language: string;
|
|
21
|
+
duration?: number;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
15
24
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// src/index.ts
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.NovaxClient = void 0;
|
|
5
|
+
const BASE_URL = "https://novaxvoice-production.up.railway.app";
|
|
4
6
|
class NovaxClient {
|
|
5
7
|
constructor({ apiKey }) {
|
|
6
|
-
|
|
8
|
+
// ── Text to Speech ────────────────────────────────────────────────────────
|
|
7
9
|
this.textToSpeech = {
|
|
8
|
-
synthesize: async ({ text, language = "kri" }) => {
|
|
9
|
-
const res = await fetch(`${
|
|
10
|
+
synthesize: async ({ text, language = "kri", }) => {
|
|
11
|
+
const res = await fetch(`${BASE_URL}/api/krio-tts`, {
|
|
10
12
|
method: "POST",
|
|
11
13
|
headers: {
|
|
12
14
|
"Content-Type": "application/json",
|
|
@@ -14,12 +16,34 @@ class NovaxClient {
|
|
|
14
16
|
},
|
|
15
17
|
body: JSON.stringify({ text, language }),
|
|
16
18
|
});
|
|
17
|
-
if (!res.ok)
|
|
18
|
-
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
const err = await res.text();
|
|
21
|
+
throw new Error(`TTS failed (${res.status}): ${err}`);
|
|
22
|
+
}
|
|
19
23
|
const blob = await res.blob();
|
|
20
24
|
return { blob };
|
|
21
25
|
},
|
|
22
26
|
};
|
|
27
|
+
// ── Speech to Text ────────────────────────────────────────────────────────
|
|
28
|
+
this.speechToText = {
|
|
29
|
+
transcribe: async ({ file, language = "kri", }) => {
|
|
30
|
+
const form = new FormData();
|
|
31
|
+
form.append("file", file, file instanceof File ? file.name : "audio.wav");
|
|
32
|
+
form.append("language", language);
|
|
33
|
+
const res = await fetch(`${BASE_URL}/api/v1/transcribe`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
37
|
+
},
|
|
38
|
+
body: form,
|
|
39
|
+
});
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const err = await res.text();
|
|
42
|
+
throw new Error(`STT failed (${res.status}): ${err}`);
|
|
43
|
+
}
|
|
44
|
+
return res.json();
|
|
45
|
+
},
|
|
46
|
+
};
|
|
23
47
|
this.apiKey = apiKey;
|
|
24
48
|
}
|
|
25
49
|
}
|