From bfc98a1c8105cbeeb9ea8def9192b95b0eab0b34 Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Tue, 1 Jan 2019 22:47:18 +0100 Subject: [PATCH] Add recognizer support to Spine integration --- .../rhubarb_for_spine/AudioFileModel.kt | 3 ++- .../rhubarb_for_spine/MainModel.kt | 15 ++++++++++++++- .../rhubarb_for_spine/MainView.kt | 15 +++++++++++++++ .../rhubarb_for_spine/RhubarbTask.kt | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt index e9f41c6..632782c 100644 --- a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt +++ b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/AudioFileModel.kt @@ -141,11 +141,12 @@ class AudioFileModel( private fun startAnimation() { val wrapperTask = Runnable { + val recognizer = parentModel.parentModel.recognizer.value val extendedMouthShapes = parentModel.mouthShapes.filter { it.isExtended }.toSet() val reportProgress: (Double?) -> Unit = { progress -> runAndWait { this@AudioFileModel.animationProgress = progress } } - val rhubarbTask = RhubarbTask(audioFilePath, dialog, extendedMouthShapes, reportProgress) + val rhubarbTask = RhubarbTask(audioFilePath, recognizer, dialog, extendedMouthShapes, reportProgress) try { try { val result = rhubarbTask.call() diff --git a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt index 9010146..6378aad 100644 --- a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt +++ b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainModel.kt @@ -2,6 +2,8 @@ package com.rhubarb_lip_sync.rhubarb_for_spine import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleStringProperty +import javafx.collections.FXCollections +import javafx.collections.ObservableList import tornadofx.FX import tornadofx.getValue import tornadofx.setValue @@ -40,6 +42,15 @@ class MainModel(private val executor: ExecutorService) { var animationFileModel by animationFileModelProperty private set + val recognizersProperty = SimpleObjectProperty>(FXCollections.observableArrayList( + Recognizer("pocketSphinx", "PocketSphinx (use for English recordings)"), + Recognizer("phonetic", "Phonetic (use for non-English recordings)") + )) + private var recognizers: ObservableList by recognizersProperty + + val recognizerProperty = SimpleObjectProperty(recognizers[0]) + var recognizer: Recognizer by recognizerProperty + val animationPrefixProperty = SimpleStringProperty("say_") var animationPrefix: String by animationPrefixProperty @@ -47,4 +58,6 @@ class MainModel(private val executor: ExecutorService) { var animationSuffix: String by animationSuffixProperty private fun getDefaultPathString() = FX.application.parameters.raw.firstOrNull() -} \ No newline at end of file +} + +class Recognizer(val value: String, val description: String) diff --git a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt index 13e2316..7a67e91 100644 --- a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt +++ b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/MainView.kt @@ -17,6 +17,7 @@ import javafx.scene.text.Font import javafx.scene.text.FontWeight import javafx.scene.text.Text import javafx.stage.FileChooser +import javafx.util.StringConverter import tornadofx.* import java.io.File import java.util.concurrent.Executors @@ -83,6 +84,20 @@ class MainView : View() { } } } + field("Dialog recognizer") { + combobox { + itemsProperty().bind(mainModel.recognizersProperty) + this.converter = object : StringConverter() { + override fun toString(recognizer: Recognizer?): String { + return recognizer?.description ?: "" + } + override fun fromString(string: String?): Recognizer { + throw NotImplementedError() + } + } + valueProperty().bindBidirectional(mainModel.recognizerProperty) + } + } field("Animation naming") { textfield { maxWidth = 100.0 diff --git a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/RhubarbTask.kt b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/RhubarbTask.kt index 0268003..0694e79 100644 --- a/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/RhubarbTask.kt +++ b/extras/EsotericSoftwareSpine/src/main/kotlin/com/rhubarb_lip_sync/rhubarb_for_spine/RhubarbTask.kt @@ -14,6 +14,7 @@ import java.util.concurrent.Callable class RhubarbTask( val audioFilePath: Path, + val recognizer: String, val dialog: String?, val extendedMouthShapes: Set, val reportProgress: (Double?) -> Unit @@ -89,6 +90,7 @@ class RhubarbTask( return mutableListOf( rhubarbBinFilePath.toString(), "--machineReadable", + "--recognizer", recognizer, "--exportFormat", "json", "--extendedShapes", extendedMouthShapesString ).apply { @@ -100,7 +102,6 @@ class RhubarbTask( }.apply { add(audioFilePath.toString()) } - } private val guiBinDirectory: Path by lazy {