JavaScript - SpeechRecognition stop

<<>>
 
Vista:
sin imagen de perfil

SpeechRecognition stop

Publicado por Carlos (3 intervenciones) el 27/06/2024 02:57:46
Hola, me descargue este código JavaScript para agregar reconocimiento de voz en mi proyecto asp.net,
funciona pero no logro hacer que se detenga con el comando de stop, alguna idea?. Gracias.

1
<button onclick="voiceWrite()" value="@item2.Info" id="btnSpeak" class="btnSpeak"> <span class="material-symbols-outlined">mic</span> speak </button>

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
<script language="JavaScript">
        function voiceWrite()
        {
            const elNavegadorEsCompatible = () =>
            {
                if (navigator.userAgent.indexOf("Chrome") ||
                    navigator.userAgent.indexOf("Edge") ||
                    navigator.userAgent.indexOf("Safari")) return true;
                alert('The Browser does not support Voice Recognition');
                return false;
            }
            if (elNavegadorEsCompatible())
            {
                const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition)();
                recognition.lang = "en-US";
                recognition.onend = event => { recognition.start(); };
                recognition.onresult = resultado => { manejarResultado(resultado); };
                recognition.start();
 
                const manejarResultado = resultado =>
                {
                    var dataId = $(document.activeElement).val();
                    var dataspeak = resultado.results[0][0].transcript;
                    if (dataId == dataspeak)
                    {
                        alert("Excelent");
                        recognition.stop();
                    }
                    else
                    {
                        alert("wrong, you said: " + dataspeak);
                    }
                }
            }
        }
    </script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder