@lvce-editor/renderer-process 30.42.1 → 30.43.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.
@@ -9797,6 +9797,7 @@ const renderCanvas = (id, selector, canvasClassName, width, height, rectangles,
9797
9797
  };
9798
9798
  const commandHandlers = {
9799
9799
  'Css.addCssStyleSheet': addCssStyleSheet,
9800
+ 'Css.removeCssStyleSheet': removeCssStyleSheet,
9800
9801
  'Viewlet.addCss': addCssStyleSheet,
9801
9802
  'Viewlet.addKeyBindings': addKeyBindings,
9802
9803
  'Viewlet.append': append,
@@ -10068,8 +10069,33 @@ const setupLevelMeter = (audioCtx, stream) => {
10068
10069
  source.connect(analyser);
10069
10070
  return analyser;
10070
10071
  };
10072
+ const isSpeechStoppedEvent = data => {
10073
+ if (typeof data !== 'string') {
10074
+ return false;
10075
+ }
10076
+ try {
10077
+ const event = JSON.parse(data);
10078
+ return event?.type === 'input_audio_buffer.speech_stopped';
10079
+ } catch {
10080
+ return false;
10081
+ }
10082
+ };
10083
+ const startInputAudioRecorder = (micStream, audioDebugPort) => {
10084
+ if (!audioDebugPort) {
10085
+ return undefined;
10086
+ }
10087
+ const recorder = new MediaRecorder(micStream);
10088
+ recorder.ondataavailable = event => {
10089
+ if (event.data.size > 0) {
10090
+ audioDebugPort.postMessage(event.data);
10091
+ }
10092
+ };
10093
+ recorder.start();
10094
+ return recorder;
10095
+ };
10071
10096
  const startWebRtcAudioStream = async options => {
10072
10097
  const {
10098
+ audioDebugPort,
10073
10099
  elementLocator,
10074
10100
  port,
10075
10101
  trackAudioData,
@@ -10102,6 +10128,7 @@ const startWebRtcAudioStream = async options => {
10102
10128
  const micStream = await navigator.mediaDevices.getUserMedia({
10103
10129
  audio: true
10104
10130
  });
10131
+ const inputAudioRecorder = startInputAudioRecorder(micStream, audioDebugPort);
10105
10132
  if (trackAudioData && audioCtx) {
10106
10133
  micAnalyzer = setupLevelMeter(audioCtx, micStream);
10107
10134
  }
@@ -10109,6 +10136,9 @@ const startWebRtcAudioStream = async options => {
10109
10136
  const dc = pc.createDataChannel('oai-events');
10110
10137
  dc.addEventListener('message', e => {
10111
10138
  port.postMessage(e.data);
10139
+ if (inputAudioRecorder?.state === 'recording' && isSpeechStoppedEvent(e.data)) {
10140
+ inputAudioRecorder.requestData();
10141
+ }
10112
10142
  });
10113
10143
  port.onmessage = event => {
10114
10144
  const {
@@ -10125,8 +10155,10 @@ const startWebRtcAudioStream = async options => {
10125
10155
  await pc.setLocalDescription(offer);
10126
10156
  pcs[uid] = {
10127
10157
  audioCtx,
10158
+ audioDebugPort,
10128
10159
  connection: pc,
10129
10160
  dataChannel: dc,
10161
+ inputAudioRecorder,
10130
10162
  micAnalyzer,
10131
10163
  micStream,
10132
10164
  port,
@@ -10163,8 +10195,10 @@ const stopWebRtcAudioStream = async uid => {
10163
10195
  // TODO use disposableMap maybe?
10164
10196
  const {
10165
10197
  audioCtx,
10198
+ audioDebugPort,
10166
10199
  connection,
10167
10200
  dataChannel,
10201
+ inputAudioRecorder,
10168
10202
  micStream,
10169
10203
  port,
10170
10204
  remoteAudio
@@ -10173,10 +10207,15 @@ const stopWebRtcAudioStream = async uid => {
10173
10207
  connection.ontrack = null;
10174
10208
  connection.close();
10175
10209
  dataChannel.close();
10210
+ if (inputAudioRecorder && inputAudioRecorder.state !== 'inactive') {
10211
+ inputAudioRecorder.ondataavailable = null;
10212
+ inputAudioRecorder.stop();
10213
+ }
10176
10214
  for (const t of micStream.getTracks()) {
10177
10215
  t.stop();
10178
10216
  }
10179
10217
  port.close();
10218
+ audioDebugPort?.close();
10180
10219
  remoteAudio.srcObject = null;
10181
10220
  if (audioCtx) {
10182
10221
  await audioCtx.close();
@@ -10224,6 +10263,7 @@ const commandMap = {
10224
10263
  'ConfirmPrompt.prompt': confirm,
10225
10264
  'Css.addCssStyleSheet': addCssStyleSheet,
10226
10265
  'Css.getSelectionText': getSelectionText,
10266
+ 'Css.removeCssStyleSheet': removeCssStyleSheet,
10227
10267
  'Developer.showState': showState,
10228
10268
  'DirectView.getFocusedUid': getFocusedViewUid,
10229
10269
  'DirectView.getUid': getViewUid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "30.42.1",
3
+ "version": "30.43.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"