Comment utiliser text to spech hors connexion en javascript

bonjour, comme le titre le dit, j'aimerai travailler avec la reconnaissance vocal et la synthèse vocal dans mon projet, et je souhaite que ça déroule en local. je veux savoir si y a une manière de le télécharger et l'inclure dans mon projet comme on inclus la bibliothèque JQuery. Merci d'avance pour votre aide.

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. Modérateur

    Bonjour,

    Pas de souci pour le faire fonctionner sans connexion internet, c'est inclus dans la bibliothèque de ton navigateur.

    Par exemple :

    <button onclick="go()" >GO</button>
    
    <script>
    function getVoices() {
      let voices = speechSynthesis.getVoices();
      if(!voices.length){
        let utterance = new SpeechSynthesisUtterance("");
        speechSynthesis.speak(utterance);
        voices = speechSynthesis.getVoices();
      }
      return voices;
    }
    
    function go(){ 
       if ('speechSynthesis' in window) {
          let speakData = new SpeechSynthesisUtterance();
          speakData.volume = 1; // From 0 to 1
          speakData.rate = 1; // From 0.1 to 10
          speakData.pitch = 2; // From 0 to 2
          speakData.text = "ça marche sans connexion internet..";
          speakData.lang = 'fr';
          speakData.voice = getVoices()[0];
          
          
          speechSynthesis.speak(speakData);
        }else{
          // Speech Synthesis is not Supported 
          console.log('ERROR');
      }
    }
    </script>