MikeyParton / react-speech-kit

React hooks for Speech Recognition and Speech Synthesis
https://mikeyparton.github.io/react-speech-kit
238 stars 63 forks source link

Improve error handling #46

Open MindOfMatter opened 3 years ago

MindOfMatter commented 3 years ago

Would it be possible to add this code in speak function in order to better deal with voice errors? please

utterance.addEventListener('error', function (event) {
    console.error("Failed to speak with \"" + voice.name + "\" voice, caused by :", event.error);
    cancel()
});

optionally it would be a good idea to add callbacks in the arguments for onend and error listener :

const {  onEnd= () => {}, onError= () => {} } = props;
...
utterance.addEventListener('error', function (event) {
    console.error("Failed to speak with \"" + voice.name + '" voice, caused by :', event.error);
    cancel()
    onError(event)
});