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

168
Visualizações
Web speech api closes after some seconds

I'm using web speech api

https://www.google.com/intl/en/chrome/demos/speech.html

but mic automatically closes after some seconds but i have to close mix only when the user clicks on close buttons.

Any solution to resolve this issue. Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should mark the recognition service as continuous and maybe start the recorder again if it stops after the timeout when there is no activity.

 <button onclick='toggleRecording()'>Toggle recorder</button>
 <div id='results'></div>
 <script>
    window.SpeechRecognition = window.SpeechRecognition ||
    window.webkitSpeechRecognition;

    let recognition = new window.SpeechRecognition()
    let recording = false;
    let results = null;

    recognition.continuous = true;

    function toggleRecording() {
        if(recording) {
            recognition.onend = null;
            recognition.stop();
            recording = false;

            // Printing all results we got so far.
            if(results) {
                let resultsDiv = document.getElementById('results')
                for(let i=0; i<results.length; ++i)
                    resultsDiv.innerHTML = resultsDiv.innerHTML + results.item(i)[0].transcript
            }
        } else {
            recognition.onend = onEnd;
            recognition.start();
            recording = true;
        }
    }

    function onEnd() {
        console.log('Speech recognition has stopped. Starting again ...');
        recognition.start();
    }


    function onSpeak(e) {
        results = e.results;
        console.log(e.results[e.results.length-1][0].transcript);
    }

    recognition.addEventListener('result', onSpeak);

</script>
about 4 years ago · Juan Pablo Isaza Relatório
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