How to check if the words from voice search are contained in array

69 views Asked by At

I'm a newbie in learning JS and have been stuck for five days now trying to solve this problem. I want to be able to play the song that in its title includes the words said by User with Voice search . For now I have response 'Playing ... song', but only if I say the name of the first song, for the other two it doesn't work.

// Response
function playingChoosenSong(message) {
  const speech = new SpeechSynthesisUtterance();

  speech.text = "I didn't catch that, can you repeat?";

  const contains = songs.some((element) => {
    if (message.includes(element)) {
      speech.text = `Playing ${element}`;
      loadSong(element);
      playSong();
    }
  });


  window.speechSynthesis.speak(speech);
}

Thank you for your time!

0

There are 0 answers