Here's the script! To learn more about what we're up to at walkthrough.ai checkout our homepage!
Instructions
Complete the following three steps.
Step 1:
Open the ChatGPT website in your Chrome browser.
Step 2:
Open the developer console by pressing Ctrl+Shift+I or right-clicking anywhere on the page and selecting “Inspect”. Open the “Console” tab.
Step 3:
Paste in the Javascript code and start chatting! You can just have a natural conversation without key-words.
The Script
const SpeechRecognition = window.SpeechRecognition || webkitSpeechRecognition; // Create a new SpeechRecognition instance. const recognition =newSpeechRecognition(); recognition.lang ="en-US"; recognition.continuous =true; recognition.maxAlternatives =1; recognition.interimResults =false; // Get UI elements. const formTextarea = document.querySelector("main form textarea"); const formSubmit = document.querySelector("main form button"); // Set global variables. let isSpeaking =false; let intervalRcg, intervalUtr; // Start the voice synthesis. functionstartVoiceSynth(){ isSpeaking =true; functionsayResult(){ // If everything has been said, stop the interval. if(this.innerText ===this.spokenText){ clearInterval(intervalUtr); isSpeaking =false; return; } // Slice unspoken text that and create a new utterance. speechSynthesis.speak( newSpeechSynthesisUtterance( this.innerText.slice((this.spokenText ||"").length) ) ); this.spokenText =this.innerText; } intervalUtr =setInterval( sayResult.bind(document.querySelector(".result-streaming")), 500 ); } // Check if the button is re-enabled, then start recognition. functionpollResultStatus(){ intervalRcg =setInterval(()=>{ if(formSubmit.disabled || isSpeaking)return; recognition.start(); clearInterval(intervalRcg); },500); } /// Input the text into the textarea and submit the form. functionfillAndsubmitForm(event){ const result = event.results[0][0].transcript; if(result =="stop")return; formTextarea.value = result; formSubmit.click(); } // On result, stop the recognition, fill the form, and start the UI for results. recognition.onresult=(event)=>{ recognition.stop(); fillAndsubmitForm(event); setTimeout(pollResultStatus,1000); setTimeout(startVoiceSynth,1000); }; // Start recognition. recognition.start();
Tags:
Post by
walkthrough.ai
February 18, 2023
February 18, 2023
Comments