-
-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete migration of web-api to local repo
- Loading branch information
Showing
5 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/gesturerecog/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/control_utils/control_utils.js" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>Processing MediaPipe Camera Input...</h1> | ||
<video class="input_video" hidden></video> | ||
</div> | ||
|
||
<script type="module"> | ||
const videoElement = document.getElementsByClassName('input_video')[0]; | ||
|
||
// Create WebSocket connection. | ||
const socket = new WebSocket('ws:https://localhost:55560'); | ||
|
||
function onResults(results) { | ||
if (results.multiHandLandmarks) { | ||
// hand id | ||
var id = 0; | ||
for (const landmarks of results.multiHandLandmarks) { | ||
var data = "" + id + ","; | ||
|
||
landmarks.forEach(point => { | ||
data += point.x + "," + point.y + "," + point.z + ","; | ||
}); | ||
|
||
socket.send(data); | ||
|
||
id++; | ||
} | ||
} | ||
} | ||
|
||
const hands = new Hands({locateFile: (file) => { | ||
return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; | ||
}}); | ||
hands.setOptions({ | ||
maxNumHands: 2, | ||
modelComplexity: 1, | ||
minDetectionConfidence: 0.5, | ||
minTrackingConfidence: 0.5 | ||
}); | ||
hands.onResults(onResults); | ||
|
||
// pick a mid-quality resolution | ||
const camera = new Camera(videoElement, { | ||
onFrame: async () => { | ||
await hands.send({image: videoElement}); | ||
}, | ||
width: 853, | ||
height: 480 | ||
}); | ||
camera.start(); | ||
</script> | ||
|
||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/speechrecog/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Speech-to-text</title> | ||
</head> | ||
|
||
<body> | ||
<h2>Speech-to-text service</h2> | ||
<script src="../rpc-common.js"></script> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
43 changes: 43 additions & 0 deletions
43
fxgl-intelligence/src/main/resources/com/almasb/fxgl/intelligence/speechrecog/script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition | ||
var SpeechGrammarList = SpeechGrammarList || window.webkitSpeechGrammarList | ||
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent | ||
|
||
const socket = new WebSocket('ws:https://localhost:55555'); | ||
|
||
socket.addEventListener('open', function (event) { | ||
initService(); | ||
}); | ||
|
||
// set up speech recog | ||
const recognition = new SpeechRecognition(); | ||
recognition.continuous = true; | ||
recognition.lang = 'en-GB'; | ||
recognition.interimResults = false; | ||
recognition.maxAlternatives = 1; | ||
|
||
recognition.onresult = (event) => { | ||
// latest result | ||
var result = event.results[event.results.length - 1][0]; | ||
var inputText = result.transcript; | ||
var confidence = result.confidence; | ||
|
||
// only call if we have something | ||
if (inputText.length > 0) { | ||
rpcRun("onSpeechInput", inputText, confidence); | ||
} | ||
} | ||
|
||
recognition.onend = (event) => { | ||
recognition.start(); | ||
} | ||
|
||
recognition.onerror = function(event) { | ||
// not much use recording event.error, so just restart | ||
recognition.start(); | ||
} | ||
|
||
recognition.start(); | ||
|
||
function initService() { | ||
rpcRun("initService"); | ||
} |