@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.
- package/dist/hooks/useRecognition.js +18 -12
- package/package.json +1 -1
|
@@ -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
|
-
|
|
353
|
-
|
|
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
|
-
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
|
|
395
|
-
|
|
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.
|