Meteor(React) - Uncaught TypeError: onFinishedListening is not a function at SpeechRecognition.SpeechToText.recognition.onend

I am developing a voice based search in Meteor-reactjs, using npm package ‘speech-to-text’. But if no voice is there or long pause is there, it is throwing below error:

Uncaught TypeError: onFinishedListening is not a function
at SpeechRecognition.SpeechToText.recognition.onend

Code looks like,

import React, { Component } from 'react';
import { render } from 'react-dom';
import TrackerReact from 'meteor/ultimatejs:tracker-react';
import SpeechToText from 'speech-to-text';

export default class SpeechToTextFormat extends TrackerReact(Component){

	componentDidMount(){

		const onAnythingSaid = text => {
											console.log(`Interim text: ${text}`);
											console.log(`${text}`);
											if(`${text}`== 'ok'){
												FlowRouter.go('/');
											}
										}
		const onFinalised    = text => {
											console.log(`Finalised text: ${text}`);
										}
		 
		try {
		  const listener = new SpeechToText(onAnythingSaid, onFinalised);
		  listener.startListening();
		} catch (error) {
		  console.log('error: '+error);
		}	

		// Check to see if this browser supports speech recognition
		if (!('webkitSpeechRecognition' in window)) {
		  throw new Error("This browser doesn't support speech recognition. Try Google Chrome.");
		}	
	}

	render(){
		return(<div>hi</div>);
	}

}

Thanks in advance!

1 Like

Same error here. Did you figure it out?

Sorry. Didn’t got any solution.

I just looked at the npm package read me:

onFinishedListening: this is a callback function that is called when the speech recognitions stops listening.

You must pass a 3rd function to the constructor

new SpeechToText(onAnythingSaid, onFinalised, onFinishedListening);
2 Likes