-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
93 additions
and
114 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
96 changes: 0 additions & 96 deletions
96
fxgl-intelligence/src/main/java/com/almasb/fxgl/speechrecog/SpeechRecognitionService.java
This file was deleted.
Oops, something went wrong.
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
54 changes: 54 additions & 0 deletions
54
...ence/src/main/kotlin/com/almasb/fxgl/intelligence/speechrecog/SpeechRecognitionService.kt
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,54 @@ | ||
/* | ||
* FXGL - JavaFX Game Library. The MIT License (MIT). | ||
* Copyright (c) AlmasB ([email protected]). | ||
* See LICENSE for details. | ||
*/ | ||
|
||
package com.almasb.fxgl.intelligence.speechrecog | ||
|
||
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 | ||
import com.almasb.fxgl.net.ws.LocalWebSocketServer | ||
import java.util.function.BiConsumer | ||
|
||
/** | ||
* @author Almas Baim (https://github.com/AlmasB) | ||
*/ | ||
class SpeechRecognitionService : WebAPIService( | ||
LocalWebSocketServer("SpeechRecogServer", WebAPI.SPEECH_RECOGNITION_PORT), | ||
WebAPI.SPEECH_RECOGNITION_API | ||
) { | ||
|
||
private val log = Logger.get(SpeechRecognitionService::class.java) | ||
|
||
private val speechInputHandlers = arrayListOf<BiConsumer<String, Double>>() | ||
|
||
/** | ||
* Add a [handler] for incoming speech input. | ||
*/ | ||
fun addInputHandler(handler: BiConsumer<String, Double>) { | ||
speechInputHandlers += handler | ||
} | ||
|
||
/** | ||
* Remove an existing input handler. | ||
*/ | ||
fun removeInputHandler(handler: BiConsumer<String, Double>) { | ||
speechInputHandlers -= handler | ||
} | ||
|
||
private fun initService() { | ||
setReady() | ||
} | ||
|
||
// TODO: expand API to also include alternative text options | ||
private fun onSpeechInput(text: String, confidence: Double) { | ||
log.debug("Received speech input ($confidence): $text") | ||
|
||
Async.startAsyncFX { | ||
speechInputHandlers.forEach { it.accept(text, confidence) } | ||
} | ||
} | ||
} |
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
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