Skip to content

Commit

Permalink
Change: metasをマージするように
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Oct 28, 2023
1 parent df6bb37 commit a958ffb
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions android/app/src/main/java/jp/hiroshiba/voicevox/CorePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class CorePlugin : Plugin() {
lateinit var openJtalk: OpenJtalk
lateinit var synthesizer: Synthesizer
lateinit var voiceModels: List<VoiceModel>
lateinit var metas: List<VoiceModel.SpeakerMeta>
lateinit var gson: Gson

@PluginMethod
Expand All @@ -43,6 +42,16 @@ class CorePlugin : Plugin() {
@PluginMethod
fun getMetasJson(call: PluginCall) {
val ret = JSObject()
val flatMetas = voiceModels.flatMap { it.metas.asIterable() }
val metas = flatMetas.map { it.speakerUuid }.toSet().map { speakerUuid ->
val baseMetas = flatMetas.filter { it.speakerUuid == speakerUuid }
val styles = baseMetas.flatMap { it.styles.asIterable() }
val mergedMetas =
gson.toJsonTree(baseMetas[0]).asJsonObject
mergedMetas.add("styles", gson.toJsonTree(styles))

mergedMetas
}
val metasJson = gson.toJson(metas)
ret.put("value", metasJson)
call.resolve(ret)
Expand Down Expand Up @@ -81,12 +90,6 @@ class CorePlugin : Plugin() {
VoiceModel(it.absolutePath)
}

Log.i("CorePlugin", "Initializing metas")
val metasJson = File(modelPath, "metas.json")
metas = gson.fromJson(
metasJson.readText(), Array<VoiceModel.SpeakerMeta>::class.java
).toList()

call.resolve()
} catch (e: VoicevoxException) {
call.reject(e.message)
Expand Down

0 comments on commit a958ffb

Please sign in to comment.