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!