diff --git a/fxgl-intelligence/src/main/java/com/almasb/fxgl/intelligence/WebAPI.java b/fxgl-intelligence/src/main/java/com/almasb/fxgl/intelligence/WebAPI.java index 65f37b967..435703701 100644 --- a/fxgl-intelligence/src/main/java/com/almasb/fxgl/intelligence/WebAPI.java +++ b/fxgl-intelligence/src/main/java/com/almasb/fxgl/intelligence/WebAPI.java @@ -6,6 +6,8 @@ package com.almasb.fxgl.intelligence; +import com.almasb.fxgl.logging.Logger; + /** * Stores constants related to web-api projects. * Changes to these values must be synchronized with the web-api project (https://github.com/AlmasB/web-api). @@ -14,11 +16,31 @@ */ public final class WebAPI { - public static final String TEXT_TO_SPEECH_API = "https://almasb.github.io/web-api/text-to-speech-v1/"; + private static final Logger log = Logger.get(WebAPI.class); + + public static final String TEXT_TO_SPEECH_API = getURL("tts/index.html"); public static final String SPEECH_RECOGNITION_API = "https://almasb.github.io/web-api/speech-recog-v1/"; public static final String GESTURE_RECOGNITION_API = "https://almasb.github.io/web-api/gesture-recog-v1/"; public static final int TEXT_TO_SPEECH_PORT = 55550; public static final int SPEECH_RECOGNITION_PORT = 55555; public static final int GESTURE_RECOGNITION_PORT = 55560; + + static { + log.debug("TTS API: " + TEXT_TO_SPEECH_API + ":" + TEXT_TO_SPEECH_PORT); + } + + private static String getURL(String relativeURL) { + try { + var url = WebAPI.class.getResource(relativeURL).toExternalForm(); + + if (url != null) + return url; + + } catch (Exception e) { + log.warning("Failed to get url: " + relativeURL, e); + } + + return "DUMMY_URL"; + } } diff --git a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/WebAPIService.kt b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/WebAPIService.kt index e75e3905e..f0aa66575 100644 --- a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/WebAPIService.kt +++ b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/WebAPIService.kt @@ -85,6 +85,8 @@ abstract class WebAPIService(server: LocalWebSocketServer, private val apiURL: S driverSuppliers.forEach { supplier -> try { + log.debug("WebDriver opening: $url") + val driver = supplier() driver.get(url) return driver diff --git a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/Hand.kt b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/Hand.kt similarity index 92% rename from fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/Hand.kt rename to fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/Hand.kt index 643396b25..e2bfbd8d6 100644 --- a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/Hand.kt +++ b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/Hand.kt @@ -4,7 +4,7 @@ * See LICENSE for details. */ -package com.almasb.fxgl.gesturerecog +package com.almasb.fxgl.intelligence.gesturerecog import javafx.geometry.Point3D diff --git a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandLandmark.kt b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandLandmark.kt similarity index 93% rename from fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandLandmark.kt rename to fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandLandmark.kt index 2050eda8a..a92f3654a 100644 --- a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandLandmark.kt +++ b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandLandmark.kt @@ -4,7 +4,7 @@ * See LICENSE for details. */ -package com.almasb.fxgl.gesturerecog +package com.almasb.fxgl.intelligence.gesturerecog /** * The ordinal of each item matches the format defined at: diff --git a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandTrackingService.kt b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandTrackingService.kt similarity index 98% rename from fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandTrackingService.kt rename to fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandTrackingService.kt index 4ae576623..3dc235a36 100644 --- a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/gesturerecog/HandTrackingService.kt +++ b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/gesturerecog/HandTrackingService.kt @@ -4,7 +4,7 @@ * See LICENSE for details. */ -package com.almasb.fxgl.gesturerecog +package com.almasb.fxgl.intelligence.gesturerecog import com.almasb.fxgl.core.EngineService import com.almasb.fxgl.core.concurrent.Async diff --git a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/tts/TextToSpeechService.kt b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/tts/TextToSpeechService.kt index 5d6bd21de..cffc1c68a 100644 --- a/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/tts/TextToSpeechService.kt +++ b/fxgl-intelligence/src/main/kotlin/com/almasb/fxgl/intelligence/tts/TextToSpeechService.kt @@ -6,7 +6,6 @@ package com.almasb.fxgl.intelligence.tts -import com.almasb.fxgl.core.concurrent.Async import com.almasb.fxgl.intelligence.WebAPI import com.almasb.fxgl.intelligence.WebAPIService import com.almasb.fxgl.logging.Logger diff --git a/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/rpc-common.js b/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/rpc-common.js new file mode 100644 index 000000000..e5ac93f33 --- /dev/null +++ b/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/rpc-common.js @@ -0,0 +1,20 @@ +const SEPARATOR = "*,,*"; +const FUNCTION_CALL_TAG = "F_CALL:"; +const FUNCTION_RETURN_TAG = "F_RETURN:"; + +function rpcRun(funcName, ...args) { + let argsString = ""; + + for (const arg of args) { + argsString += arg + SEPARATOR; + } + + let message = `${FUNCTION_CALL_TAG}${funcName}${SEPARATOR}${argsString}`; + + socket.send(message); +} + +function rpcReturn(funcName) { + // TODO: unique id? + //socket.send(`${FUNCTION_RETURN_TAG}${funcName}.F_RESULT:${names}`); +} \ No newline at end of file diff --git a/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/tts/index.html b/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/tts/index.html new file mode 100644 index 000000000..b2ec0232a --- /dev/null +++ b/fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/tts/index.html @@ -0,0 +1,24 @@ + + +
+ + + +