Spaces:
Runtime error
Runtime error
HuggingFace-SK
commited on
Commit
·
22280c3
1
Parent(s):
dd8cdc8
add text-area, stability indicator
Browse files- templates/browser-detect.html +59 -62
templates/browser-detect.html
CHANGED
|
@@ -6,33 +6,13 @@
|
|
| 6 |
|
| 7 |
|
| 8 |
<title>Sign Language Interpreter</title>
|
| 9 |
-
|
| 10 |
-
* {
|
| 11 |
-
box-sizing: border-box;
|
| 12 |
-
}
|
| 13 |
-
|
| 14 |
-
body {
|
| 15 |
-
font-family: roboto;
|
| 16 |
-
color: #3d3d3d;
|
| 17 |
-
--mdc-theme-primary: #007f8b;
|
| 18 |
-
--mdc-theme-on-primary: #f1f3f4;
|
| 19 |
-
margin-left: 0px;
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
.container {
|
| 23 |
-
position: relative;
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
canvas {
|
| 27 |
-
background-color: lightgray;
|
| 28 |
-
/* Just for visibility */
|
| 29 |
-
}
|
| 30 |
-
</style>
|
| 31 |
|
| 32 |
<script>
|
| 33 |
window.console = window.console || function (t) { };
|
| 34 |
</script>
|
| 35 |
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
</head>
|
|
@@ -48,55 +28,67 @@
|
|
| 48 |
|
| 49 |
<div class="container">
|
| 50 |
<video id="webcam" style="display:none" autoplay="" playsinline=""></video>
|
| 51 |
-
<canvas class="output_canvas" id="output_canvas"
|
| 52 |
-
height="300%"></canvas>
|
| 53 |
</div>
|
| 54 |
<center>
|
| 55 |
<img id="output_image" style="display:none"></img>
|
| 56 |
<button id="webcamButton">
|
| 57 |
<span>ENABLE WEBCAM</span>
|
| 58 |
</button>
|
| 59 |
-
<div
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
<center>
|
| 65 |
-
<script>
|
|
|
|
|
|
|
|
|
|
| 66 |
var synthesis = window.speechSynthesis;
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
var synthesis = window.speechSynthesis;
|
| 70 |
-
} else {
|
| 71 |
-
console.log('Text-to-speech not supported.');
|
| 72 |
-
}
|
| 73 |
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
return voice.lang === 'en';
|
| 82 |
-
})[0];
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
}
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
<script type="module">
|
| 102 |
|
|
@@ -108,7 +100,6 @@ if ('speechSynthesis' in window) {
|
|
| 108 |
let webcamRunning = false;
|
| 109 |
var time_since_letter = 0
|
| 110 |
var last_letter_time = 0
|
| 111 |
-
var word_list = []
|
| 112 |
// Before we can use HandLandmarker class we must wait for it to finish
|
| 113 |
// loading. Machine Learning models can be large and take a moment to
|
| 114 |
// get everything needed to run.
|
|
@@ -192,6 +183,8 @@ if ('speechSynthesis' in window) {
|
|
| 192 |
canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
|
| 193 |
|
| 194 |
if (results.landmarks && results.handednesses[0]) {
|
|
|
|
|
|
|
| 195 |
if (results.handednesses[0][0].categoryName == "Left") {
|
| 196 |
annotateImage()
|
| 197 |
console.log("LEFT")
|
|
@@ -201,14 +194,14 @@ if ('speechSynthesis' in window) {
|
|
| 201 |
var current_result = "_"
|
| 202 |
var previous_result = document.getElementById("predicted_result").innerText
|
| 203 |
document.getElementById("predicted_result").innerText = current_result
|
| 204 |
-
|
| 205 |
|
| 206 |
if (previous_result == current_result) {
|
| 207 |
if (current_time - last_letter_time > 1000) {
|
| 208 |
last_letter_time = current_time
|
| 209 |
word_list.push(current_result)
|
| 210 |
console.log(word_list)
|
| 211 |
-
document.getElementById("text").
|
| 212 |
}
|
| 213 |
}
|
| 214 |
else {
|
|
@@ -225,17 +218,21 @@ if ('speechSynthesis' in window) {
|
|
| 225 |
var current_time = Math.round(Date.now())
|
| 226 |
console.log(current_time - last_letter_time)
|
| 227 |
if (previous_result == current_result) {
|
| 228 |
-
if (current_time - last_letter_time >
|
| 229 |
last_letter_time = current_time
|
| 230 |
word_list.pop()
|
| 231 |
console.log(word_list)
|
| 232 |
-
document.getElementById("text").
|
| 233 |
}
|
| 234 |
}
|
| 235 |
else {
|
| 236 |
last_letter_time = current_time
|
| 237 |
}
|
| 238 |
-
} else {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
}
|
| 240 |
|
| 241 |
canvasCtx.restore();
|
|
@@ -427,7 +424,7 @@ if ('speechSynthesis' in window) {
|
|
| 427 |
last_letter_time = current_time
|
| 428 |
word_list.push(current_result)
|
| 429 |
console.log(word_list)
|
| 430 |
-
document.getElementById("text").
|
| 431 |
}
|
| 432 |
}
|
| 433 |
else {
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
<title>Sign Language Interpreter</title>
|
| 9 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
<script>
|
| 12 |
window.console = window.console || function (t) { };
|
| 13 |
</script>
|
| 14 |
|
| 15 |
+
<link rel="stylesheet" type="text/css" href="static/browser_detect.css" />
|
| 16 |
|
| 17 |
|
| 18 |
</head>
|
|
|
|
| 28 |
|
| 29 |
<div class="container">
|
| 30 |
<video id="webcam" style="display:none" autoplay="" playsinline=""></video>
|
| 31 |
+
<canvas class="output_canvas" id="output_canvas" width="100%" height="300%"></canvas>
|
|
|
|
| 32 |
</div>
|
| 33 |
<center>
|
| 34 |
<img id="output_image" style="display:none"></img>
|
| 35 |
<button id="webcamButton">
|
| 36 |
<span>ENABLE WEBCAM</span>
|
| 37 |
</button>
|
| 38 |
+
<div class="wrapper_result">
|
| 39 |
+
<div id="predicted_result">></div>
|
| 40 |
+
</div>
|
| 41 |
+
<div class="wrapper_text">
|
| 42 |
+
<textarea id="text" onkeyup="set_output_array(this.value)"></textarea>
|
| 43 |
+
<button id="text-to-speech" onclick="speak(document.getElementById('text').value)">
|
| 44 |
+
<span>🔊</span>
|
| 45 |
+
</button>
|
| 46 |
+
</div>
|
| 47 |
<center>
|
| 48 |
+
<script>
|
| 49 |
+
var synthesis = window.speechSynthesis;
|
| 50 |
+
|
| 51 |
+
if ('speechSynthesis' in window) {
|
| 52 |
var synthesis = window.speechSynthesis;
|
| 53 |
+
} else {
|
| 54 |
+
console.log('Text-to-speech not supported.');
|
| 55 |
+
}
|
| 56 |
|
| 57 |
+
function speak(text) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
if ('speechSynthesis' in window) {
|
| 60 |
+
var synthesis = window.speechSynthesis;
|
| 61 |
|
| 62 |
+
// Get the first `en` language voice in the list
|
| 63 |
+
var voice = synthesis.getVoices().filter(function (voice) {
|
| 64 |
+
return voice.lang === 'en';
|
| 65 |
+
})[0];
|
| 66 |
|
| 67 |
+
// Create an utterance object
|
| 68 |
+
var utterance = new SpeechSynthesisUtterance(text);
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
// Set utterance properties
|
| 71 |
+
utterance.voice = voice;
|
| 72 |
+
utterance.pitch = 0.6;
|
| 73 |
+
utterance.rate = 0.8;
|
| 74 |
+
utterance.volume = 0.8;
|
| 75 |
|
| 76 |
+
// Speak the utterance
|
| 77 |
+
synthesis.speak(utterance);
|
| 78 |
+
} else {
|
| 79 |
+
console.log('Text-to-speech not supported.');
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
var word_list = []
|
| 83 |
|
| 84 |
+
|
| 85 |
+
function set_output_array(text) {
|
| 86 |
+
console.log(text)
|
| 87 |
+
word_list = text.split("");
|
| 88 |
+
console.log(word_list)
|
| 89 |
}
|
| 90 |
+
|
| 91 |
+
</script>
|
| 92 |
|
| 93 |
<script type="module">
|
| 94 |
|
|
|
|
| 100 |
let webcamRunning = false;
|
| 101 |
var time_since_letter = 0
|
| 102 |
var last_letter_time = 0
|
|
|
|
| 103 |
// Before we can use HandLandmarker class we must wait for it to finish
|
| 104 |
// loading. Machine Learning models can be large and take a moment to
|
| 105 |
// get everything needed to run.
|
|
|
|
| 183 |
canvasCtx.drawImage(video, 0, 0, canvasElement.width, (video.videoHeight / video.videoWidth) * canvasElement.width)
|
| 184 |
|
| 185 |
if (results.landmarks && results.handednesses[0]) {
|
| 186 |
+
var current_time = Math.round(Date.now())
|
| 187 |
+
document.getElementById("predicted_result").style.width = String((current_time - last_letter_time) / 10) + "%"
|
| 188 |
if (results.handednesses[0][0].categoryName == "Left") {
|
| 189 |
annotateImage()
|
| 190 |
console.log("LEFT")
|
|
|
|
| 194 |
var current_result = "_"
|
| 195 |
var previous_result = document.getElementById("predicted_result").innerText
|
| 196 |
document.getElementById("predicted_result").innerText = current_result
|
| 197 |
+
|
| 198 |
|
| 199 |
if (previous_result == current_result) {
|
| 200 |
if (current_time - last_letter_time > 1000) {
|
| 201 |
last_letter_time = current_time
|
| 202 |
word_list.push(current_result)
|
| 203 |
console.log(word_list)
|
| 204 |
+
document.getElementById("text").value = word_list.join('')
|
| 205 |
}
|
| 206 |
}
|
| 207 |
else {
|
|
|
|
| 218 |
var current_time = Math.round(Date.now())
|
| 219 |
console.log(current_time - last_letter_time)
|
| 220 |
if (previous_result == current_result) {
|
| 221 |
+
if (current_time - last_letter_time > 400) {
|
| 222 |
last_letter_time = current_time
|
| 223 |
word_list.pop()
|
| 224 |
console.log(word_list)
|
| 225 |
+
document.getElementById("text").value = word_list.join('')
|
| 226 |
}
|
| 227 |
}
|
| 228 |
else {
|
| 229 |
last_letter_time = current_time
|
| 230 |
}
|
| 231 |
+
} else {
|
| 232 |
+
last_letter_time = Math.round(Date.now())
|
| 233 |
+
|
| 234 |
+
document.getElementById("predicted_result").style.width = String(0) + "%"
|
| 235 |
+
}
|
| 236 |
}
|
| 237 |
|
| 238 |
canvasCtx.restore();
|
|
|
|
| 424 |
last_letter_time = current_time
|
| 425 |
word_list.push(current_result)
|
| 426 |
console.log(word_list)
|
| 427 |
+
document.getElementById("text").value = word_list.join('')
|
| 428 |
}
|
| 429 |
}
|
| 430 |
else {
|