JSFiddle - React, Tailwind, and code Playground

by ElijahCirioli

JavaScript

const speechRate = 1; //0-10 value
const depthCutoff = 6; //the maximum distance an object can be away before it is said to be far

const setupSpeech = () => {
	if (typeof speechSynthesis === "undefined") {
		return;
	}
};

//speak out a given string
const speak = str => {
	const sound = new SpeechSynthesisUtterance(str);

	sound.rate = speechRate;
	sound.voice = speechSynthesis.getVoices().filter(voice => {
		return voice.name === "Google US English";
	})[0];
	window.speechSynthesis.speak(sound);
};

document.onclick = e => {
	speak("Judge detected directly ahead... Thank you!")
}


speechSynthesis.onvoiceschanged = setupSpeech;