Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let recognition = new webkitSpeechRecognition();
- let noActivityTimeout = null;
- recognition.continuous = true;
- recognition.interimResults = true;
- recognition.lang = "fr-FR";
- recognition.onresult = (event) => {
- let finalText= "";//Contient le texte corrigé ~1s après avoir fini de parler
- let tempText = "";//Contient le flow de texte
- for (let i = event.resultIndex; i < event.results.length; i++) {
- if(event.results[i].isFinal) {
- finalText = event.results[i][0].transcript;
- }else{
- tempText += event.results[i][0].transcript;
- }
- }
- clearTimeout(noActivityTimeout);
- //Avoid staying blocked if talking a lot and S2T is lost
- noActivityTimeout = setTimeout(_=> {
- recognition.stop();
- }, 2000);
- if(/et (compagnie|cie)/gi.test(tempText)) {
- console.log("WESH ARRETE DE DIRE CA !!");
- }
- if(finalText.length > 0) {
- //Ici c'est le texte corrigé quand tu arrête de parler
- //pendant ~1 seconde.
- //Exemple de TTS natif à chrome
- //var speech = new SpeechSynthesisUtterance();
- //speech.lang = "fr";
- //speech.text = finalText;
- //window.speechSynthesis.speak(speech);
- }
- };
- recognition.onend = (e) => {
- // console.log("ON END");
- recognition.start();//Relance l'écoute pour écouter en permanence
- };
- recognition.onspeechend = () => {
- // console.log("SPEECH END");
- };
- recognition.onerror = (e) => {
- // console.log("ON ERROR", e);
- }
- recognition.start();
Add Comment
Please, Sign In to add comment