|
|
@ -55,6 +55,7 @@ const SpeechRecognition = window.webkitSpeechRecognition; |
|
|
|
recognizer = new SpeechRecognition(); |
|
|
|
recognizer = new SpeechRecognition(); |
|
|
|
recognizer.interimResults = true; |
|
|
|
recognizer.interimResults = true; |
|
|
|
recognizer.continuous = true; |
|
|
|
recognizer.continuous = true; |
|
|
|
|
|
|
|
// does not work recognizer.lang = 'fr-FR'; |
|
|
|
recognizer.lang = 'en-US'; |
|
|
|
recognizer.lang = 'en-US'; |
|
|
|
|
|
|
|
|
|
|
|
const aframeprimitives = getAllPrimitives() |
|
|
|
const aframeprimitives = getAllPrimitives() |
|
|
@ -66,34 +67,31 @@ recognizer.onresult = (event) => { |
|
|
|
if (result.isFinal) { |
|
|
|
if (result.isFinal) { |
|
|
|
console.log('You said: ' + result[0].transcript ) |
|
|
|
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 speechContent = result[0].transcript |
|
|
|
// let newPostIt = addNewNoteAsPostItNote(speechContent, "0 1.2 -.5") |
|
|
|
let latest = addedContent.at(-1) |
|
|
|
// could become jxr code proper later, also allowing to re-execute a command again |
|
|
|
|
|
|
|
let cmd_words = speechContent.split(" ").map( i => i.toLowerCase() ) |
|
|
|
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") |
|
|
|
console.log("recognized proper command") |
|
|
|
let primitive = cmd_words[1] // assuming fixed order for now |
|
|
|
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("target", "") |
|
|
|
el.setAttribute("scale", ".1 .1 .1") |
|
|
|
el.setAttribute("scale", ".1 .1 .1") |
|
|
|
el.setAttribute("position", "0 1.5 -0.4") |
|
|
|
el.setAttribute("position", "0 1.5 -0.4") |
|
|
|
addedContent.push(el) |
|
|
|
addedContent.push(el) |
|
|
|
AFRAME.scenes[0].appendChild( el ) |
|
|
|
AFRAME.scenes[0].appendChild( el ) |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case speechactions[1] : |
|
|
|
if (cmd_words[0] == speechactions[1]){ // limited to apply |
|
|
|
|
|
|
|
console.log("recognized apply command") |
|
|
|
console.log("recognized apply command") |
|
|
|
addedContent.at(-1).setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now |
|
|
|
latest.setAttribute( cmd_words[1], cmd_words[2]) // assuming fixed order for now |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
case speechactions[2] : |
|
|
|
if (cmd_words[0] == speechactions[2]) |
|
|
|
deleteTarget( latest ) |
|
|
|
deleteTarget( addedContent.at(-1) ) |
|
|
|
break; |
|
|
|
|
|
|
|
case speechactions[3] : |
|
|
|
let latest = addedContent.at(-1) |
|
|
|
el = latest.cloneNode(true) // does not work properly, losing some attributes, in particular scale can be problematic |
|
|
|
if (cmd_words[0] == speechactions[3]){ |
|
|
|
|
|
|
|
let 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", "wireframe", "target", "material"].map( prop => el.setAttribute(prop, latest.getAttribute(prop) ) ) |
|
|
|
//["scale", "position", "rotation", "target" ].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") ) |
|
|
|
el.setAttribute("scale", latest.getAttribute("scale") ) |
|
|
@ -105,11 +103,15 @@ recognizer.onresult = (event) => { |
|
|
|
// could optionally add a number of times |
|
|
|
// could optionally add a number of times |
|
|
|
addedContent.push(el) |
|
|
|
addedContent.push(el) |
|
|
|
AFRAME.scenes[0].appendChild( el ) |
|
|
|
AFRAME.scenes[0].appendChild( el ) |
|
|
|
el.object3D.translateX(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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cmd_words[0] == speechactions[4]) |
|
|
|
|
|
|
|
getModelFromKeyword( cmd_words[1] ) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
recognizer.start(); |
|
|
|
recognizer.start(); |
|
|
|