Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

142
Vistas
How to add forced alignment to chrome's web speech api?

I am using a modified code snippet from one of the mdn examples. Is there anyway we can make this code return one of the words from phrases exclusively and not any other words. Any alternatives would be appreciated too, if this is not possible.

var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var SpeechRecognitionEvent =
  SpeechRecognitionEvent || webkitSpeechRecognitionEvent;

var resultPara = document.querySelector(".result");
var testBtn = document.querySelector("button");

const phrases = ["dummy phrase"];

function testSpeech() {
  testBtn.disabled = true;
  testBtn.textContent = "Listening";

  // To ensure case consistency while checking with the returned output text
  resultPara.textContent = "";
  var recognition = new SpeechRecognition();
  var speechRecognitionList = new SpeechGrammarList();

  phrases.forEach((phrase) => {
    const grammar =
      "#JSGF V1.0; grammar phrase; public <phrase> = " + phrase + ";";
    speechRecognitionList.addFromString(grammar, 1);
  });

  recognition.grammars = speechRecognitionList;
  recognition.lang = "en-US";
  recognition.interimResults = false;
  recognition.maxAlternatives = 1;

  recognition.start();

  recognition.onresult = function (event) {
    var speechResult = event.results[0][0].transcript.toLowerCase();
    console.log("Speech received: " + speechResult + ".");
    resultPara.textContent = speechResult;
    console.log("Confidence: " + event.results[0][0].confidence);
  };

  recognition.onspeechend = function () {
    recognition.stop();
    testBtn.disabled = false;
    testBtn.textContent = "Start new test";
  };

  recognition.onerror = function (event) {
    testBtn.disabled = false;
    testBtn.textContent = "Start new test";
    console.error("Error occurred in recognition: " + event.error);
  };
}

testBtn.addEventListener("click", testSpeech);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda