JavaScript - hacerq ue con un boton se dispare una funcion que no me logra funcionar

 
Vista:
Imágen de perfil de Eduardo
Val: 159
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

hacerq ue con un boton se dispare una funcion que no me logra funcionar

Publicado por Eduardo (186 intervenciones) el 08/06/2024 08:20:56
Hola a todos espero me púedan ayudar con esto

tome este ejemplo de este video el cual al oprimir sobre un boton se habilita el microfono 7y se puede dictar sobre un textarea el ejemplo del video tiene una particularidad que luego de escribir lo dictado lo lee con una vez sintetica algo que no queria que lo hiciera al terminar a no ser que le oprimiera la opcion de escuchar

por lo que yo le puse un nuevo boton al ejemplo y a cada boton le puse un sonido que sonara al ser oprimido.

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
<!DOCTYPE html>
<html lang="es">
 
<head>
<meta name="google" content="notranslate" />
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
 
<body>
    <button onclick="sound.play();" style=" font-size:16; width:100px; height:40px; margin-right:6px" id="btnStart">DICTAR</button>
    <button onclick="sound.play();" style=" font-size:16; width:100px; height:40px; margin-right:6px" id="btnStop">DETENER</button>
    <button onclick="sound.play();" style=" font-size:16; width:100px; height:40px; margin-right:6px" id="btnOir">ESCUCHAR</button>
    <button id="borrar" onclick="javascript:eraseText();sound.play();" style=" font-size:16; width:100px; height:40px; margin-right:6px">BORRAR</button>
    <textarea style="width:100%" id="textArea" cols="30" rows="10"></textarea>
 
 
    <script src="./js/script.js"></script>
    <script>
function eraseText() {
    document.getElementById("textArea").value = "";
}
 
var sound=new Audio();
sound.src="pip.mp3";
</script>
	 <script type="text/javascript">
     function confirmation(){
        if(confirm("Empiece a Dictar")){
	   return true;
		} else {
	   return false;
	}
     }
</script>
</body>
 
</html>

en el js que se llema hay lo siguiente, lo cual le puse la linea para almacenar lo del nuevo boton y mas abajo la accion para que llamara a la funcion que hacia la lectura de lo dictado.

si notan comenté leerTexto(texto); esa parte ya que era la que hacia que luego de dictado leyera el texto en automatico y yo lo que quiero es que se lea solo al oprimir el boton Escuchar

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
const btnStart = document.getElementById('btnStart');
const btnStop = document.getElementById('btnStop');
const btnOir = document.getElementById('btnOir');
const textArea = document.getElementById('textArea');
 
const recognition = new webkitSpeechRecognition();
 
recognition.continuous = true;
recognition.lang = 'es-ES';
recognition.interimResult = false;
 
btnStart.addEventListener('click', () => {
	   recognition.start();
});
 
btnStop.addEventListener('click', () => {
    recognition.abort();
});
 
btnOir.addEventListener('click', () => {
	leerTexto(texto);
});
 
recognition.onresult = (event) => {
    const texto = event.results[event.results.length - 1][0].transcript;
    textArea.value = texto;
    //leerTexto(texto);
}
 
function leerTexto(text) {
    const speech = new SpeechSynthesisUtterance(text);
    speech.volume = 1;
    speech.rate = 0.5;
    speech.pitch = 0.4;
    speech.lang = 'es-ES'
 
   window.speechSynthesis.speak(speech);
}

y si notan he intentado colocar un confirm para que se muestre cuando sea oprimido el boton dictar para asi preparar antes de que empieze a hacer la grabacion aceptarla o no
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
Imágen de perfil de Alejandro
Val: 1.448
Plata
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

hacerq ue con un boton se dispare una funcion que no me logra funcionar

Publicado por Alejandro (540 intervenciones) el 11/06/2024 17:33:22
  • Alejandro se encuentra ahora conectado en el
  • chat de PHP
Aquí no existe la variable texto.
1
2
3
btnOir.addEventListener('click', () => {
	leerTexto(texto);
});

1
2
3
4
btnOir.addEventListener('click', () => {
	const texto = textArea.value;
	leerTexto(texto);
});
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar