forked from mr-body/bookstoreHTML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.html
More file actions
61 lines (51 loc) · 1.68 KB
/
speech.html
File metadata and controls
61 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Conversor de Voz para Texto</title>
</head>
<body>
<h1>Conversor de Voz para Texto</h1>
<select id="language-select">
<option value="en">Ingles</option>
<option value="pt">Portugues</option>
</select>
<button id="start-btn">Iniciar</button>
<button id="stop-btn">Parar</button>
<span id="tmpOutput"></span>
<script>
const startBtn = document.getElementById('start-btn');
const stopBtn = document.getElementById('stop-btn');
const outputSpan = document.getElementById('tmpOutput');
const languageSelect = document.getElementById('language-select');
let recognition;
startBtn.addEventListener('click', startSpeechRecognition);
stopBtn.addEventListener('click', stopSpeechRecognition);
function startSpeechRecognition() {
const lang = languageSelect.value;
recognition = new webkitSpeechRecognition(); // para navegadores que suportam apenas o prefixo webkit
// Configuracoes para reconhecimento de voz em tempo real
recognition.continuous = true;
recognition.interimResults = true;
recognition.lang = lang;
recognition.onresult = function(event) {
let transcript = '';
for (let i = event.resultIndex; i < event.results.length; i++) {
transcript += event.results[i][0].transcript;
}
outputSpan.textContent = transcript
};
recognition.onend = function() {
console.log('Reconhecimento de voz parado.');
};
recognition.start();
}
function stopSpeechRecognition() {
if (recognition) {
recognition.stop();
}
}
</script>
</body>
</html>