How to play text-to-speech only if certain text is found in SQL response using JavaScript and ResponsiveVoice?

44 Views Asked by At

I'm making a database query and need to pronounce a text when the row is equal to 'llamar.' However, sometimes it doesn't play, or when it's playing, it cuts off and starts playing again. The text is returned to me by the SQL Server procedure 'P_registrar_turnos'. Is there a better way to handle this?

This is my code:

  setInterval(function () {
    llamarTurno();  
  }, 5000);


  function textoPorVoz(texto,funcion) {
    // +
    responsiveVoice.setDefaultVoice('Spanish Latin American Female');

    // +
    responsiveVoice.speak(texto, 'Spanish Latin American Female', {
      pitch: 1,
      rate: 1,
      onend: funcion
    });
  }

  function llamarTurno() {
      peticionActual = peticion({
        ruta: './ejecutarPeticion?procedimiento=p_traer_turnos',
        parametros: {
          renglon: 'LLAMAR'
        },
        funcion: {
          antesEnviarPeticion: function antesEnviarPeticion(peticion, configuracion) {},
          peticionExitosa: function peticionExitosa(respuesta, estado, peticion1) {

            textoPorVoz(" " + respuesta[0].texto, function() { 
              AsignarTurno(respuesta[0].id_turno);
              });
            
        }
      }
      });
    }

   function AsignarTurno(id_turno) {

    peticionActual = peticion({
      tipo: 'GET',
      ruta: './ejecutarPeticion?procedimiento=p_registrar_asignacion_turno',
      parametros: {
        renglon: 'ASIGNADO',
        id_turno_asignado: id_turno
        }
        ,
      funcion: {
      peticionExitosa: function peticionExitosa(respuesta,estado,peticion) {

        }
      }
      })

    }

0

There are 0 best solutions below