Skip to content

Commit

Permalink
Merge pull request #8 from Here-Charlie/prototype
Browse files Browse the repository at this point in the history
Camera Improvements
  • Loading branch information
Larry-Larriee committed Jun 13, 2023
2 parents 60ff4d7 + 5961ccf commit 5d20634
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/components/roboflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const Roboflow = (props) => {
const webcamRef = useRef(null);
const canvasRef = useRef(null);
var inferRunning = useRef(true);
var tempClass = "";
var sayItOnce = true;

// Text to Speech
const synthesis = window.speechSynthesis;

const startInfer = () => {
window.roboflow
Expand All @@ -20,10 +21,9 @@ const Roboflow = (props) => {
console.log("model loaded");
}
}).then((model) => {
// Detect every 10 miliseconds
setInterval(() => {
if (inferRunning) detect(model);
}, 0.5);
}, 10);
});
};

Expand Down Expand Up @@ -112,28 +112,20 @@ const Roboflow = (props) => {
const textHeight = fontSize;
var textWidth = ctx.measureText(msgTxt).width;

// Text to Speech
const synthesis = window.speechSynthesis;

// Text to Speech metadata
var utterance = new SpeechSynthesisUtterance(classTxt);

// synthesis.cancel();
// synthesis.speak(utterance);

if(tempClass === classTxt && row.confidence*100 > 10 && sayItOnce){
// synthesis.cancel clears the thing currently spoken AND the queue
// making it wait one second allows tts to quickly say "person" and then clear everything
if (synthesis.speaking === false){
synthesis.speak(utterance);
sayItOnce = false;
// if(synthesis.pending === true){
// synthesis.cancel();
// }
} else {
synthesis.cancel();
tempClass = classTxt;
sayItOnce = true;
}


else{
// setTimeout is async so the detections will still render
setTimeout(() => {
synthesis.cancel();
}, 1000);
}

if (textHeight <= h && textWidth <= w) {
ctx.strokeStyle = row.color;
Expand Down Expand Up @@ -164,9 +156,6 @@ const Roboflow = (props) => {
});
};


// console.log(speechMetaData + "hello");

return (
<div className="roboflowCam">
<Webcam
Expand Down

0 comments on commit 5d20634

Please sign in to comment.