@sdata/web-vue 3.22.0 → 3.22.1
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/es/sender/use-speech.js +32 -12
- package/json/web-types.json +1 -1
- package/package.json +1 -1
package/es/sender/use-speech.js
CHANGED
|
@@ -66,6 +66,7 @@ function useSpeech(allowSpeech, options) {
|
|
|
66
66
|
const sequence = shallowRef(0);
|
|
67
67
|
let generatedWorkletUrl;
|
|
68
68
|
let resolveWorkletFlush;
|
|
69
|
+
let workletReady = false;
|
|
69
70
|
let disposed = false;
|
|
70
71
|
const recording = computed(() => controlled.value && typeof config.value === "object" ? Boolean(config.value.recording) : internalRecording.value);
|
|
71
72
|
const available = computed(() => Boolean(config.value) && (controlled.value || supported.value) && !(captureError.value && isPermissionDeniedError(captureError.value.error)));
|
|
@@ -138,24 +139,33 @@ function useSpeech(allowSpeech, options) {
|
|
|
138
139
|
});
|
|
139
140
|
const releaseResources = function() {
|
|
140
141
|
var _ref = _asyncToGenerator(function* () {
|
|
141
|
-
var _workletNode$value2, _sourceNode$value, _stream$value, _audioContext$value
|
|
142
|
+
var _workletNode$value2, _sourceNode$value, _stream$value, _audioContext$value;
|
|
142
143
|
(_workletNode$value2 = workletNode.value) === null || _workletNode$value2 === void 0 || _workletNode$value2.disconnect();
|
|
143
144
|
(_sourceNode$value = sourceNode.value) === null || _sourceNode$value === void 0 || _sourceNode$value.disconnect();
|
|
144
145
|
(_stream$value = stream.value) === null || _stream$value === void 0 || _stream$value.getTracks().forEach((track) => track.stop());
|
|
145
|
-
if (((_audioContext$value = audioContext.value) === null || _audioContext$value === void 0 ? void 0 : _audioContext$value.state)
|
|
146
|
+
if (((_audioContext$value = audioContext.value) === null || _audioContext$value === void 0 ? void 0 : _audioContext$value.state) === "running") yield audioContext.value.suspend();
|
|
146
147
|
if (socket.value && (socket.value.readyState === WebSocket.OPEN || socket.value.readyState === WebSocket.CONNECTING)) socket.value.close(1e3, "speech-ended");
|
|
147
148
|
workletNode.value = void 0;
|
|
148
149
|
sourceNode.value = void 0;
|
|
149
150
|
stream.value = void 0;
|
|
150
|
-
audioContext.value = void 0;
|
|
151
151
|
socket.value = void 0;
|
|
152
152
|
});
|
|
153
153
|
return function releaseResources() {
|
|
154
154
|
return _ref.apply(this, arguments);
|
|
155
155
|
};
|
|
156
156
|
}();
|
|
157
|
+
const closeAudioContext = function() {
|
|
158
|
+
var _ref2 = _asyncToGenerator(function* () {
|
|
159
|
+
if (audioContext.value && audioContext.value.state !== "closed") yield audioContext.value.close();
|
|
160
|
+
audioContext.value = void 0;
|
|
161
|
+
workletReady = false;
|
|
162
|
+
});
|
|
163
|
+
return function closeAudioContext() {
|
|
164
|
+
return _ref2.apply(this, arguments);
|
|
165
|
+
};
|
|
166
|
+
}();
|
|
157
167
|
const stopCapture = function() {
|
|
158
|
-
var
|
|
168
|
+
var _ref3 = _asyncToGenerator(function* (reason = "manual") {
|
|
159
169
|
var _socket$value, _config$value$onRecor, _config$value;
|
|
160
170
|
if (!internalRecording.value) return;
|
|
161
171
|
yield flushWorklet();
|
|
@@ -177,11 +187,11 @@ function useSpeech(allowSpeech, options) {
|
|
|
177
187
|
});
|
|
178
188
|
});
|
|
179
189
|
return function stopCapture() {
|
|
180
|
-
return
|
|
190
|
+
return _ref3.apply(this, arguments);
|
|
181
191
|
};
|
|
182
192
|
}();
|
|
183
193
|
const startCapture = function() {
|
|
184
|
-
var
|
|
194
|
+
var _ref4 = _asyncToGenerator(function* () {
|
|
185
195
|
if (requesting.value || internalRecording.value || !available.value) return;
|
|
186
196
|
requesting.value = true;
|
|
187
197
|
captureError.value = void 0;
|
|
@@ -207,10 +217,18 @@ function useSpeech(allowSpeech, options) {
|
|
|
207
217
|
}
|
|
208
218
|
}
|
|
209
219
|
phase = "audioContext";
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
let nextAudioContext = audioContext.value;
|
|
221
|
+
if (!nextAudioContext) {
|
|
222
|
+
nextAudioContext = resolveAudioContext();
|
|
223
|
+
audioContext.value = nextAudioContext;
|
|
224
|
+
workletReady = false;
|
|
225
|
+
}
|
|
226
|
+
if (nextAudioContext.state === "suspended") yield nextAudioContext.resume();
|
|
212
227
|
phase = "audioWorklet";
|
|
213
|
-
|
|
228
|
+
if (!workletReady) {
|
|
229
|
+
yield nextAudioContext.audioWorklet.addModule(resolveWorkletUrl());
|
|
230
|
+
workletReady = true;
|
|
231
|
+
}
|
|
214
232
|
if (disposed) {
|
|
215
233
|
yield releaseResources();
|
|
216
234
|
return;
|
|
@@ -271,16 +289,17 @@ function useSpeech(allowSpeech, options) {
|
|
|
271
289
|
captureError.value = errorEvent;
|
|
272
290
|
options.onError(errorEvent);
|
|
273
291
|
yield releaseResources();
|
|
292
|
+
yield closeAudioContext();
|
|
274
293
|
} finally {
|
|
275
294
|
requesting.value = false;
|
|
276
295
|
}
|
|
277
296
|
});
|
|
278
297
|
return function startCapture() {
|
|
279
|
-
return
|
|
298
|
+
return _ref4.apply(this, arguments);
|
|
280
299
|
};
|
|
281
300
|
}();
|
|
282
301
|
const trigger = function() {
|
|
283
|
-
var
|
|
302
|
+
var _ref5 = _asyncToGenerator(function* (breakRecording = false) {
|
|
284
303
|
if (breakRecording && !recording.value) return;
|
|
285
304
|
if (controlled.value && typeof config.value === "object") {
|
|
286
305
|
var _config$value$onRecor2, _config$value2;
|
|
@@ -307,7 +326,7 @@ function useSpeech(allowSpeech, options) {
|
|
|
307
326
|
else yield startCapture();
|
|
308
327
|
});
|
|
309
328
|
return function trigger() {
|
|
310
|
-
return
|
|
329
|
+
return _ref5.apply(this, arguments);
|
|
311
330
|
};
|
|
312
331
|
}();
|
|
313
332
|
onMounted(() => {
|
|
@@ -324,6 +343,7 @@ function useSpeech(allowSpeech, options) {
|
|
|
324
343
|
disposed = true;
|
|
325
344
|
if (internalRecording.value) yield stopCapture("unmount");
|
|
326
345
|
else yield releaseResources();
|
|
346
|
+
yield closeAudioContext();
|
|
327
347
|
if (generatedWorkletUrl) URL.revokeObjectURL(generatedWorkletUrl);
|
|
328
348
|
}));
|
|
329
349
|
return {
|
package/json/web-types.json
CHANGED