From af86654c1e9a1830534a6f4e00eb1495fcece37d Mon Sep 17 00:00:00 2001
From: Dheirya Tyagi <69175561+Dheirya@users.noreply.github.com>
Date: Sun, 27 Aug 2023 18:15:00 -0400
Subject: [PATCH] Update screen.min.js
---
frontend/static/screen.min.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/static/screen.min.js b/frontend/static/screen.min.js
index a926cb5..eeffaad 100644
--- a/frontend/static/screen.min.js
+++ b/frontend/static/screen.min.js
@@ -1 +1 @@
-const timeElement=document.getElementById("time");function updateTime(){let e=new Date,t=e.getHours()%12||12,n=e.getMinutes().toString().padStart(2,"0");timeElement.textContent=`${t}:${n}`}updateTime(),setInterval(updateTime,1e3);const utterance=new SpeechSynthesisUtterance;let wordIndex=0;utterance.lang="en-UK",utterance.volume=1,utterance.rate=.9,utterance.pitch=1.2;const speakQueue=[];let isSpeaking=!1,lastSpokenWord="";function scrollToBottom(){window.scrollTo({left:0,top:document.body.scrollHeight,behavior:"smooth"})}function speak(e,t){"error"!==document.getElementById("speak-icon").innerHTML&&"mic_off"!==document.getElementById("speak-icon").innerHTML&&(document.getElementById("speak-icon").innerHTML="pending"),speakQueue.push({text:e,callback:t}),isSpeaking||speakNext()}function speakNext(){if(0===speakQueue.length){isSpeaking=!1;return}isSpeaking=!0;let{text:e,callback:t}=speakQueue.shift();utterance.text=e,speechSynthesis.speak(utterance),"function"==typeof t?utterance.onend=function(){wordIndex=0,t(),document.getElementById("spoken").removeAttribute("id"),scrollToBottom(),speakNext()}:utterance.onend=function(){wordIndex=0,document.getElementById("spoken").removeAttribute("id"),scrollToBottom(),speakNext()}}function getWordAt(e,t){e=String(e),t=Number(t)>>>0;let n=e.slice(0,t+1).search(/\S+$/),o=e.slice(t).search(/\s/);return o<0?e.slice(n):e.slice(n,o+t)}function autoplay(){if("SpeechSynthesisUtterance"in window&&"webkitSpeechRecognition"in window&&"speechSynthesis"in window){let e,t;try{new AudioContext,e=!0}catch(n){document.getElementById("spoken").innerHTML="Please press the microphone button to start speaking"}if(e){let o=speechSynthesis.getVoices();(t=o.length>0)?speak("Please press the microphone button to start speaking",()=>{}):(document.getElementById("spoken").innerHTML="Please press the microphone button to start speaking",document.getElementById("spoken").removeAttribute("id"))}}else document.getElementById("spoken").innerHTML="Sorry, your browser doesn't support speech synthesis. Please use a more modern browser or check your settings.",document.getElementById("speak").remove()}utterance.onboundary=function(e){let t=getWordAt(utterance.text,e.charIndex);t!==lastSpokenWord&&(document.getElementById("spoken").innerHTML+=t+" ",lastSpokenWord=t,scrollToBottom())},window.parent.document.querySelector("#voice").addEventListener("change",()=>{window.parent.document.querySelector('#voice [value="default"]').remove(),utterance.voice=speechSynthesis.getVoices().filter(function(e){return e.name==window.parent.document.querySelector("#voice").value})[0]}),window.parent.document.querySelector("#speed").addEventListener("change",()=>{utterance.rate=window.parent.document.querySelector("#speed").value,window.parent.document.querySelector("#numSpeed").innerHTML=window.parent.document.querySelector("#speed").value}),window.parent.document.querySelector("#pitch").addEventListener("change",()=>{utterance.pitch=window.parent.document.querySelector("#pitch").value,window.parent.document.querySelector("#numPitch").innerHTML=window.parent.document.querySelector("#pitch").value});const speechRecognition=new webkitSpeechRecognition,updateInterval=1e3;let currentContext,globalStream,blink=!0,isListening=!1,final_transcript="",lastTranscriptUpdateTime=Date.now(),personalize="default";function enableMic(){navigator.mediaDevices.getUserMedia({video:!1,audio:!0}).then(e=>{let t=speechSynthesis.getVoices();t.forEach(e=>{let t=document.createElement("option");t.value=e.name,t.textContent=e.name,window.parent.document.querySelector("#voice").appendChild(t)}),window.parent.postMessage("Start Read","*"),globalStream=e,speechRecognition.stop(),document.getElementById("speak").style.bottom="2px",document.getElementById("speak").style.left="5px",document.getElementById("speak").style.transform="scale(0.5)",document.getElementById("speak").removeAttribute("onclick"),document.getElementById("speak-icon").innerHTML="mic",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("Welcome!",function(){document.getElementById("m1").style.display="inline"}),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("You will always talk after I finish speaking, or until the microphone icon starts flashing red. To stop the conversation, just say 'see you later'! Got it? Great!",function(){document.getElementById("m2").style.display="inline"}),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("So, what's on your mind?",function(){window.parent.postMessage("End Read","*"),document.getElementById("speak-icon").innerHTML="mic",blink=!0,blinkRed(),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"You: Speak...
",speechRecognition.start()})}).catch(e=>{window.parent.postMessage("Declined","*"),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"System: "+e+"
",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",document.getElementById("speak-icon").innerHTML="error",speak("Please click the icon to try again and enable your microphone, and try checking your browser settings")})}function blinkRed(){blink&&("red"===document.getElementById("speak-icon").style.color?document.getElementById("speak-icon").style.color="white":document.getElementById("speak-icon").style.color="red",setTimeout(blinkRed,1e3))}speechRecognition.lang="en-US",speechRecognition.continuous=!0,speechRecognition.interimResults=!0,speechRecognition.onerror=()=>{isListening=!1},speechRecognition.onend=()=>{final_transcript?(window.parent.postMessage("Thinking","*"),isListening=!1,blink=!1,document.getElementById("yourTalk").style.color="#fff",document.getElementById("yourTalk").innerHTML=final_transcript.charAt(0).toUpperCase()+final_transcript.slice(1),document.getElementById("yourTalk").removeAttribute("id"),document.getElementById("speak-icon").style.color="white","see you later"===final_transcript.toLowerCase()?(window.postMessage("Wave","*"),document.getElementById("speak-icon").innerHTML="mic_off",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("Goodbye, hope we talk again soon!",function(){})):(document.getElementById("speak-icon").innerHTML="pending",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT: Thinking...
",scrollToBottom(),fetch("https://talkgpt-1-r6338284.deta.app/ask/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:final_transcript,context:currentContext,personality:personalize})}).then(e=>e.json()).then(e=>{window.parent.postMessage("Start Read","*"),currentContext=e.context,document.getElementById("spoken").innerHTML="",speak(e.response,function(){window.parent.postMessage("End Read","*"),document.getElementById("speak-icon").innerHTML="mic",blink=!0,blinkRed(),document.getElementById("output").innerHTML+="You: Speak...
",speechRecognition.start()})}),final_transcript="")):speechRecognition.start()},speechRecognition.onresult=e=>{scrollToBottom(),lastTranscriptUpdateTime=Date.now(),isListening||(isListening=!0);let t="";for(let n=e.resultIndex;n{personalize=window.parent.document.querySelector("#personality").value}),setInterval(function(){if(isListening){let e=Date.now()-lastTranscriptUpdateTime;e>1e3&&speechRecognition.stop()}},250);
+const timeElement=document.getElementById("time");function updateTime(){let e=new Date,t=e.getHours()%12||12,n=e.getMinutes().toString().padStart(2,"0");timeElement.textContent=`${t}:${n}`}updateTime(),setInterval(updateTime,1e3);const utterance=new SpeechSynthesisUtterance;let wordIndex=0;utterance.lang="en-UK",utterance.volume=1,utterance.rate=.9,utterance.pitch=1.2;const speakQueue=[];let isSpeaking=!1,lastSpokenWord="";function scrollToBottom(){window.scrollTo({left:0,top:document.body.scrollHeight,behavior:"smooth"})}function speak(e,t){"error"!==document.getElementById("speak-icon").innerHTML&&"mic_off"!==document.getElementById("speak-icon").innerHTML&&(document.getElementById("speak-icon").innerHTML="pending"),speakQueue.push({text:e,callback:t}),isSpeaking||speakNext()}function speakNext(){if(0===speakQueue.length){isSpeaking=!1;return}isSpeaking=!0;let{text:e,callback:t}=speakQueue.shift();utterance.text=e,speechSynthesis.speak(utterance),"function"==typeof t?utterance.onend=function(){wordIndex=0,t(),document.getElementById("spoken").removeAttribute("id"),scrollToBottom(),speakNext()}:utterance.onend=function(){wordIndex=0,document.getElementById("spoken").removeAttribute("id"),scrollToBottom(),speakNext()}}function getWordAt(e,t){e=String(e),t=Number(t)>>>0;let n=e.slice(0,t+1).search(/\S+$/),o=e.slice(t).search(/\s/);return o<0?e.slice(n):e.slice(n,o+t)}function autoplay(){if("SpeechSynthesisUtterance"in window&&"webkitSpeechRecognition"in window&&"speechSynthesis"in window){let e,t;try{new AudioContext,e=!0}catch(n){document.getElementById("spoken").innerHTML="Please press the microphone button to start speaking"}if(e){let o=speechSynthesis.getVoices();(t=o.length>0)?speak("Please press the microphone button to start speaking",()=>{}):(document.getElementById("spoken").innerHTML="Please press the microphone button to start speaking",document.getElementById("spoken").removeAttribute("id"))}}else document.getElementById("spoken").innerHTML="Sorry, your browser doesn't support speech synthesis. Please use a more modern browser or check your settings.",document.getElementById("speak").remove()}utterance.onboundary=function(e){let t=getWordAt(utterance.text,e.charIndex);t!==lastSpokenWord&&(document.getElementById("spoken").innerHTML+=t+" ",lastSpokenWord=t,scrollToBottom())},window.parent.document.querySelector("#voice").addEventListener("change",()=>{utterance.voice=speechSynthesis.getVoices().filter(function(e){return e.name==window.parent.document.querySelector("#voice").value})[0],window.parent.document.querySelector('#voice [value="default"]')&&window.parent.document.querySelector('#voice [value="default"]').remove()}),window.parent.document.querySelector("#speed").addEventListener("change",()=>{utterance.rate=window.parent.document.querySelector("#speed").value,window.parent.document.querySelector("#numSpeed").innerHTML=window.parent.document.querySelector("#speed").value}),window.parent.document.querySelector("#pitch").addEventListener("change",()=>{utterance.pitch=window.parent.document.querySelector("#pitch").value,window.parent.document.querySelector("#numPitch").innerHTML=window.parent.document.querySelector("#pitch").value});const speechRecognition=new webkitSpeechRecognition,updateInterval=1e3;let currentContext,globalStream,blink=!0,isListening=!1,final_transcript="",lastTranscriptUpdateTime=Date.now(),personalize="default";function enableMic(){navigator.mediaDevices.getUserMedia({video:!1,audio:!0}).then(e=>{let t=speechSynthesis.getVoices();t.forEach(e=>{let t=document.createElement("option");t.value=e.name,t.textContent=e.name,window.parent.document.querySelector("#voice").appendChild(t)}),window.parent.postMessage("Start Read","*"),globalStream=e,speechRecognition.stop(),document.getElementById("speak").style.bottom="2px",document.getElementById("speak").style.left="5px",document.getElementById("speak").style.transform="scale(0.5)",document.getElementById("speak").removeAttribute("onclick"),document.getElementById("speak-icon").innerHTML="mic",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("Welcome!",function(){document.getElementById("m1").style.display="inline"}),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("You will always talk after I finish speaking, or until the microphone icon starts flashing red. To stop the conversation, just say 'see you later'! Got it? Great!",function(){document.getElementById("m2").style.display="inline"}),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("So, what's on your mind?",function(){window.parent.postMessage("End Read","*"),document.getElementById("speak-icon").innerHTML="mic",blink=!0,blinkRed(),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"You: Speak...
",speechRecognition.start()})}).catch(e=>{window.parent.postMessage("Declined","*"),document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"System: "+e+"
",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",document.getElementById("speak-icon").innerHTML="error",speak("Please click the icon to try again and enable your microphone, and try checking your browser settings")})}function blinkRed(){blink&&("red"===document.getElementById("speak-icon").style.color?document.getElementById("speak-icon").style.color="white":document.getElementById("speak-icon").style.color="red",setTimeout(blinkRed,1e3))}speechRecognition.lang="en-US",speechRecognition.continuous=!0,speechRecognition.interimResults=!0,speechRecognition.onerror=()=>{isListening=!1},speechRecognition.onend=()=>{final_transcript?(window.parent.postMessage("Thinking","*"),isListening=!1,blink=!1,document.getElementById("yourTalk").style.color="#fff",document.getElementById("yourTalk").innerHTML=final_transcript.charAt(0).toUpperCase()+final_transcript.slice(1),document.getElementById("yourTalk").removeAttribute("id"),document.getElementById("speak-icon").style.color="white","see you later"===final_transcript.toLowerCase()?(window.postMessage("Wave","*"),document.getElementById("speak-icon").innerHTML="mic_off",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT:
",speak("Goodbye, hope we talk again soon!",function(){})):(document.getElementById("speak-icon").innerHTML="pending",document.getElementById("output").innerHTML=document.getElementById("output").innerHTML+"TalkGPT: Thinking...
",scrollToBottom(),fetch("https://talkgpt-1-r6338284.deta.app/ask/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:final_transcript,context:currentContext,personality:personalize})}).then(e=>e.json()).then(e=>{window.parent.postMessage("Start Read","*"),currentContext=e.context,document.getElementById("spoken").innerHTML="",speak(e.response,function(){window.parent.postMessage("End Read","*"),document.getElementById("speak-icon").innerHTML="mic",blink=!0,blinkRed(),document.getElementById("output").innerHTML+="You: Speak...
",speechRecognition.start()})}),final_transcript="")):speechRecognition.start()},speechRecognition.onresult=e=>{scrollToBottom(),lastTranscriptUpdateTime=Date.now(),isListening||(isListening=!0);let t="";for(let n=e.resultIndex;n{personalize=window.parent.document.querySelector("#personality").value}),setInterval(function(){if(isListening){let e=Date.now()-lastTranscriptUpdateTime;e>1e3&&speechRecognition.stop()}},250);