Spaces:
Running
Running
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
.then(data => {
|
| 13 |
-
statusElement.textContent = `Status: ${data.status}`;
|
| 14 |
-
});
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
// Função para simular uma resposta de comando
|
| 18 |
-
function sendCommand() {
|
| 19 |
-
fetch('command.json')
|
| 20 |
-
.then(response => response.json())
|
| 21 |
-
.then(data => {
|
| 22 |
-
outputElement.textContent = `Comando recebido: ${data.command}`;
|
| 23 |
-
});
|
| 24 |
-
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.getElementById('startButton').addEventListener('click', () => {
|
| 2 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 3 |
+
recognition.lang = 'pt-BR';
|
| 4 |
+
recognition.start();
|
| 5 |
|
| 6 |
+
recognition.onresult = (event) => {
|
| 7 |
+
const transcript = event.results[0][0].transcript;
|
| 8 |
+
console.log('Você disse:', transcript);
|
| 9 |
+
// Enviar o texto para o processamento de linguagem natural
|
| 10 |
+
processText(transcript);
|
| 11 |
+
};
|
| 12 |
|
| 13 |
+
recognition.onerror = (event) => {
|
| 14 |
+
console.error('Erro no reconhecimento de voz:', event.error);
|
| 15 |
+
};
|
| 16 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
function speak(text) {
|
| 19 |
+
const utterance = new SpeechSynthesisUtterance(text);
|
| 20 |
+
utterance.lang = 'pt-BR';
|
| 21 |
+
window.speechSynthesis.speak(utterance);
|
| 22 |
+
}
|
| 23 |
|
| 24 |
+
function processText(text) {
|
| 25 |
+
// Aqui você pode adicionar a lógica de processamento de linguagem natural
|
| 26 |
+
// Por exemplo, usar uma API como Dialogflow, IBM Watson, etc.
|
| 27 |
+
// Para este exemplo, vamos apenas repetir o texto
|
| 28 |
+
const response = `Você disse: ${text}`;
|
| 29 |
+
document.getElementById('response').textContent = response;
|
| 30 |
+
speak(response);
|
| 31 |
+
}
|