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

102
Visualizações
SpeechRecognition API not stopping on React application

I am trying to add speech recognition to my web application. I am using Web Api's speech recognition. This is my react's code:

import logo from './logo.svg';
import './App.css';
import React from 'react';
import { Typography, Button, Box } from '@mui/material';

function App() {
  const [values,setValues] = React.useState("Click on the start button and start speaking.");
  var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
  var recognition = new SpeechRecognition();
  recognition.continuous = true;
  recognition.lang = 'en-US';
  recognition.interimResults = true;
  
  recognition.onresult = function(event) {
    console.log("Value is "+event.results[0][0].transcript)
    setValues(event.results[0][0].transcript)
  }
  return (
    <React.Fragment>
      <Typography align='center' variant="h1">
        Filler word helper
      </Typography>

      <Box sx={{
        backgroundColor:'gray',
        maxWidth:'md',
        margin:'auto',
        minHeight:200,
      }}>
        <Typography style={{
          paddingLeft:'2%',
          paddingRight:'2%'
        }} color="white">
          {values}
        </Typography>
      </Box>

      <Box sx={{
        display:'flex',
        justifyContent:'space-around',
        paddingTop:'2%'
      }}>
        <Button 
        onClick={()=>{
          recognition.start()
        }}
        variant="contained"
        >Start</Button>

        <Button 
        onClick={()=>{
          setValues("Click on the start button and start speaking.")
        }}
        variant="contained"
        >Clear</Button>

        <Button 
        onClick={()=>{
          recognition.abort()
          recognition.stop()
          console.log("Stop pressed")
        }}
        variant="contained"
        >Stop</Button>

      </Box>
    </React.Fragment>
  );
}

export default App;

The problem is that after I start the process I cannot stop it. It keeps on going. I did try stopping and aborting and trying various combinations.

Can anyone help me with this issue ?

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

0

The issue seems to be that you have set continuous to true.


This appears to always listen to the user, even when it has been aborted.

To fix this, you simply have to set it to false, as below.

recognition.continuous = false;

Also, by default, continuous is set to false, so removing it will have the same result.


This should stop the SpeechRecognition API from listening continuously, and abort/stop when abort() and stop() are called.

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