Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda