From c5c3c34f98929cb7b70629eced2c2fccdff6fd58 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Thu, 6 Jun 2024 16:50:03 +0200 Subject: [PATCH] post-it note escape hatch --- index.html | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index f0bd24b..8b0dad7 100644 --- a/index.html +++ b/index.html @@ -55,6 +55,7 @@ const SpeechRecognition = window.webkitSpeechRecognition; recognizer = new SpeechRecognition(); recognizer.interimResults = true; recognizer.continuous = true; +// does not work recognizer.lang = 'fr-FR'; recognizer.lang = 'en-US'; const aframeprimitives = getAllPrimitives() @@ -66,34 +67,31 @@ recognizer.onresult = (event) => { if (result.isFinal) { console.log('You said: ' + result[0].transcript ) - // should instead look if starting with speechContent following by aframeprimitives, optionally speechcustomcomponents - // then apply accordingly let speechContent = result[0].transcript - // let newPostIt = addNewNoteAsPostItNote(speechContent, "0 1.2 -.5") - // could become jxr code proper later, also allowing to re-execute a command again + let latest = addedContent.at(-1) let cmd_words = speechContent.split(" ").map( i => i.toLowerCase() ) - if (cmd_words[0] == speechactions[0]){ // limited to add command for now + let el + + switch(cmd_words[0]) { + case speechactions[0]: console.log("recognized proper command") let primitive = cmd_words[1] // assuming fixed order for now - let el = document.createElement("a-"+primitive) + el = document.createElement("a-"+primitive) el.setAttribute("target", "") el.setAttribute("scale", ".1 .1 .1") el.setAttribute("position", "0 1.5 -0.4") addedContent.push(el) AFRAME.scenes[0].appendChild( el ) - } - - if (cmd_words[0] == speechactions[1]){ // limited to apply + break; + case speechactions[1] : console.log("recognized apply command") - addedContent.at(-1).setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now - } - - if (cmd_words[0] == speechactions[2]) - deleteTarget( addedContent.at(-1) ) - - let latest = addedContent.at(-1) - if (cmd_words[0] == speechactions[3]){ - let el = latest.cloneNode(true) // does not work properly, losing some attributes, in particular scale can be problematic + latest.setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now + break; + case speechactions[2] : + deleteTarget( latest ) + break; + case speechactions[3] : + el = latest.cloneNode(true) // does not work properly, losing some attributes, in particular scale can be problematic //["scale", "position", "rotation", "wireframe", "target", "material"].map( prop => el.setAttribute(prop, latest.getAttribute(prop) ) ) //["scale", "position", "rotation", "target" ].map( prop => el.setAttribute(prop, latest.getAttribute(prop) ) ) el.setAttribute("scale", latest.getAttribute("scale") ) @@ -105,11 +103,15 @@ recognizer.onresult = (event) => { // could optionally add a number of times addedContent.push(el) AFRAME.scenes[0].appendChild( el ) - el.object3D.translateX(1) - } - - if (cmd_words[0] == speechactions[4]) - getModelFromKeyword( cmd_words[1] ) + el.object3D.translateX(10) // due to scaling + break; + case speechactions[4] : + getModelFromKeyword( cmd_words[1] ) // requires the backend (proxy, LAN only for now, waiting for API clarification on 403) + break; + default: + addedContent.push( addNewNoteAsPostItNote(speechContent, "0 1.2 -.5") ) + // could become jxr code proper later, also allowing to re-execute a command again + } } } recognizer.start();