Spaces:
Runtime error
Runtime error
HuggingFace-SK
commited on
Commit
·
d5c0578
1
Parent(s):
5c494db
add tts
Browse files- templates/browser-detect.html +38 -33
templates/browser-detect.html
CHANGED
|
@@ -58,42 +58,47 @@
|
|
| 58 |
</button>
|
| 59 |
<div style="position:relative" id="predicted_result"></div>
|
| 60 |
<div style="position:relative" id="text"></div>
|
|
|
|
|
|
|
|
|
|
| 61 |
<center>
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
<script type="module">
|
| 65 |
-
var synthesis = window.speechSynthesis;
|
| 66 |
-
|
| 67 |
-
if ('speechSynthesis' in window) {
|
| 68 |
var synthesis = window.speechSynthesis;
|
| 69 |
-
} else {
|
| 70 |
-
console.log('Text-to-speech not supported.');
|
| 71 |
-
}
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
var langRegex = /^en(-[a-z]{2})?$/i;
|
| 78 |
-
|
| 79 |
-
// Get the available voices and filter the list to only have English speakers
|
| 80 |
-
var voices = synthesis
|
| 81 |
-
.getVoices()
|
| 82 |
-
.filter((voice) => langRegex.test(voice.lang));
|
| 83 |
-
|
| 84 |
-
// Log the properties of the voices in the list
|
| 85 |
-
voices.forEach(function (voice) {
|
| 86 |
-
console.log({
|
| 87 |
-
name: voice.name,
|
| 88 |
-
lang: voice.lang,
|
| 89 |
-
uri: voice.voiceURI,
|
| 90 |
-
local: voice.localService,
|
| 91 |
-
default: voice.default,
|
| 92 |
-
});
|
| 93 |
-
});
|
| 94 |
-
} else {
|
| 95 |
-
console.log('Text-to-speech not supported.');
|
| 96 |
-
}
|
| 97 |
|
| 98 |
|
| 99 |
import { HandLandmarker, FilesetResolver } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0";
|
|
@@ -193,7 +198,7 @@
|
|
| 193 |
//detectSign()
|
| 194 |
} else {
|
| 195 |
console.log("RIGHT")
|
| 196 |
-
var current_result = "
|
| 197 |
var previous_result = document.getElementById("predicted_result").innerText
|
| 198 |
document.getElementById("predicted_result").innerText = current_result
|
| 199 |
var current_time = Math.round(Date.now())
|
|
|
|
| 58 |
</button>
|
| 59 |
<div style="position:relative" id="predicted_result"></div>
|
| 60 |
<div style="position:relative" id="text"></div>
|
| 61 |
+
<button id="text-to-speech" onclick="speak(document.getElementById('text').innerText)">
|
| 62 |
+
<span>🔊</span>
|
| 63 |
+
</button>
|
| 64 |
<center>
|
| 65 |
+
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
var synthesis = window.speechSynthesis;
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
if ('speechSynthesis' in window) {
|
| 69 |
+
var synthesis = window.speechSynthesis;
|
| 70 |
+
} else {
|
| 71 |
+
console.log('Text-to-speech not supported.');
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
function speak(text){
|
| 75 |
+
|
| 76 |
+
if ('speechSynthesis' in window) {
|
| 77 |
+
var synthesis = window.speechSynthesis;
|
| 78 |
+
|
| 79 |
+
// Get the first `en` language voice in the list
|
| 80 |
+
var voice = synthesis.getVoices().filter(function (voice) {
|
| 81 |
+
return voice.lang === 'en';
|
| 82 |
+
})[0];
|
| 83 |
+
|
| 84 |
+
// Create an utterance object
|
| 85 |
+
var utterance = new SpeechSynthesisUtterance(text);
|
| 86 |
+
|
| 87 |
+
// Set utterance properties
|
| 88 |
+
utterance.voice = voice;
|
| 89 |
+
utterance.pitch = 0.6;
|
| 90 |
+
utterance.rate = 0.8;
|
| 91 |
+
utterance.volume = 0.8;
|
| 92 |
+
|
| 93 |
+
// Speak the utterance
|
| 94 |
+
synthesis.speak(utterance);
|
| 95 |
+
} else {
|
| 96 |
+
console.log('Text-to-speech not supported.');
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
</script>
|
| 100 |
|
| 101 |
+
<script type="module">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
|
| 104 |
import { HandLandmarker, FilesetResolver } from "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.0";
|
|
|
|
| 198 |
//detectSign()
|
| 199 |
} else {
|
| 200 |
console.log("RIGHT")
|
| 201 |
+
var current_result = "_"
|
| 202 |
var previous_result = document.getElementById("predicted_result").innerText
|
| 203 |
document.getElementById("predicted_result").innerText = current_result
|
| 204 |
var current_time = Math.round(Date.now())
|