Mike0021 commited on
Commit
b41e91e
·
verified ·
1 Parent(s): fce50fe

Add WebGPU probe timeout for static demo

Browse files
Files changed (1) hide show
  1. app.js +18 -1
app.js CHANGED
@@ -114,6 +114,7 @@ const MIN_VAD_SILENCE_MS = 200;
114
  const MAX_VAD_SILENCE_MS = 800;
115
  const DEFAULT_LOOPBACK_SPEED = 1.10;
116
  const MIC_START_TIMEOUT_MS = 15000;
 
117
  const DEFAULT_TTS_CHUNKING = Object.freeze({
118
  firstSentenceMinChars: 5,
119
  sentenceMinChars: 8,
@@ -587,7 +588,11 @@ async function supportsWebGPU() {
587
  return false;
588
  }
589
  try {
590
- const adapter = await navigator.gpu.requestAdapter();
 
 
 
 
591
  state.webgpuAvailable = Boolean(adapter);
592
  state.webgpuAdapterInfo = await readGpuAdapterInfo(adapter);
593
  state.webgpuAdapterFeatures = adapter?.features ? [...adapter.features].sort() : [];
@@ -850,6 +855,18 @@ async function getUserMediaWithTimeout(constraints, timeoutMs = MIC_START_TIMEOU
850
  return stream;
851
  }
852
 
 
 
 
 
 
 
 
 
 
 
 
 
853
  function stopMic() {
854
  if (!state.micActive) return;
855
  state.micActive = false;
 
114
  const MAX_VAD_SILENCE_MS = 800;
115
  const DEFAULT_LOOPBACK_SPEED = 1.10;
116
  const MIC_START_TIMEOUT_MS = 15000;
117
+ const WEBGPU_ADAPTER_TIMEOUT_MS = 5000;
118
  const DEFAULT_TTS_CHUNKING = Object.freeze({
119
  firstSentenceMinChars: 5,
120
  sentenceMinChars: 8,
 
588
  return false;
589
  }
590
  try {
591
+ const adapter = await withTimeout(
592
+ navigator.gpu.requestAdapter(),
593
+ WEBGPU_ADAPTER_TIMEOUT_MS,
594
+ "WebGPU adapter probe",
595
+ );
596
  state.webgpuAvailable = Boolean(adapter);
597
  state.webgpuAdapterInfo = await readGpuAdapterInfo(adapter);
598
  state.webgpuAdapterFeatures = adapter?.features ? [...adapter.features].sort() : [];
 
855
  return stream;
856
  }
857
 
858
+ function withTimeout(promise, timeoutMs, label) {
859
+ let timeoutId = 0;
860
+ return Promise.race([
861
+ promise.finally(() => window.clearTimeout(timeoutId)),
862
+ new Promise((_, reject) => {
863
+ timeoutId = window.setTimeout(() => {
864
+ reject(new Error(`${label} timed out after ${(timeoutMs / 1000).toFixed(0)} seconds.`));
865
+ }, timeoutMs);
866
+ }),
867
+ ]);
868
+ }
869
+
870
  function stopMic() {
871
  if (!state.micActive) return;
872
  state.micActive = false;