@charivo/stt 0.2.1 → 0.3.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.js +7 -4
- package/dist/index.mjs +9 -4
- package/dist/openai/index.js +16 -11
- package/dist/openai/index.mjs +20 -11
- package/dist/remote/index.js +6 -3
- package/dist/remote/index.mjs +10 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ __export(index_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
|
|
29
29
|
// src/stt-manager.ts
|
|
30
|
+
var import_core = require("@charivo/core");
|
|
30
31
|
var STTManagerImpl = class {
|
|
31
32
|
sttTranscriber;
|
|
32
33
|
eventEmitter;
|
|
@@ -47,8 +48,9 @@ var STTManagerImpl = class {
|
|
|
47
48
|
try {
|
|
48
49
|
await this.sttTranscriber.startRecording(options);
|
|
49
50
|
} catch (error) {
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const typedError = (0, import_core.toCharivoError)("provider", error);
|
|
52
|
+
this.eventEmitter?.emit("stt:error", { error: typedError });
|
|
53
|
+
throw typedError;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
@@ -60,8 +62,9 @@ var STTManagerImpl = class {
|
|
|
60
62
|
this.eventEmitter?.emit("stt:stop", { transcription });
|
|
61
63
|
return transcription;
|
|
62
64
|
} catch (error) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
const typedError = (0, import_core.toCharivoError)("provider", error);
|
|
66
|
+
this.eventEmitter?.emit("stt:error", { error: typedError });
|
|
67
|
+
throw typedError;
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,9 @@ import {
|
|
|
3
3
|
} from "./chunk-YUPKYMAU.mjs";
|
|
4
4
|
|
|
5
5
|
// src/stt-manager.ts
|
|
6
|
+
import {
|
|
7
|
+
toCharivoError
|
|
8
|
+
} from "@charivo/core";
|
|
6
9
|
var STTManagerImpl = class {
|
|
7
10
|
sttTranscriber;
|
|
8
11
|
eventEmitter;
|
|
@@ -23,8 +26,9 @@ var STTManagerImpl = class {
|
|
|
23
26
|
try {
|
|
24
27
|
await this.sttTranscriber.startRecording(options);
|
|
25
28
|
} catch (error) {
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
const typedError = toCharivoError("provider", error);
|
|
30
|
+
this.eventEmitter?.emit("stt:error", { error: typedError });
|
|
31
|
+
throw typedError;
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
@@ -36,8 +40,9 @@ var STTManagerImpl = class {
|
|
|
36
40
|
this.eventEmitter?.emit("stt:stop", { transcription });
|
|
37
41
|
return transcription;
|
|
38
42
|
} catch (error) {
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
const typedError = toCharivoError("provider", error);
|
|
44
|
+
this.eventEmitter?.emit("stt:error", { error: typedError });
|
|
45
|
+
throw typedError;
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
48
|
/**
|
package/dist/openai/index.js
CHANGED
|
@@ -108,6 +108,7 @@ var MediaRecorderHelper = class {
|
|
|
108
108
|
|
|
109
109
|
// src/openai/provider.ts
|
|
110
110
|
var import_openai = __toESM(require("openai"));
|
|
111
|
+
var import_core = require("@charivo/core");
|
|
111
112
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
112
113
|
var OpenAISTTProvider = class {
|
|
113
114
|
openai;
|
|
@@ -115,7 +116,7 @@ var OpenAISTTProvider = class {
|
|
|
115
116
|
defaultLanguage;
|
|
116
117
|
constructor(config) {
|
|
117
118
|
if (typeof window !== "undefined" && !config.dangerouslyAllowBrowser) {
|
|
118
|
-
throw new
|
|
119
|
+
throw new import_core.CharivoStateError(
|
|
119
120
|
"OpenAI provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing"
|
|
120
121
|
);
|
|
121
122
|
}
|
|
@@ -131,15 +132,19 @@ var OpenAISTTProvider = class {
|
|
|
131
132
|
const audioFile = new File([audioBlob], "audio.wav", {
|
|
132
133
|
type: "audio/wav"
|
|
133
134
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
135
|
+
try {
|
|
136
|
+
const response = await withTimeout(
|
|
137
|
+
this.openai.audio.transcriptions.create({
|
|
138
|
+
file: audioFile,
|
|
139
|
+
model: this.defaultModel,
|
|
140
|
+
language: options?.language || this.defaultLanguage
|
|
141
|
+
}),
|
|
142
|
+
`OpenAI STT request timed out after ${REQUEST_TIMEOUT_MS}ms`
|
|
143
|
+
);
|
|
144
|
+
return response.text;
|
|
145
|
+
} catch (error) {
|
|
146
|
+
throw (0, import_core.toCharivoError)("provider", error, "OpenAI STT request failed");
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
};
|
|
145
150
|
function createOpenAISTTProvider(config) {
|
|
@@ -149,7 +154,7 @@ async function withTimeout(promise, timeoutMessage) {
|
|
|
149
154
|
let timeoutId;
|
|
150
155
|
const timeoutPromise = new Promise((_, reject) => {
|
|
151
156
|
timeoutId = setTimeout(
|
|
152
|
-
() => reject(new
|
|
157
|
+
() => reject(new import_core.CharivoTimeoutError(timeoutMessage)),
|
|
153
158
|
REQUEST_TIMEOUT_MS
|
|
154
159
|
);
|
|
155
160
|
});
|
package/dist/openai/index.mjs
CHANGED
|
@@ -4,6 +4,11 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/openai/provider.ts
|
|
6
6
|
import OpenAI from "openai";
|
|
7
|
+
import {
|
|
8
|
+
CharivoStateError,
|
|
9
|
+
CharivoTimeoutError,
|
|
10
|
+
toCharivoError
|
|
11
|
+
} from "@charivo/core";
|
|
7
12
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
8
13
|
var OpenAISTTProvider = class {
|
|
9
14
|
openai;
|
|
@@ -11,7 +16,7 @@ var OpenAISTTProvider = class {
|
|
|
11
16
|
defaultLanguage;
|
|
12
17
|
constructor(config) {
|
|
13
18
|
if (typeof window !== "undefined" && !config.dangerouslyAllowBrowser) {
|
|
14
|
-
throw new
|
|
19
|
+
throw new CharivoStateError(
|
|
15
20
|
"OpenAI provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing"
|
|
16
21
|
);
|
|
17
22
|
}
|
|
@@ -27,15 +32,19 @@ var OpenAISTTProvider = class {
|
|
|
27
32
|
const audioFile = new File([audioBlob], "audio.wav", {
|
|
28
33
|
type: "audio/wav"
|
|
29
34
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
try {
|
|
36
|
+
const response = await withTimeout(
|
|
37
|
+
this.openai.audio.transcriptions.create({
|
|
38
|
+
file: audioFile,
|
|
39
|
+
model: this.defaultModel,
|
|
40
|
+
language: options?.language || this.defaultLanguage
|
|
41
|
+
}),
|
|
42
|
+
`OpenAI STT request timed out after ${REQUEST_TIMEOUT_MS}ms`
|
|
43
|
+
);
|
|
44
|
+
return response.text;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw toCharivoError("provider", error, "OpenAI STT request failed");
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
49
|
};
|
|
41
50
|
function createOpenAISTTProvider(config) {
|
|
@@ -45,7 +54,7 @@ async function withTimeout(promise, timeoutMessage) {
|
|
|
45
54
|
let timeoutId;
|
|
46
55
|
const timeoutPromise = new Promise((_, reject) => {
|
|
47
56
|
timeoutId = setTimeout(
|
|
48
|
-
() => reject(new
|
|
57
|
+
() => reject(new CharivoTimeoutError(timeoutMessage)),
|
|
49
58
|
REQUEST_TIMEOUT_MS
|
|
50
59
|
);
|
|
51
60
|
});
|
package/dist/remote/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(remote_exports, {
|
|
|
24
24
|
createRemoteSTTTranscriber: () => createRemoteSTTTranscriber
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(remote_exports);
|
|
27
|
+
var import_core = require("@charivo/core");
|
|
27
28
|
|
|
28
29
|
// src/media-recorder-helper.ts
|
|
29
30
|
var MediaRecorderHelper = class {
|
|
@@ -132,7 +133,7 @@ var RemoteSTTTranscriber = class {
|
|
|
132
133
|
`STT request timed out after ${REQUEST_TIMEOUT_MS}ms`
|
|
133
134
|
);
|
|
134
135
|
if (!response.ok) {
|
|
135
|
-
throw new
|
|
136
|
+
throw new import_core.CharivoProviderError(`STT API failed: ${response.statusText}`);
|
|
136
137
|
}
|
|
137
138
|
const data = await response.json();
|
|
138
139
|
this.recordingOptions = void 0;
|
|
@@ -158,9 +159,11 @@ async function fetchWithTimeout(input, init, timeoutMessage) {
|
|
|
158
159
|
});
|
|
159
160
|
} catch (error) {
|
|
160
161
|
if (isAbortError(error)) {
|
|
161
|
-
throw new
|
|
162
|
+
throw new import_core.CharivoTimeoutError(timeoutMessage, { cause: error });
|
|
162
163
|
}
|
|
163
|
-
throw
|
|
164
|
+
throw new import_core.CharivoTransportError("STT request failed", {
|
|
165
|
+
cause: error instanceof Error ? error : void 0
|
|
166
|
+
});
|
|
164
167
|
} finally {
|
|
165
168
|
clearTimeout(timeoutId);
|
|
166
169
|
}
|
package/dist/remote/index.mjs
CHANGED
|
@@ -3,6 +3,11 @@ import {
|
|
|
3
3
|
} from "../chunk-YUPKYMAU.mjs";
|
|
4
4
|
|
|
5
5
|
// src/remote/index.ts
|
|
6
|
+
import {
|
|
7
|
+
CharivoProviderError,
|
|
8
|
+
CharivoTimeoutError,
|
|
9
|
+
CharivoTransportError
|
|
10
|
+
} from "@charivo/core";
|
|
6
11
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
7
12
|
var RemoteSTTTranscriber = class {
|
|
8
13
|
apiEndpoint;
|
|
@@ -38,7 +43,7 @@ var RemoteSTTTranscriber = class {
|
|
|
38
43
|
`STT request timed out after ${REQUEST_TIMEOUT_MS}ms`
|
|
39
44
|
);
|
|
40
45
|
if (!response.ok) {
|
|
41
|
-
throw new
|
|
46
|
+
throw new CharivoProviderError(`STT API failed: ${response.statusText}`);
|
|
42
47
|
}
|
|
43
48
|
const data = await response.json();
|
|
44
49
|
this.recordingOptions = void 0;
|
|
@@ -64,9 +69,11 @@ async function fetchWithTimeout(input, init, timeoutMessage) {
|
|
|
64
69
|
});
|
|
65
70
|
} catch (error) {
|
|
66
71
|
if (isAbortError(error)) {
|
|
67
|
-
throw new
|
|
72
|
+
throw new CharivoTimeoutError(timeoutMessage, { cause: error });
|
|
68
73
|
}
|
|
69
|
-
throw
|
|
74
|
+
throw new CharivoTransportError("STT request failed", {
|
|
75
|
+
cause: error instanceof Error ? error : void 0
|
|
76
|
+
});
|
|
70
77
|
} finally {
|
|
71
78
|
clearTimeout(timeoutId);
|
|
72
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charivo/stt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "STT manager and browser adapters for Charivo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"openai": "^4.47.1",
|
|
39
|
-
"@charivo/core": "0.
|
|
39
|
+
"@charivo/core": "0.9.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"tsup": "^8.5.0",
|