@nualang/nualang-ui-components 0.1.1426 → 0.1.1427

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.
@@ -348,11 +348,19 @@ export default function useRecognition(props = {}) {
348
348
  return;
349
349
  }
350
350
  audioInputRef.current.connect(processorRef.current);
351
+
352
+ // Resolved on the worklet's first real audio frame - the signal that
353
+ // capture has actually started, not just that permission/resume
354
+ // resolved. Capped so a genuinely silent/broken input can't hang
355
+ // start() forever; the cap is a safety net, not the primary signal.
356
+ let resolveFirstAudioFrame;
357
+ const firstAudioFrame = new Promise(resolve => {
358
+ resolveFirstAudioFrame = resolve;
359
+ });
360
+ const firstAudioFrameTimeoutId = setTimeout(resolveFirstAudioFrame, 800);
351
361
  processorRef.current.port.onmessage = event => {
352
- const audioData = event.data;
353
- socket.emit("binaryData", audioData, version);
354
- };
355
- processorRef.current.port.onmessage = event => {
362
+ clearTimeout(firstAudioFrameTimeoutId);
363
+ resolveFirstAudioFrame();
356
364
  const audioData = event.data;
357
365
  let sampleRate = 44100; // Default sample rate
358
366
  if (audioContextRef?.current?.sampleRate && audioContextRef?.current?.sampleRate !== 44100) {
@@ -387,14 +395,12 @@ export default function useRecognition(props = {}) {
387
395
  mediaRecorderRef.current = null;
388
396
  }
389
397
  }
390
- if (
391
- // Excludes bare "Safari", which also matches every desktop
392
- // Chrome/Edge/Firefox UA string and was adding this delay for
393
- // almost all browsers, not just mobile ones.
394
- /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
395
- // wait half second to indicate recording, this helps prevent speech being lost at the start
396
- return new Promise(resolve => setTimeout(resolve, 500));
397
- }
398
+
399
+ // recognizing:true (which flips the mic button to its "recording"
400
+ // state) must not fire until this resolves - otherwise Safari can
401
+ // show the button as live before AVAudioSession route negotiation
402
+ // has actually let samples through, losing the start of speech.
403
+ await firstAudioFrame;
398
404
  };
399
405
  if (navigator && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
400
406
  // Re-assert in case TTS playback downgraded the session since mount.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nualang/nualang-ui-components",
3
- "version": "0.1.1426",
3
+ "version": "0.1.1427",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "files": [