Search code examples
javascriptspeechspeech-synthesiswebspeech-api

How to make it so that SpeechSynthesis avoids emojis in JavaScript?


I have this JavaScript for performing SpeechSynthesis

let utterance = new SpeechSynthesisUtterance("Hello world! 👋");
speechSynthesis.speak(utterance);

which works!

However, I have this slight problem that the string "Hello World! 👋" contains an emoji 👋 and when the SpeechSynthesis happens it actually speaks out the emoji, i.e. it would say "Hello world waving hand".

Is there any way for it to filter out that 👋 waving hand from its speech?

Do note that the provided string contains 👋 and I have to try my best not to filter it out of the string itself but only from the speech.


Solution

  • I wasn't able to do this so the only solution was just to filter out the emoji from the string.

    Here it goes:

    let toSpeak = "Hello World 👋";
    toSpeak = toSpeak.replace('👋','');
    let utterance = new SpeechSynthesisUtterance(toSpeak);
    speechSynthesis.speak(utterance);