@voquill/voice-ai 0.3.6 → 0.3.10
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 +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/xai.utils.d.ts +28 -0
- package/dist/xai.utils.d.ts.map +1 -0
- package/dist/xai.utils.js +71 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare const XAI_TRANSCRIPTION_MODELS: readonly ["grok-stt"];
|
|
2
|
+
export type XaiTranscriptionModel = (typeof XAI_TRANSCRIPTION_MODELS)[number];
|
|
3
|
+
export declare const XAI_TTS_VOICES: readonly ["eve", "ara", "rex", "sal", "leo"];
|
|
4
|
+
export type XaiTtsVoice = (typeof XAI_TTS_VOICES)[number];
|
|
5
|
+
export type XaiTestIntegrationArgs = {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const xaiTestIntegration: ({ apiKey, }: XaiTestIntegrationArgs) => Promise<boolean>;
|
|
9
|
+
export type XaiTranscriptionArgs = {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
model?: XaiTranscriptionModel;
|
|
12
|
+
blob: ArrayBuffer | Buffer;
|
|
13
|
+
ext: string;
|
|
14
|
+
language?: string;
|
|
15
|
+
};
|
|
16
|
+
export type XaiTranscribeAudioOutput = {
|
|
17
|
+
text: string;
|
|
18
|
+
wordsUsed: number;
|
|
19
|
+
};
|
|
20
|
+
export declare const xaiTranscribeAudio: ({ apiKey, model, blob, ext, language, }: XaiTranscriptionArgs) => Promise<XaiTranscribeAudioOutput>;
|
|
21
|
+
export type XaiSpeakArgs = {
|
|
22
|
+
apiKey: string;
|
|
23
|
+
text: string;
|
|
24
|
+
voice?: XaiTtsVoice;
|
|
25
|
+
language?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const xaiGenerateSpeech: ({ apiKey, text, voice, language, }: XaiSpeakArgs) => Promise<ArrayBuffer>;
|
|
28
|
+
//# sourceMappingURL=xai.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xai.utils.d.ts","sourceRoot":"","sources":["../src/xai.utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBA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
export const XAI_TTS_VOICES = ["eve", "ara", "rex", "sal", "leo"];
|
|
5
|
+
export const xaiTestIntegration = async ({ apiKey, }) => {
|
|
6
|
+
const response = await fetch(`${XAI_BASE_URL}/models`, {
|
|
7
|
+
method: "GET",
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: `Bearer ${apiKey.trim()}`,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
const detail = await response.text().catch(() => "");
|
|
14
|
+
throw new Error(detail
|
|
15
|
+
? `xAI responded ${response.status}: ${detail}`
|
|
16
|
+
: `xAI responded with status ${response.status}`);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
export const xaiTranscribeAudio = async ({ apiKey, model = "grok-stt", blob, ext, language, }) => {
|
|
21
|
+
return retry({
|
|
22
|
+
retries: 3,
|
|
23
|
+
fn: async () => {
|
|
24
|
+
const formData = new FormData();
|
|
25
|
+
const bodyData = blob instanceof ArrayBuffer ? blob : blob.buffer;
|
|
26
|
+
const audioBlob = new Blob([bodyData], { type: `audio/${ext}` });
|
|
27
|
+
formData.append("file", audioBlob, `audio.${ext}`);
|
|
28
|
+
formData.append("model", model);
|
|
29
|
+
formData.append("format", "json");
|
|
30
|
+
if (language && language !== "auto") {
|
|
31
|
+
formData.append("language", language);
|
|
32
|
+
}
|
|
33
|
+
const response = await fetch(`${XAI_BASE_URL}/stt`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
Authorization: `Bearer ${apiKey.trim()}`,
|
|
37
|
+
},
|
|
38
|
+
body: formData,
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
42
|
+
throw new Error(`xAI STT request failed with status ${response.status}: ${errorText}`);
|
|
43
|
+
}
|
|
44
|
+
const data = (await response.json());
|
|
45
|
+
const transcript = data?.text;
|
|
46
|
+
if (!transcript) {
|
|
47
|
+
throw new Error("Transcription failed: No text in xAI STT response");
|
|
48
|
+
}
|
|
49
|
+
return { text: transcript, wordsUsed: countWords(transcript) };
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
export const xaiGenerateSpeech = async ({ apiKey, text, voice = "eve", language = "en", }) => {
|
|
54
|
+
const response = await fetch(`${XAI_BASE_URL}/tts`, {
|
|
55
|
+
method: "POST",
|
|
56
|
+
headers: {
|
|
57
|
+
Authorization: `Bearer ${apiKey.trim()}`,
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({
|
|
61
|
+
text,
|
|
62
|
+
voice_id: voice,
|
|
63
|
+
language,
|
|
64
|
+
}),
|
|
65
|
+
});
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
68
|
+
throw new Error(`xAI TTS request failed with status ${response.status}: ${errorText}`);
|
|
69
|
+
}
|
|
70
|
+
return response.arrayBuffer();
|
|
71
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voquill/voice-ai",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "Shared Groq voice transcription helpers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"wavefile": "^11.0.0",
|
|
23
23
|
"zod": "^3.25.76",
|
|
24
24
|
"zod-to-json-schema": "^3.25.2",
|
|
25
|
-
"@voquill/
|
|
26
|
-
"@voquill/
|
|
25
|
+
"@voquill/utilities": "0.3.10",
|
|
26
|
+
"@voquill/types": "0.3.10"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"typescript": "5.9.2",
|
|
30
|
-
"@voquill/typescript-config": "0.3.
|
|
30
|
+
"@voquill/typescript-config": "0.3.10"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|