react-speech-to-text icon indicating copy to clipboard operation
react-speech-to-text copied to clipboard

Browser runs out of memory after speech recognition runs for too long

Open MarkCarbonell98 opened this issue 2 years ago • 2 comments

Hello @Riley-Brown!

First of all, thanks for this amazing NPM package. It has saved me a lot of time implementing my first live-voice-chat browser application.

Expected behavior: react-speech-to-text does not make the browser crash due to OOM errors after running for a long time. Current behavior: react-speech-to-text makes the browser crash out of memory when speech recognition runs long, either in continuous or non-continuous mode. I observed crashes happen after 15min of usage with continuous transcription, or with non-continuous transcription every 30 seconds approximately.

Steps to reproduce:

  • My configuration:
  const {
  	error: speechRecognitionError,
  	interimResult: speechRecognitionInterimResult,
  	isRecording: speechRecognitionIsRecording,
  	results: speechRecognitionResults,
  	startSpeechToText,
  	stopSpeechToText
  } = useSpeechToText({
  	useLegacyResults: false,
  	useOnlyGoogleCloud: true,
  	crossBrowser: false,
  	continuous: false,
  	googleApiKey: GOOGLE_SPEECH_RECOGNITION_API_KEY,
  	googleCloudRecognitionConfig: {
  		languageCode: 'de-DE',
  		sampleRateHertz: 48000,
  		maxAlternatives: 1,
  		model: 'command_and_search',
  	}
  });
  • Package version: ^0.8.0

  • Browser: Chrome version 106.0.5249.103

  • OS: Windows 11

  • Possible cause: I have not revised the package's code, but I have the impression that the audio stream used for the speech recognition stores the buffers locally as blobs, which progressively accumulate over time if they are not cleaned up. A useful StackOverflow post to successfully delete blobs might be: https://stackoverflow.com/questions/22899333/delete-javascript-blobs

MarkCarbonell98 avatar Oct 12 '22 17:10 MarkCarbonell98

Hi @MarkCarbonell98 glad you are finding this package useful.

Do you currently make use of the speechBlob in the results array? A possible solution to this memory problem could be adding an option to prevent saving the speechBlob if you do not need it

Riley-Brown avatar Oct 30 '22 15:10 Riley-Brown

Yes, I'm using the package and face the same issue. I think its better if you can introduce an input param to clear the speechBlob. If so then it will be useful.

prabathFC avatar Jan 09 '24 10:01 prabathFC