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


#1

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!


#2

Same error here. Did you figure it out?


#3

Sorry. Didn’t got any solution.


#4

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);