Spaces:
Running
Running
ecoute sa ne fonctionne pas
Browse files- rosalinda.html +44 -16
- style.css +4 -0
rosalinda.html
CHANGED
|
@@ -102,27 +102,38 @@ div.textContent = text;
|
|
| 102 |
});
|
| 103 |
|
| 104 |
speakBtn.onclick = () => lastAIText && speak(lastAIText);
|
| 105 |
-
|
| 106 |
let rec = null;
|
| 107 |
let listening = false;
|
| 108 |
|
| 109 |
function setupSTT(){
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
rec = setupSTT();
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
micBtn.onclick = async () => {
|
| 121 |
-
if (!rec){
|
| 122 |
-
|
| 123 |
return;
|
| 124 |
}
|
| 125 |
-
|
| 126 |
rec.stop();
|
| 127 |
listening = false;
|
| 128 |
statusEl.textContent = "Micro: prêt";
|
|
@@ -166,17 +177,34 @@ div.textContent = text;
|
|
| 166 |
micBtn.classList.remove("listening");
|
| 167 |
if (inp.value.trim()) handleSend(inp.value);
|
| 168 |
};
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
// Auto-stop after 8 seconds if no speech detected
|
| 173 |
setTimeout(() => {
|
| 174 |
if (listening) rec.stop();
|
| 175 |
}, 8000);
|
| 176 |
} catch (e) {
|
| 177 |
-
console.error("Speech recognition
|
|
|
|
| 178 |
listening = false;
|
| 179 |
-
statusEl.textContent = "Micro: prêt";
|
| 180 |
micBtn.classList.remove("listening");
|
| 181 |
}
|
| 182 |
};
|
|
|
|
| 102 |
});
|
| 103 |
|
| 104 |
speakBtn.onclick = () => lastAIText && speak(lastAIText);
|
|
|
|
| 105 |
let rec = null;
|
| 106 |
let listening = false;
|
| 107 |
|
| 108 |
function setupSTT(){
|
| 109 |
+
try {
|
| 110 |
+
const SR = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 111 |
+
if (!SR) {
|
| 112 |
+
statusEl.textContent = "Micro: non supporté";
|
| 113 |
+
return null;
|
| 114 |
+
}
|
| 115 |
+
const r = new SR();
|
| 116 |
+
r.lang = "fr-FR";
|
| 117 |
+
r.interimResults = true;
|
| 118 |
+
r.continuous = false;
|
| 119 |
+
return r;
|
| 120 |
+
} catch (e) {
|
| 121 |
+
statusEl.textContent = "Micro: erreur";
|
| 122 |
+
return null;
|
| 123 |
+
}
|
| 124 |
}
|
| 125 |
rec = setupSTT();
|
| 126 |
|
| 127 |
+
if (!rec) {
|
| 128 |
+
micBtn.disabled = true;
|
| 129 |
+
micBtn.classList.add("opacity-50");
|
| 130 |
+
}
|
| 131 |
micBtn.onclick = async () => {
|
| 132 |
+
if (!rec) {
|
| 133 |
+
statusEl.textContent = "Micro: erreur";
|
| 134 |
return;
|
| 135 |
}
|
| 136 |
+
if (listening) {
|
| 137 |
rec.stop();
|
| 138 |
listening = false;
|
| 139 |
statusEl.textContent = "Micro: prêt";
|
|
|
|
| 177 |
micBtn.classList.remove("listening");
|
| 178 |
if (inp.value.trim()) handleSend(inp.value);
|
| 179 |
};
|
| 180 |
+
try {
|
| 181 |
+
await new Promise((resolve) => {
|
| 182 |
+
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
|
| 183 |
+
navigator.mediaDevices.getUserMedia({ audio: true })
|
| 184 |
+
.then(() => {
|
| 185 |
+
rec.start();
|
| 186 |
+
resolve();
|
| 187 |
+
})
|
| 188 |
+
.catch(err => {
|
| 189 |
+
console.error("Microphone access error:", err);
|
| 190 |
+
statusEl.textContent = "Micro: accès refusé";
|
| 191 |
+
listening = false;
|
| 192 |
+
micBtn.classList.remove("listening");
|
| 193 |
+
});
|
| 194 |
+
} else {
|
| 195 |
+
rec.start();
|
| 196 |
+
resolve();
|
| 197 |
+
}
|
| 198 |
+
});
|
| 199 |
+
|
| 200 |
// Auto-stop after 8 seconds if no speech detected
|
| 201 |
setTimeout(() => {
|
| 202 |
if (listening) rec.stop();
|
| 203 |
}, 8000);
|
| 204 |
} catch (e) {
|
| 205 |
+
console.error("Speech recognition error:", e);
|
| 206 |
+
statusEl.textContent = "Micro: erreur";
|
| 207 |
listening = false;
|
|
|
|
| 208 |
micBtn.classList.remove("listening");
|
| 209 |
}
|
| 210 |
};
|
style.css
CHANGED
|
@@ -113,6 +113,10 @@ input:focus, button:focus {
|
|
| 113 |
border-color: rgba(239, 68, 68, 0.5) !important;
|
| 114 |
}
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
.msg {
|
| 117 |
word-break: break-word;
|
| 118 |
white-space: pre-wrap;
|
|
|
|
| 113 |
border-color: rgba(239, 68, 68, 0.5) !important;
|
| 114 |
}
|
| 115 |
|
| 116 |
+
.opacity-50 {
|
| 117 |
+
opacity: 0.5;
|
| 118 |
+
cursor: not-allowed;
|
| 119 |
+
}
|
| 120 |
.msg {
|
| 121 |
word-break: break-word;
|
| 122 |
white-space: pre-wrap;
|