@charivo/stt 0.2.0 → 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/{chunk-EKUYDBHB.mjs → chunk-YUPKYMAU.mjs} +7 -1
- package/dist/index.js +14 -5
- package/dist/index.mjs +10 -5
- package/dist/openai/index.js +23 -12
- package/dist/openai/index.mjs +21 -12
- package/dist/remote/index.js +13 -4
- package/dist/remote/index.mjs +11 -4
- package/package.json +2 -2
|
@@ -10,7 +10,13 @@ var MediaRecorderHelper = class {
|
|
|
10
10
|
if (this.recording) {
|
|
11
11
|
throw new Error("Already recording");
|
|
12
12
|
}
|
|
13
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
13
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
14
|
+
audio: {
|
|
15
|
+
echoCancellation: true,
|
|
16
|
+
noiseSuppression: true,
|
|
17
|
+
autoGainControl: true
|
|
18
|
+
}
|
|
19
|
+
});
|
|
14
20
|
this.mediaRecorder = new MediaRecorder(stream);
|
|
15
21
|
this.audioChunks = [];
|
|
16
22
|
this.mediaRecorder.ondataavailable = (event) => {
|
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
|
/**
|
|
@@ -87,7 +90,13 @@ var MediaRecorderHelper = class {
|
|
|
87
90
|
if (this.recording) {
|
|
88
91
|
throw new Error("Already recording");
|
|
89
92
|
}
|
|
90
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
93
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
94
|
+
audio: {
|
|
95
|
+
echoCancellation: true,
|
|
96
|
+
noiseSuppression: true,
|
|
97
|
+
autoGainControl: true
|
|
98
|
+
}
|
|
99
|
+
});
|
|
91
100
|
this.mediaRecorder = new MediaRecorder(stream);
|
|
92
101
|
this.audioChunks = [];
|
|
93
102
|
this.mediaRecorder.ondataavailable = (event) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MediaRecorderHelper
|
|
3
|
-
} from "./chunk-
|
|
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
|
@@ -47,7 +47,13 @@ var MediaRecorderHelper = class {
|
|
|
47
47
|
if (this.recording) {
|
|
48
48
|
throw new Error("Already recording");
|
|
49
49
|
}
|
|
50
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
50
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
51
|
+
audio: {
|
|
52
|
+
echoCancellation: true,
|
|
53
|
+
noiseSuppression: true,
|
|
54
|
+
autoGainControl: true
|
|
55
|
+
}
|
|
56
|
+
});
|
|
51
57
|
this.mediaRecorder = new MediaRecorder(stream);
|
|
52
58
|
this.audioChunks = [];
|
|
53
59
|
this.mediaRecorder.ondataavailable = (event) => {
|
|
@@ -102,6 +108,7 @@ var MediaRecorderHelper = class {
|
|
|
102
108
|
|
|
103
109
|
// src/openai/provider.ts
|
|
104
110
|
var import_openai = __toESM(require("openai"));
|
|
111
|
+
var import_core = require("@charivo/core");
|
|
105
112
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
106
113
|
var OpenAISTTProvider = class {
|
|
107
114
|
openai;
|
|
@@ -109,7 +116,7 @@ var OpenAISTTProvider = class {
|
|
|
109
116
|
defaultLanguage;
|
|
110
117
|
constructor(config) {
|
|
111
118
|
if (typeof window !== "undefined" && !config.dangerouslyAllowBrowser) {
|
|
112
|
-
throw new
|
|
119
|
+
throw new import_core.CharivoStateError(
|
|
113
120
|
"OpenAI provider is for server-side use only. Set dangerouslyAllowBrowser: true for testing"
|
|
114
121
|
);
|
|
115
122
|
}
|
|
@@ -125,15 +132,19 @@ var OpenAISTTProvider = class {
|
|
|
125
132
|
const audioFile = new File([audioBlob], "audio.wav", {
|
|
126
133
|
type: "audio/wav"
|
|
127
134
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
+
}
|
|
137
148
|
}
|
|
138
149
|
};
|
|
139
150
|
function createOpenAISTTProvider(config) {
|
|
@@ -143,7 +154,7 @@ async function withTimeout(promise, timeoutMessage) {
|
|
|
143
154
|
let timeoutId;
|
|
144
155
|
const timeoutPromise = new Promise((_, reject) => {
|
|
145
156
|
timeoutId = setTimeout(
|
|
146
|
-
() => reject(new
|
|
157
|
+
() => reject(new import_core.CharivoTimeoutError(timeoutMessage)),
|
|
147
158
|
REQUEST_TIMEOUT_MS
|
|
148
159
|
);
|
|
149
160
|
});
|
package/dist/openai/index.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MediaRecorderHelper
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-YUPKYMAU.mjs";
|
|
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 {
|
|
@@ -37,7 +38,13 @@ var MediaRecorderHelper = class {
|
|
|
37
38
|
if (this.recording) {
|
|
38
39
|
throw new Error("Already recording");
|
|
39
40
|
}
|
|
40
|
-
const stream = await navigator.mediaDevices.getUserMedia({
|
|
41
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
42
|
+
audio: {
|
|
43
|
+
echoCancellation: true,
|
|
44
|
+
noiseSuppression: true,
|
|
45
|
+
autoGainControl: true
|
|
46
|
+
}
|
|
47
|
+
});
|
|
41
48
|
this.mediaRecorder = new MediaRecorder(stream);
|
|
42
49
|
this.audioChunks = [];
|
|
43
50
|
this.mediaRecorder.ondataavailable = (event) => {
|
|
@@ -126,7 +133,7 @@ var RemoteSTTTranscriber = class {
|
|
|
126
133
|
`STT request timed out after ${REQUEST_TIMEOUT_MS}ms`
|
|
127
134
|
);
|
|
128
135
|
if (!response.ok) {
|
|
129
|
-
throw new
|
|
136
|
+
throw new import_core.CharivoProviderError(`STT API failed: ${response.statusText}`);
|
|
130
137
|
}
|
|
131
138
|
const data = await response.json();
|
|
132
139
|
this.recordingOptions = void 0;
|
|
@@ -152,9 +159,11 @@ async function fetchWithTimeout(input, init, timeoutMessage) {
|
|
|
152
159
|
});
|
|
153
160
|
} catch (error) {
|
|
154
161
|
if (isAbortError(error)) {
|
|
155
|
-
throw new
|
|
162
|
+
throw new import_core.CharivoTimeoutError(timeoutMessage, { cause: error });
|
|
156
163
|
}
|
|
157
|
-
throw
|
|
164
|
+
throw new import_core.CharivoTransportError("STT request failed", {
|
|
165
|
+
cause: error instanceof Error ? error : void 0
|
|
166
|
+
});
|
|
158
167
|
} finally {
|
|
159
168
|
clearTimeout(timeoutId);
|
|
160
169
|
}
|
package/dist/remote/index.mjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MediaRecorderHelper
|
|
3
|
-
} from "../chunk-
|
|
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",
|