Skip to content
Snippets Groups Projects
Commit 08c8a4eb authored by Lucio Zambon's avatar Lucio Zambon
Browse files

Update talk.js

parent 21813ad5
No related branches found
No related tags found
No related merge requests found
......@@ -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(' ', '');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment