File size: 5,535 Bytes
f563b68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
if (typeof gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded !== "undefined") {
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.registeredGdjsCallbacks.forEach(callback =>
gdjs._unregisterCallback(callback)
);
}
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded = {};
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.userFunc0x83f3a8 = function GDJSInlineCode(runtimeScene, eventsFunctionContext) {
"use strict";
function VoiceRecognition() {
this.errorStatus = false;
this.successStatus = false;
this.setStatus = function (status) {
this.status = status;
}
this.setError = function (error) {
this.error = error;
}
this.setResultText = function (result) {
this.result = result;
}
this.getResultText = function () {
return this.result;
}
this.getStatus = function () {
return this.status;
}
this.getError = function () {
return this.error;
}
this.setLanguage = function (lang) {
this.recognition.lang = lang;
}
let parent = this;
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition
var SpeechGrammarList = SpeechGrammarList || window.webkitSpeechGrammarList
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent
this.recognition = new SpeechRecognition();
this.recognition.continuous = false;
this.recognition.interimResults = false;
this.recognition.maxAlternatives = 1;
// This runs when the speech recognition service starts
this.recognition.onstart = function() {
parent.setStatus("listening, please speak...");
};
this.recognition.onspeechend = function() {
parent.recognition.stop();
}
this.recognition.onerror = function(event) {
parent.errorStatus = true;
parent.setError('Error occurred in recognition: ' + event.error);
}
// This runs when the speech recognition service returns result
this.recognition.onresult = function(event) {
var transcript = event.results[0][0].transcript;
var confidence = event.results[0][0].confidence;
parent.successStatus = true;
parent.confidence = confidence;
parent.setResultText(transcript);
};
// start recognition
this.startListening = function() {
parent.recognition.start();
parent.errorStatus = false;
parent.successStatus = false;
parent.setStatus("listening, please speak...");
}
}
if(gdjs._extensionVoiceRecognition == undefined) {
gdjs._extensionVoiceRecognition = new VoiceRecognition();
}
};
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.eventsList0 = function(runtimeScene, eventsFunctionContext) {
{
let isConditionTrue_0 = false;
{
}
}
{
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.userFunc0x83f3a8(runtimeScene, typeof eventsFunctionContext !== 'undefined' ? eventsFunctionContext : undefined);
}
};
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.func = function(runtimeScene, parentEventsFunctionContext) {
var eventsFunctionContext = {
_objectsMap: {
},
_objectArraysMap: {
},
_behaviorNamesMap: {
},
globalVariablesForExtension: runtimeScene.getGame().getVariablesForExtension("VoiceRecognition"),
sceneVariablesForExtension: runtimeScene.getScene().getVariablesForExtension("VoiceRecognition"),
localVariables: [],
getObjects: function(objectName) {
return eventsFunctionContext._objectArraysMap[objectName] || [];
},
getObjectsLists: function(objectName) {
return eventsFunctionContext._objectsMap[objectName] || null;
},
getBehaviorName: function(behaviorName) {
return eventsFunctionContext._behaviorNamesMap[behaviorName] || behaviorName;
},
createObject: function(objectName) {
const objectsList = eventsFunctionContext._objectsMap[objectName];
if (objectsList) {
const object = parentEventsFunctionContext ?
parentEventsFunctionContext.createObject(objectsList.firstKey()) :
runtimeScene.createObject(objectsList.firstKey());
if (object) {
objectsList.get(objectsList.firstKey()).push(object);
eventsFunctionContext._objectArraysMap[objectName].push(object);
}
return object; }
return null;
},
getInstancesCountOnScene: function(objectName) {
const objectsList = eventsFunctionContext._objectsMap[objectName];
let count = 0;
if (objectsList) {
for(const objectName in objectsList.items)
count += parentEventsFunctionContext ?
parentEventsFunctionContext.getInstancesCountOnScene(objectName) :
runtimeScene.getInstancesCountOnScene(objectName);
}
return count;
},
getLayer: function(layerName) {
return runtimeScene.getLayer(layerName);
},
getArgument: function(argName) {
return "";
},
getOnceTriggers: function() { return runtimeScene.getOnceTriggers(); }
};
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.eventsList0(runtimeScene, eventsFunctionContext);
return;
}
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.registeredGdjsCallbacks = [];
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.registeredGdjsCallbacks.push((runtimeScene) => {
gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.func(runtimeScene, runtimeScene);
})
gdjs.registerFirstRuntimeSceneLoadedCallback(gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.registeredGdjsCallbacks[gdjs.evtsExt__VoiceRecognition__onFirstSceneLoaded.registeredGdjsCallbacks.length - 1]);
|