diff --git a/src/content/Language.kt b/src/content/Language.kt index 97780d0..85b4bd9 100644 --- a/src/content/Language.kt +++ b/src/content/Language.kt @@ -13,4 +13,26 @@ enum class Language(name: String) { JAPANESE("JAPANESE"), CHINESE("CHINESE"), ARABIC("ARABIC"); + + companion object{ + fun from_GoogleTTSLanguage(lang: google.GoogleTTSLanguage) : Language { + return when(lang) { + google.GoogleTTSLanguage.Indonesia -> INDONESIA + google.GoogleTTSLanguage.English -> ENGLISH + google.GoogleTTSLanguage.Japanese -> JAPANESE + google.GoogleTTSLanguage.Chinese -> CHINESE + google.GoogleTTSLanguage.Arabic -> ARABIC + } + } + fun from_GoogleTTSLanguage(code: String) : Language { + return when(code) { + "id-ID" -> INDONESIA + "en-US" -> ENGLISH + "ja-JP" -> JAPANESE + "zh-CN" -> CHINESE + "ar-SA" -> ARABIC + else -> INDONESIA + } + } + } } \ No newline at end of file diff --git a/src/content/VoiceType.kt b/src/content/VoiceType.kt index 2bfdcff..a1e1a1c 100644 --- a/src/content/VoiceType.kt +++ b/src/content/VoiceType.kt @@ -10,4 +10,15 @@ enum class VoiceType(voicename: String) { VOICE_1("VOICE_1"), VOICE_2("VOICE_2"), VOICE_3("VOICE_3"); + + companion object { + fun fromString(name: String): VoiceType { + return when (name) { + "VOICE_1" -> VOICE_1 + "VOICE_2" -> VOICE_2 + "VOICE_3" -> VOICE_3 + else -> VOICE_1 + } + } + } } \ No newline at end of file diff --git a/src/google/autoadd.kt b/src/google/autoadd.kt index daa57ce..6f757e0 100644 --- a/src/google/autoadd.kt +++ b/src/google/autoadd.kt @@ -4,4 +4,14 @@ package google enum class autoadd(name: String) { ADD("add"), SKIP("skip"); + + companion object { + fun fromString(name: String): autoadd { + return when (name.lowercase()) { + "add" -> ADD + "skip" -> SKIP + else -> ADD + } + } + } } \ No newline at end of file diff --git a/src/google/fileoperation.kt b/src/google/fileoperation.kt index 94141e0..6e7b857 100644 --- a/src/google/fileoperation.kt +++ b/src/google/fileoperation.kt @@ -4,4 +4,14 @@ package google enum class fileoperation(name: String) { OVERWRITE("overwrite"), SKIP("skip"); + + companion object { + fun fromString(name: String): fileoperation { + return when (name.lowercase()) { + "overwrite" -> OVERWRITE + "skip" -> SKIP + else -> OVERWRITE + } + } + } } \ No newline at end of file diff --git a/src/web/WebApp.kt b/src/web/WebApp.kt index 9761544..379bfef 100644 --- a/src/web/WebApp.kt +++ b/src/web/WebApp.kt @@ -45,6 +45,8 @@ import codes.configKeys import config import database.QueueTable import google.GoogleTTS +import google.autoadd +import google.fileoperation import io.javalin.websocket.WsCloseStatus import org.tinylog.Logger import java.io.File @@ -210,10 +212,13 @@ class WebApp(val listenPort: Int, var userlist: List>, val val languagecode = js.get("languagecode")?.asText("id-ID") ?: "id-ID" val databasesource = js.get("databasesource")?.asText("VOICE_1") ?: "VOICE_1" val targetas = js.get("targetas")?.asText("VOICE_2") ?: "VOICE_2" - val fileoperation = js.get("fileoperation")?.asText("overwrite") ?: "overwrite" - val autoadd = js.get("autoadd")?.asText("add") ?: "add" + val fop = js.get("fileoperation")?.asText("overwrite") ?: "overwrite" + val aa = js.get("autoadd")?.asText("add") ?: "add" Logger.info {"Starting TTS Soundbank Generation, VoiceType=$voicetype, Language"} - ttsjob.GenerateSoundbank(voicetype, languagecode, databasesource, targetas, fileoperation, autoadd){ progress, message -> + ttsjob.GenerateSoundbank(voicetype, Language.from_GoogleTTSLanguage(languagecode), + VoiceType.fromString(databasesource), + VoiceType.fromString(targetas), fileoperation.fromString(fop), + autoadd.fromString(aa)){ progress, message -> SendReply(wsMessageContext, "tts_generate_progress", objectmapper.writeValueAsString( mapOf( "progress" to progress, @@ -427,7 +432,7 @@ class WebApp(val listenPort: Int, var userlist: List>, val val key = ctx.cookie("client-stream-id") if (command == "Open"){ // open command - if (key!=null && key.isNotEmpty()){ + if (!key.isNullOrEmpty()){ // ada connection sebelumnya, kemungkinan reconnect val prev = WsContextMap[key] if (prev!=null){ @@ -445,7 +450,7 @@ class WebApp(val listenPort: Int, var userlist: List>, val } else { // close command - if (key!=null && key.isNotEmpty()){ + if (!key.isNullOrEmpty()){ // close connection val prev = WsContextMap[key] if (prev!=null){ @@ -465,7 +470,7 @@ class WebApp(val listenPort: Int, var userlist: List>, val ws("ws"){ wscontext -> wscontext.onConnect { val key = it.cookie("client-stream-id") - if (key!=null && key.isNotEmpty()){ + if (!key.isNullOrEmpty()){ val lld = WsContextMap[key] if (lld!=null){ it.enableAutomaticPings() @@ -490,7 +495,7 @@ class WebApp(val listenPort: Int, var userlist: List>, val } wscontext.onClose { val key = it.cookie("client-stream-id") - if (key!=null && key.isNotEmpty()){ + if (!key.isNullOrEmpty()){ val lld = WsContextMap[key] lld?.bc?.Remove_Mp3_Consumer(key) lld?.ws?.closeSession() @@ -731,7 +736,7 @@ class WebApp(val listenPort: Int, var userlist: List>, val .result(objectmapper.writeValueAsString(resultMessage("Failed to update soundbank with index $index"))) } else it.status(400) .result(objectmapper.writeValueAsString(resultMessage("Nothing has changed for soundbank with index $index"))) - } else Exception("Some fields are empty") + } } catch (e: Exception) { it.status(400) .result(objectmapper.writeValueAsString(resultMessage("Unable to parse request body to Soundbank, Message: ${e.message}")))