HuggingFace-SK commited on
Commit
bb63de4
·
1 Parent(s): 58634d3

fix speech lag

Browse files
Files changed (1) hide show
  1. templates/browser-detect.html +19 -18
templates/browser-detect.html CHANGED
@@ -59,7 +59,16 @@
59
  var synthesis = window.speechSynthesis;
60
 
61
  if ('speechSynthesis' in window) {
 
62
  var synthesis = window.speechSynthesis;
 
 
 
 
 
 
 
 
63
  } else {
64
  console.log('Text-to-speech not supported.');
65
  }
@@ -67,23 +76,15 @@
67
  function speak(text) {
68
 
69
  if ('speechSynthesis' in window) {
70
- var synthesis = window.speechSynthesis;
71
-
72
- // Get the first `en` language voice in the list
73
- var voice = synthesis.getVoices().filter(function (voice) {
74
- return voice.lang === 'en';
75
- })[0];
76
-
77
- // Create an utterance object
78
- var utterance = new SpeechSynthesisUtterance(text);
79
-
80
- // Set utterance properties
81
- utterance.voice = voice;
82
- utterance.pitch = 0.6;
83
- utterance.rate = 0.8;
84
- utterance.volume = 0.8;
85
 
86
  // Speak the utterance
 
 
 
 
 
 
 
87
  synthesis.speak(utterance);
88
  } else {
89
  console.log('Text-to-speech not supported.');
@@ -131,7 +132,7 @@
131
  var objectDetector = tflite.loadTFLiteModel(MODEL_PATH);
132
 
133
  /********************************************************************
134
- // Demo 2: Continuously grab image from webcam stream and detect it.
135
  ********************************************************************/
136
  var global_res = 0;
137
  const video = document.getElementById("webcam");
@@ -205,7 +206,7 @@
205
  return
206
  }
207
  canvasElement.width = window.innerWidth;
208
- // Now let's start detecting the stream.
209
  if (runningMode === "IMAGE") {
210
  runningMode = "VIDEO";
211
  await handLandmarker.setOptions({ runningMode: "VIDEO" });
@@ -280,7 +281,7 @@
280
  }
281
 
282
  canvasCtx.restore();
283
- // Call this function again to keep predicting when the browser is ready.
284
  if (webcamRunning === true) {
285
  window.requestAnimationFrame(predictWebcam);
286
  }
 
59
  var synthesis = window.speechSynthesis;
60
 
61
  if ('speechSynthesis' in window) {
62
+
63
  var synthesis = window.speechSynthesis;
64
+
65
+ // Get the first `en` language voice in the list
66
+ var voice = synthesis.getVoices().filter(function (voice) {
67
+ return voice.lang === 'en';
68
+ })[0];
69
+
70
+ // Create an utterance object
71
+
72
  } else {
73
  console.log('Text-to-speech not supported.');
74
  }
 
76
  function speak(text) {
77
 
78
  if ('speechSynthesis' in window) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  // Speak the utterance
81
+ var utterance = new SpeechSynthesisUtterance(text);
82
+
83
+ // Set utterance properties
84
+ utterance.voice = voice;
85
+ utterance.pitch = 0.6;
86
+ utterance.rate = 0.8;
87
+ utterance.volume = 0.8;
88
  synthesis.speak(utterance);
89
  } else {
90
  console.log('Text-to-speech not supported.');
 
132
  var objectDetector = tflite.loadTFLiteModel(MODEL_PATH);
133
 
134
  /********************************************************************
135
+ // Continuously grab images
136
  ********************************************************************/
137
  var global_res = 0;
138
  const video = document.getElementById("webcam");
 
206
  return
207
  }
208
  canvasElement.width = window.innerWidth;
209
+ // Start detecting the stream.
210
  if (runningMode === "IMAGE") {
211
  runningMode = "VIDEO";
212
  await handLandmarker.setOptions({ runningMode: "VIDEO" });
 
281
  }
282
 
283
  canvasCtx.restore();
284
+ // Kepp predicting
285
  if (webcamRunning === true) {
286
  window.requestAnimationFrame(predictWebcam);
287
  }