From d1dc852c083fb85d06f930b59c198f8427606d8f Mon Sep 17 00:00:00 2001 From: Sakuya Kosugi Date: Wed, 29 Mar 2023 12:47:22 +0900 Subject: [PATCH] =?UTF-8?q?=E8=AA=AD=E3=81=BF=E4=B8=8A=E3=81=92=E6=96=87?= =?UTF-8?q?=E5=AD=97=E6=95=B0=E3=81=AE=E5=88=B6=E9=99=90=E3=81=AB=E9=81=94?= =?UTF-8?q?=E3=81=97=E3=81=9F=E9=9A=9B=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/sqldialects.xml | 4 ++-- .../dev/cosgy/textToSpeak/audio/Dictionary.kt | 2 +- .../cosgy/textToSpeak/audio/VoiceCreation.kt | 21 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 9a00d45..3dec230 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,8 +1,8 @@ - - + + \ No newline at end of file diff --git a/src/main/java/dev/cosgy/textToSpeak/audio/Dictionary.kt b/src/main/java/dev/cosgy/textToSpeak/audio/Dictionary.kt index 98d4558..fc7d934 100644 --- a/src/main/java/dev/cosgy/textToSpeak/audio/Dictionary.kt +++ b/src/main/java/dev/cosgy/textToSpeak/audio/Dictionary.kt @@ -26,7 +26,7 @@ import java.util.* import java.util.concurrent.ConcurrentHashMap import java.util.function.BiFunction -class Dictionary private constructor(private val bot: Bot) { +class Dictionary private constructor(bot: Bot) { private val logger = LoggerFactory.getLogger(this.javaClass) private val path: Path? private val create: Boolean diff --git a/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt b/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt index f63aaa0..57a57cd 100644 --- a/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt +++ b/src/main/java/dev/cosgy/textToSpeak/audio/VoiceCreation.kt @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory import java.io.* import java.nio.file.Files import java.nio.file.Paths +import java.text.BreakIterator import java.util.* class VoiceCreation( // 各種設定の値を保持するためのフィールド @@ -68,9 +69,27 @@ class VoiceCreation( // 各種設定の値を保持するためのフィール private fun sanitizeMessage(message: String): String { var sanitizedMsg = message.replace("[\\uD800-\\uDFFF]".toRegex(), " ") sanitizedMsg = sanitizedMsg.replace("Kosugi_kun".toRegex(), "コスギクン") - return sanitizedMsg + val sentences = BreakIterator.getSentenceInstance(Locale.JAPANESE) + sentences.setText(sanitizedMsg) + var messageCount = 0 + var lastIndex = 0 + val builder = StringBuilder() + while (sentences.next() != BreakIterator.DONE) { + val sentence = sanitizedMsg.substring(lastIndex, sentences.current()) + if (sentence.length + builder.length > maxMessageCount) { + builder.append("以下略") + break + } + builder.append(sentence) + builder.append("\n") + messageCount++ + lastIndex = sentences.current() + } + return builder.toString() } + + // テキストファイルを作成するメソッド @Throws(FileNotFoundException::class, UnsupportedEncodingException::class) private fun createTmpTextFile(guildId: String, fileId: String, message: String): String {