From 08c8a4eb35787ef09625497502cb9249123d01fe Mon Sep 17 00:00:00 2001 From: Lucio Zambon <lucio.zambon@elettra.eu> Date: Wed, 17 Jul 2024 03:23:16 +0000 Subject: [PATCH] Update talk.js --- speech/talk.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/speech/talk.js b/speech/talk.js index 2aac3e3..e955d4d 100644 --- a/speech/talk.js +++ b/speech/talk.js @@ -96,24 +96,24 @@ if (typeof p != 'undefined') console.log(p); console.trace(currentToken); // Show log in console and UI. - $('#log').html(currentToken); + $('#log').html($('#log').html()+'\n'+currentToken); // const logElement = document.querySelector('#log'); // logElement.textContent = logElement.textContent+'\n'+JSON.stringify(currentToken); } let finalTranscript = ''; const SpeechRecognition = window.speechRecognition || window.webkitSpeechRecognition; const recognition = new SpeechRecognition(); - recognition.maxAlternatives = 10; recognition.continuous = true; recognition.interimResults = true; recognition.lang = lang; recognition.maxAlternatives = 3; showLog('starting...'+'\n'); recognition.onerror = function(event) { - showLog(locale[lang].errorname + event.error+', '+event.message+', '+event.lineno+'\n'); + //showLog(locale[lang].errorname + event.error+', '+event.message+', '+event.lineno+'\n'); showLog(locale[lang].errormessage + JSON.stringify(event.error)); console.log(event); - startRec(); + // startRec(); + setTimeout(startRec, 5000); }; recognition.onend = function(event) { showLog('.'); @@ -121,7 +121,8 @@ document.getElementById('micna').style.display = 'none'; document.getElementById('micstart').style.display = 'none'; document.getElementById('micstop').style.display = 'inline'; - if (keepAlive && aliveTimer==-1) aliveTimer = setTimeout(startRec, 200); + // if (keepAlive && aliveTimer==-1) aliveTimer = setTimeout(startRec, 200); + if (keepAlive && aliveTimer==-1) aliveTimer = setTimeout(startRec, 500); }; recognition.onstart = function(event) { if (document.location.search.indexOf('debug')==-1) $('#log').hide(); @@ -152,6 +153,7 @@ let txt = transcript.toLowerCase(); if (txt.length>0) { let tok = txt.split(' ')[0]; + console.log('tok', tok); if (locale[lang].open.indexOf(tok)>-1) { mode = 'open'; $('#search').hide(); @@ -228,16 +230,6 @@ // mode = ''; // $('#search').hide(); $('#open').hide(); } - if (locale[lang].ujive.indexOf(tok)>-1) { - const token = document.location.search.indexOf('token=')>-1? '&token='+document.location.search.split('token=')[1].split('&')[0]: (document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: ''); - const snd = './talk.php?search=ujive'+token+"&lang="+lang; - showLog('ujive'); - showLog(snd); - fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);}); - mode = 'ujive'; - ancestor.length = 0; - txt = txt.replace(tok, '').replace(' ', ''); - } if (mode=='ujive') { showLog('ujive: '+tok); if (!isNaN(tok)) {ancestor.push(tok); tok = 'n'+ancestor.join('_');} @@ -250,6 +242,16 @@ mode = ''; $('#search').hide(); $('#open').hide(); } + if (locale[lang].ujive.indexOf(tok)>-1) { + const token = document.location.search.indexOf('token=')>-1? '&token='+document.location.search.split('token=')[1].split('&')[0]: (document.location.search.indexOf('?d=')>-1? '&token='+document.location.search.split('?d=')[1].split('&')[0]: ''); + const snd = './talk.php?search=ujive'+token+"&lang="+lang; + console.log('ujive'); + showLog(snd); + fetch(snd).then((response) => {return response.json();}).then((rlocale) => {showLog(rlocale); alert(rlocale);}); + mode = 'ujive'; + ancestor.length = 0; + txt = txt.replace(tok, '').replace(' ', ''); + } if (locale[lang].list.indexOf(tok)>-1) { mode = 'list'; txt = txt.replace(tok, '').replace(' ', ''); -- GitLab