Comment utiliser text to spech hors connexion en javascript

Fermé
Frijo_7715 - 5 mars 2023 à 17:20
jordane45 Messages postés 38472 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2025 - 5 mars 2023 à 22:04

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.

A voir également:

1 réponse

jordane45 Messages postés 38472 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 5 mai 2025 4 744
5 mars 2023 à 22:04

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>  

0