commit 11/12/2025

This commit is contained in:
2025-12-11 08:21:39 +07:00
parent cbca8cd43d
commit bdb24a7c03
5 changed files with 66 additions and 8 deletions

View File

@@ -13,4 +13,26 @@ enum class Language(name: String) {
JAPANESE("JAPANESE"), JAPANESE("JAPANESE"),
CHINESE("CHINESE"), CHINESE("CHINESE"),
ARABIC("ARABIC"); 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
}
}
}
} }

View File

@@ -10,4 +10,15 @@ enum class VoiceType(voicename: String) {
VOICE_1("VOICE_1"), VOICE_1("VOICE_1"),
VOICE_2("VOICE_2"), VOICE_2("VOICE_2"),
VOICE_3("VOICE_3"); 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
}
}
}
} }

View File

@@ -4,4 +4,14 @@ package google
enum class autoadd(name: String) { enum class autoadd(name: String) {
ADD("add"), ADD("add"),
SKIP("skip"); SKIP("skip");
companion object {
fun fromString(name: String): autoadd {
return when (name.lowercase()) {
"add" -> ADD
"skip" -> SKIP
else -> ADD
}
}
}
} }

View File

@@ -4,4 +4,14 @@ package google
enum class fileoperation(name: String) { enum class fileoperation(name: String) {
OVERWRITE("overwrite"), OVERWRITE("overwrite"),
SKIP("skip"); SKIP("skip");
companion object {
fun fromString(name: String): fileoperation {
return when (name.lowercase()) {
"overwrite" -> OVERWRITE
"skip" -> SKIP
else -> OVERWRITE
}
}
}
} }

View File

@@ -45,6 +45,8 @@ import codes.configKeys
import config import config
import database.QueueTable import database.QueueTable
import google.GoogleTTS import google.GoogleTTS
import google.autoadd
import google.fileoperation
import io.javalin.websocket.WsCloseStatus import io.javalin.websocket.WsCloseStatus
import org.tinylog.Logger import org.tinylog.Logger
import java.io.File import java.io.File
@@ -210,10 +212,13 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
val languagecode = js.get("languagecode")?.asText("id-ID") ?: "id-ID" val languagecode = js.get("languagecode")?.asText("id-ID") ?: "id-ID"
val databasesource = js.get("databasesource")?.asText("VOICE_1") ?: "VOICE_1" val databasesource = js.get("databasesource")?.asText("VOICE_1") ?: "VOICE_1"
val targetas = js.get("targetas")?.asText("VOICE_2") ?: "VOICE_2" val targetas = js.get("targetas")?.asText("VOICE_2") ?: "VOICE_2"
val fileoperation = js.get("fileoperation")?.asText("overwrite") ?: "overwrite" val fop = js.get("fileoperation")?.asText("overwrite") ?: "overwrite"
val autoadd = js.get("autoadd")?.asText("add") ?: "add" val aa = js.get("autoadd")?.asText("add") ?: "add"
Logger.info {"Starting TTS Soundbank Generation, VoiceType=$voicetype, Language"} 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( SendReply(wsMessageContext, "tts_generate_progress", objectmapper.writeValueAsString(
mapOf( mapOf(
"progress" to progress, "progress" to progress,
@@ -427,7 +432,7 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
val key = ctx.cookie("client-stream-id") val key = ctx.cookie("client-stream-id")
if (command == "Open"){ if (command == "Open"){
// open command // open command
if (key!=null && key.isNotEmpty()){ if (!key.isNullOrEmpty()){
// ada connection sebelumnya, kemungkinan reconnect // ada connection sebelumnya, kemungkinan reconnect
val prev = WsContextMap[key] val prev = WsContextMap[key]
if (prev!=null){ if (prev!=null){
@@ -445,7 +450,7 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
} else { } else {
// close command // close command
if (key!=null && key.isNotEmpty()){ if (!key.isNullOrEmpty()){
// close connection // close connection
val prev = WsContextMap[key] val prev = WsContextMap[key]
if (prev!=null){ if (prev!=null){
@@ -465,7 +470,7 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
ws("ws"){ wscontext -> ws("ws"){ wscontext ->
wscontext.onConnect { wscontext.onConnect {
val key = it.cookie("client-stream-id") val key = it.cookie("client-stream-id")
if (key!=null && key.isNotEmpty()){ if (!key.isNullOrEmpty()){
val lld = WsContextMap[key] val lld = WsContextMap[key]
if (lld!=null){ if (lld!=null){
it.enableAutomaticPings() it.enableAutomaticPings()
@@ -490,7 +495,7 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
} }
wscontext.onClose { wscontext.onClose {
val key = it.cookie("client-stream-id") val key = it.cookie("client-stream-id")
if (key!=null && key.isNotEmpty()){ if (!key.isNullOrEmpty()){
val lld = WsContextMap[key] val lld = WsContextMap[key]
lld?.bc?.Remove_Mp3_Consumer(key) lld?.bc?.Remove_Mp3_Consumer(key)
lld?.ws?.closeSession() lld?.ws?.closeSession()
@@ -731,7 +736,7 @@ class WebApp(val listenPort: Int, var userlist: List<Pair<String, String>>, val
.result(objectmapper.writeValueAsString(resultMessage("Failed to update soundbank with index $index"))) .result(objectmapper.writeValueAsString(resultMessage("Failed to update soundbank with index $index")))
} else it.status(400) } else it.status(400)
.result(objectmapper.writeValueAsString(resultMessage("Nothing has changed for soundbank with index $index"))) .result(objectmapper.writeValueAsString(resultMessage("Nothing has changed for soundbank with index $index")))
} else Exception("Some fields are empty") }
} catch (e: Exception) { } catch (e: Exception) {
it.status(400) it.status(400)
.result(objectmapper.writeValueAsString(resultMessage("Unable to parse request body to Soundbank, Message: ${e.message}"))) .result(objectmapper.writeValueAsString(resultMessage("Unable to parse request body to Soundbank, Message: ${e.message}")))